jewel/schema

v1.0.0 2014-04-17 16:48 UTC

README

License Packagist

Jewel Schema - entity description format.

Example

User entity description:

User:
    id: Id
    name: String(32) => Index
    email: Email
    Timestamps(1, 2, 3)
    Unique(email)

Post entity description:

Post:
    id: Id
    author: User
    title: String(100)
    content: Text
    comments: HasMany(Comment) # Описание связи "OneToMany" к сущности Comment

Comment entity description:

Comment:
    id: Id
    content: Text
    author: User
    post: Reverse(Post.comments) # Описание связи "ManyToOne" на основе объявленной связи

Usage

$schema = Parser::parse('blog.schema');
$user = $schema->getChild('User');
$userName = $user->getField('name');
var_dump(
    $userName->getType()->getName(), // "String"
    $userName->getType()->getArguments(), // [30]
    $userName->getFilters()[0]->getName() // Index
);

$timestampsAction = $user->getActions()[0];
$uniqueAction = $user->getActions()[1];
var_dump(
    $timestampsAction->getName(), // "Timestamps"
    $timestampsAction->getArguments(), // [1, 2, 3]
    $uniqueAction->getName(), // "Unique"
    $uniqueAction->getArguments() // ["email"]
);