2014-11-05 17:02 GMT+03:00 Marco Pivetta <ocram...@gmail.com>:

> For example, this alternative approach perfectly fits the current
> doctrine/annotations use-case:
>
> use Doctrine\ORM\Mapping\Entity;
> use Doctrine\ORM\Mapping\Table;
> use Doctrine\ORM\Mapping\Id;
> use Doctrine\ORM\Mapping\GeneratedValue;
> use Doctrine\ORM\Mapping\Column;
>
> [Entity::class => []]
> [Table::class => ['name' => 'foo_table']]
> class Foo
> {
>     [Id::class => []]
>     [GeneratedValue::class => [GeneratedValue::UUID]]
>     [Column::class => ['name' => 'bar_column', 'type' => 'string']]
>     private $bar;
> }
>

This looks great indeed for many reasons:
1) it's a simple array
2) it can be parsed with built-in DSL syntax for PHP, so any arbitrary
evaluations with constants can be applied transparently, e.g.
[Loggable::class => ['pointcut' => self::PREFIX . 'test' ]]

3) C# uses similar syntax with square brackets for annotations:

public class Foo
{
    [Display(Name="Product Number")]
    [Range(0, 5000)]
    public int ProductID { get; set; }
}

However, I would like to see simple markers without nested associative
arrays, e.g just put single AnnotationName::class into brackets or specify
multiple annotations in one section:

[Entity::class, Table::class => 'foo_table']
class Foo
{
  // ...
}

Reply via email to