I think keeping this just like an array definition in a property would make
this both simple and flexible.

You can even improve on Marcos example with a class having constants:

namespace Doctrine\ORM\Mapping\Annotations;

class ORM
{
    const ENTITY = 'Doctrine\ORM\Mapping\Annotations\Entity';
    // more constants here
}

And then use it like:

use Doctrine\ORM\Mapping\Annotations\ORM;

[ORM::ENTITY => ["key" => "value"]]
class Article
{
}

This would allow projects to namespace their annotations without much
hassle. But it also allows people to disregard this and just write simple
strings as keys with the risk of clashes with third parties.

greetings
Benjamin

On Wed, Nov 5, 2014 at 4:15 PM, Alexander Lisachenko <
lisachenko...@gmail.com> wrote:

>
> 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