On Wed, Jan 9, 2013 at 1:42 PM, Derick Rethans <[email protected]> wrote:
> Please, no top posting!!!
>
> On Wed, 9 Jan 2013, Vladislav Veselinov wrote:
>
> > Taken from the Doctrine documentation:
> >
> > <?php
> > class User
> > {
> > //...
> > /**
> > * @ManyToMany(targetEntity="Group")
> > * @JoinTable(name="User_Group",
> > * joinColumns={@JoinColumn(name="User_id",
> referencedColumnName="id")},
> > * inverseJoinColumns={@JoinColumn(name="Group_id",
> referencedColumnName="id")}
> > * )
> > */
> > private $groups;
> > //...
> > }
> >
> > Not that I'm a fan of it, but it provides a valid usecase. I'm sure
> > there are more.
>
> Maybe valid, but sticking this into core-syntax seems mental.
>
The Doctrine Syntax is verbose, because that is necessary to make up for
the missing compile time support in the language.
The core could easily offer a "simpler" language or one that looks more
like PHP code (array syntax).
If you take a look at annotations by starting with PHP code, instead of
docblocks and the syntax optimized for that use-case you can end up with
something much simpler, see:
The most simple type of annotations is attaching metadata to a class,
method, function, property. In Clojure this is actually done like this at
runtime setting a hashmap to any structure.
In PHP that would be something like:
function foo() {}
$refl = new ReflectionFunction('foo');
$refl->setMetadata(array('foo' => 'bar'));
$refl->getMetadata();
Doctrine Annotations do allow "retrieving" metadata for any structure,
sspecified in docblocks. For seperation we need something the Annotations
RFC defined, a new type of docblock that is executable code wrapped in for
example <> brackets, if this were just PHP code, then we'd have:
<return array('foo' => 'bar'))>
function foo() {}
Now the difference between this syntax, and something resembling "Docblock
Annotations" would mean that the last statement between <> is returned from
the block. With short syntax for arrays we get:
<['foo' => 'bar']>
function foo() {}
Now this is nothing new to learn for anybody, except that <> code for any
structure can be "executed" using $reflection->getMetadata();
And the crazy people (like me) could do more structured things:
use Doctrine\ORM\Mapping AS ORM;
<[new ORM\Entity, new ORM\Table(name="user")]>
class User {}