Created
May 23, 2011 09:32
-
-
Save davidino/986464 to your computer and use it in GitHub Desktop.
how to use doctrine annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //http://jwage.com/2010/08/02/doctrine-annotations-library/ | |
| //http://www.doctrine-project.org/projects/common/2.0/docs/reference/annotations/en | |
| namespace Orient; | |
| require_once 'lib/Doctrine/Common/ClassLoader.php'; | |
| use Doctrine\Common\ClassLoader; | |
| use Doctrine\Common\Annotations\AnnotationReader; | |
| $loader = new ClassLoader('Doctrine\Common', 'lib'); | |
| $loader->register(); | |
| $reader = new AnnotationReader(); | |
| class Annotation extends \Doctrine\Common\Annotations\Annotation | |
| { | |
| public $cluster; | |
| /** | |
| * Orient attribute attributes | |
| */ | |
| public $name; | |
| public $type; | |
| public $linkedType; | |
| public $linkedClass; | |
| public $mandatory; | |
| public $notNull; | |
| public $min; | |
| public $max; | |
| public $indexed; | |
| } | |
| /** | |
| * @Orient\Annotation(cluster="documents") | |
| */ | |
| class Popo | |
| { | |
| /** | |
| * @Orient\Annotation(type="linkset") | |
| */ | |
| protected $linkset; | |
| protected $relations; | |
| } | |
| $reflClass = new \ReflectionClass('Orient\Popo'); | |
| $classAnnotations = $reader->getClassAnnotations($reflClass); | |
| echo $classAnnotations['Orient\Annotation']->cluster . "\n" ; | |
| $props = $reflClass->getProperties(); | |
| foreach ($props as $prop) { | |
| $field1Prop = $reflClass->getProperty($prop->getName()); | |
| $propAnnots = $reader->getPropertyAnnotations($field1Prop); | |
| if(array_key_exists('Orient\Annotation', $propAnnots)) | |
| { | |
| echo $propAnnots['Orient\Annotation']->type . "\n" ; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment