Skip to content

Instantly share code, notes, and snippets.

@davidino
Created May 23, 2011 09:32
Show Gist options
  • Select an option

  • Save davidino/986464 to your computer and use it in GitHub Desktop.

Select an option

Save davidino/986464 to your computer and use it in GitHub Desktop.
how to use doctrine annotations
<?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