protected function getMethodSrc($methodName, $file = null)
 {
     if (is_null($file)) {
         $file = file($this->analyzer->getReflection()->getFileName());
     }
     try {
         $startLine = $this->analyzer->getReflection()->getMethod($methodName)->getStartLine() - 1;
         $endLine = $this->analyzer->getReflection()->getMethod($methodName)->getEndLine() + 1;
     } catch (\ReflectionException $e) {
         return '';
     }
     $length = $endLine - $startLine;
     return implode('', array_slice($file, $startLine, $length));
 }
Beispiel #2
0
 public function defineCollection($entity)
 {
     foreach ($this->analyzer->listColumns() as $name => $info) {
         switch ($info['type']) {
             case 'array':
                 $value = new ArrayCollection();
                 break;
             case 'entity':
                 if ($info['relation']['multi']) {
                     $value = new EntityCollection(EntityCollection::DN, $info['relation']['classname'], array());
                 } else {
                     $value = null;
                 }
                 break;
             default:
                 $value = null;
         }
         if (!is_null($value)) {
             $property = $this->analyzer->getReflection()->getProperty($name);
             $isAccessible = $property->isPublic();
             $property->setAccessible(true);
             $property->setValue($entity, $value);
             if (!$isAccessible) {
                 $property->setAccessible(false);
             }
         }
     }
 }
 public function defineObjectClass(Entity $entity)
 {
     $classAnnotation = $this->analyzer->getClassAnnotation();
     foreach ($classAnnotation['objectclass'] as $objectClass) {
         $entity->addObjectClass($objectClass);
     }
 }
Beispiel #4
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);
 }
 public function testListMissingMethod()
 {
     $this->assertEquals($this->entityAnalyzer->listMissingMethod(), array('getUid' => array('type' => EntityAnalyzer::GETTER, 'column' => 'uid'), 'setUid' => array('type' => EntityAnalyzer::SETTER, 'column' => 'uid'), 'getCn' => array('type' => EntityAnalyzer::GETTER, 'column' => 'cn'), 'setCn' => array('type' => EntityAnalyzer::SETTER, 'column' => 'cn'), 'getSn' => array('type' => EntityAnalyzer::GETTER, 'column' => 'sn'), 'setSn' => array('type' => EntityAnalyzer::SETTER, 'column' => 'sn'), 'getGivenName' => array('type' => EntityAnalyzer::GETTER, 'column' => 'givenName'), 'setGivenName' => array('type' => EntityAnalyzer::SETTER, 'column' => 'givenName'), 'getMail' => array('type' => EntityAnalyzer::GETTER, 'column' => 'mail'), 'setMail' => array('type' => EntityAnalyzer::SETTER, 'column' => 'mail'), 'getTelephoneNumber' => array('type' => EntityAnalyzer::GETTER, 'column' => 'telephoneNumber'), 'addTelephoneNumber' => array('type' => EntityAnalyzer::ADDER, 'column' => 'telephoneNumber'), 'removeTelephoneNumber' => array('type' => EntityAnalyzer::REMOVER, 'column' => 'telephoneNumber')));
 }
 public function testIsMultiEntityRelation()
 {
     $this->assertEquals($this->entityAnalyzer->isEntityRelationMultiple('member'), true);
     $this->assertEquals($this->entityAnalyzer->isEntityRelationMultiple('cn'), false);
 }
 private function getNewDn($entity, $currentData, EntityAnalyzer $analyzer)
 {
     $index = $analyzer->getIndex();
     if ($index === false) {
         throw new InflushableException('Entity ' . get_class($entity) . 'have no index');
     }
     $dnPiece = array();
     $dnPiece[] = $index . '=' . $currentData[$index];
     if (is_string($analyzer->getBaseDn())) {
         $dnPiece[] = $analyzer->getBaseDn();
     }
     if (is_string($this->em->getClient()->getBaseDn())) {
         $dnPiece[] = $this->em->getClient()->getBaseDn();
     }
     return implode(',', $dnPiece);
 }
 /**
  * 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;
 }