Esempio n. 1
0
 public function __construct(EntityManager $em, $className)
 {
     $this->em = $em;
     $this->className = $className;
     $this->analyzer = EntityAnalyzer::get($className);
     $column = $this->analyzer->listColumns();
     $index = $this->analyzer->getIndex();
     $this->columns = array_keys($column);
     $this->baseDn = $this->analyzer->getBaseDn();
     $this->hydrater = new Hydrater($this->className, $em);
 }
 /**
  * @expectedException OpenLdapObject\Annotations\InvalidAnnotationException
  */
 public function testListFieldMultiIndex()
 {
     $entityWithMultiIndex = EntityAnalyzer::get('OpenLdapObject\\Tests\\Manager\\PeopleMultiIndex');
     $this->assertEquals($entityWithMultiIndex->listColumns(), array('uid' => array('type' => 'string', 'index' => true), 'cn' => array('type' => 'string', 'index' => false), 'sn' => array('type' => 'string', 'index' => false), 'givenName' => array('type' => 'string', 'index' => false), 'mail' => array('type' => 'string', 'index' => false), 'telephoneNumber' => array('type' => 'array', 'index' => false)));
 }
Esempio n. 3
0
 public function __construct($className)
 {
     $this->className = $className;
     $this->analyzer = EntityAnalyzer::get($this->className);
 }
Esempio n. 4
0
 public function __construct($className, EntityManager $em = null)
 {
     $this->className = $className;
     $this->analyzer = EntityAnalyzer::get($className);
     $this->em = $em;
 }
 /**
  * @expectedException OpenLdapObject\Annotations\InvalidAnnotationException
  */
 public function testListFieldMultiIndex()
 {
     $entityAnalyzer = EntityAnalyzer::get('OpenLdapObject\\Tests\\Manager\\OrganisationInvalid');
     $entityAnalyzer->listColumns();
 }
Esempio n. 6
0
 /**
  * List the Ldap Columns of an Entity Class
  * @return array
  * @throws \OpenLdapObject\Annotations\InvalidAnnotationException
  */
 public function listColumns()
 {
     if (!is_null($this->listColumns)) {
         return $this->listColumns;
     }
     // We use this method to load the annotation classes, because the annotation Library Doctrine does not
     AnnotationManager::autoLoadAnnotation();
     // Set the list of properties, an array to contain the list of columns and a boolean to check if the class has several indexes
     $properties = $this->reflection->getProperties();
     $haveIndex = false;
     $columns = array();
     foreach ($properties as $property) {
         // For each properties, get the list of annotations
         $propertyAnnotation = $this->annotationReader->getPropertyAnnotations($property);
         // Check the property has a Column Annotation
         if (($columnAnnotation = self::haveAnnotation(self::$ColumnAnnotation, $propertyAnnotation)) !== false) {
             $columnAnnotation->check();
             $column = array('type' => $columnAnnotation->type);
             // Check the property has an Index Annotation
             if (($indexAnnotation = self::haveAnnotation(self::$IndexAnnotation, $propertyAnnotation)) !== false) {
                 $indexAnnotation->check();
                 // Verify that the class have a unique index annotation
                 if ($haveIndex == true) {
                     throw new InvalidAnnotationException($indexAnnotation, $property->getName(), 'Class ' . $this->className . ' have already an index when he read the annotation of ' . $property->getName());
                 }
                 $column['index'] = true;
                 $haveIndex = true;
             } else {
                 $column['index'] = false;
             }
             // If is an entity Column, check entityRelationAnnotation
             if ($column['type'] == 'entity') {
                 if (($relationAnnotation = self::haveAnnotation(self::$entityRelationAnnotation, $propertyAnnotation)) !== false) {
                     $relationAnnotation->check();
                     try {
                         $annotationClassOfRelation = EntityAnalyzer::get($relationAnnotation->classname)->getClassAnnotation();
                     } catch (InvalidEntityException $e) {
                         throw new InvalidAnnotationException($relationAnnotation, 'classname', 'The class ' . $relationAnnotation->classname . ' is not an Entity');
                     }
                     $column['relation'] = array('classname' => $relationAnnotation->classname, 'multi' => $relationAnnotation->multi);
                 } else {
                     throw new InvalidAnnotationException(null, null, 'A Entity Column must have a EntityRelation annotations');
                 }
             }
             $columns[$property->getName()] = $column;
         }
     }
     $this->listColumns = $columns;
     return $columns;
 }