Re: Annotations in PHP7

From: Date: Wed, 18 Feb 2015 08:05:35 +0000
Subject: Re: Annotations in PHP7
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-83031@lists.php.net to get a copy of this message
On Wed, Feb 18, 2015 at 8:02 AM, Dmitry Stogov <dmitry@zend.com> wrote: > > > On Wed, Feb 18, 2015 at 12:51 AM, guilhermeblanco@gmail.com < > guilhermeblanco@gmail.com> wrote: > >> François, >> >> Doctrine relies on nested annotations for a variety of mapping >> information. >> One example: >> >> >> >> http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html#one-to-many-unidirectional-with-join-table >> >> > Nested annotations are not going to be necessary, because they may be > represented by PHP pseudo-syntax (and/or PHP array syntax) > > <Doctrine_Join( > ManyToMany($targetEntity="Phonenumber"), > JoinTable($name="users_phonenumbers", > $joinColumns=JoinColumn($name="user_id", > $referencedColumnName="id")) > inverseJoinColumns=JoinColumn($name="phonenumber_id", > $referencedColumnName="id", $unique=true))> > class User { > ... > } > > $r = new ReflectionClass("User"); > $ast = $r->getAnnotation("Doctine_Join"); > echo $ast->child[0]->child[0]; // "ManyToMany" > echo $ast->child[0]->child[1]->child[0]->child[0]; // "$targetEntity" > > or If we provide API similar to SimpleXML > > echo $ast[0][0]; // "ManyToMany" > echo $ast[0][1][0][0]; // "$targetEntity" > > Thanks. Dmitry. > nested can be done in any way, its a statement so the following would work: <orm(new JoinTable(['joinColumns' => [new JoinColumn('id', 'other_id')]]))> You might need to improve this by defining functions, so that "new JoinTable" becomes just "JoinTable", but in any case we will find a way to make it work in Doctrine. > > > > >> []s, >> >> On Tue, Feb 17, 2015 at 4:33 PM, François Laupretre <francois@php.net> >> wrote: >> >>> Hi Alexander, >>> >>> > De : Alexander Lisachenko [mailto:lisachenko.it@gmail.com] >>> > >>> > This RFC consists of two parts: parsing API and parser extension API. >>> Last >>> > one can be rejected, however it can be perfectly connected with >>> annotation >>> > RFC (if AST will be used as values) >>> >>> Parser extension API is great. Go on with it. I have a lot of uses in >>> mind. >>> >>> > As for annotations, general use-case is appreciated. This can be >>> extended >>> > later in future versions of PHP. Therefore, annotation syntax should >>> allow >>> > to define key and values. Value can be valid expression (AST? concrete >>> > node? compiled value?) or can recursively contain nested annotations. >>> >>> Can you give a use case for nested annotations ? I don't see what they >>> can be needed for. >>> >>> Thanks >>> >>> François >>> >>> >>> >>> >> >> >> -- >> Guilherme Blanco >> MSN: guilhermeblanco@hotmail.com >> GTalk: guilhermeblanco >> Toronto - ON/Canada >> > >

« previous php.internals (#83031) next »