Re: Annotation PHP 7
| From: | Alexander Lisachenko | Date: | Wed, 05 Nov 2014 15:15:58 +0000 |
| Subject: | Re: Annotation PHP 7 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78724@lists.php.net to get a copy of this message | ||
2014-11-05 17:02 GMT+03:00 Marco Pivetta <ocramius@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
{
// ...
}