Exemplo n.º 1
0
 public function __construct()
 {
     $this->objectClass = new ArrayCollection();
     $hydrater = new Hydrater(get_class($this));
     $hydrater->defineCollection($this);
     $hydrater->defineObjectClass($this);
 }
 /**
  * @param Entity $entity
  * @param Hydrater $hydrater
  * @param EntityAnalyzer $analyzer
  */
 public function flushEntity($entity, Hydrater $hydrater, EntityAnalyzer $analyzer)
 {
     $originData = $entity->_getOriginData();
     $originName = array();
     if (is_null($originData)) {
         $originData = array();
         foreach ($analyzer->listColumns() as $name => $data) {
             if ($data['type'] === 'array') {
                 $originData[strtolower($name)] = array();
             } else {
                 $originData[strtolower($name)] = NULL;
             }
         }
     }
     foreach ($analyzer->listColumns() as $name => $data) {
         $originName[strtolower($name)] = $name;
     }
     $originName['objectclass'] = 'objectclass';
     $currentData = $hydrater->getData($entity);
     foreach ($currentData as $column => $value) {
         if (array_key_exists($originName[strtolower($column)], $analyzer->listColumns()) && $analyzer->listColumns()[$originName[strtolower($column)]]['type'] === 'array' && is_null($value)) {
             $currentData[$column] = array();
         }
         // Convert array of entity to array of DN
         if ($analyzer->isEntityRelation($originName[strtolower($column)])) {
             $listDn = array();
             foreach ($value as $e) {
                 if ($e instanceof Entity) {
                     $listDn[] = $e->_getDn();
                 }
             }
             $currentData[$column] = $listDn;
         }
     }
     $diff = self::dataDiff($currentData, $originData);
     $dn = $entity->_getDn();
     if (is_null($dn)) {
         if ($this->param[EntityFlusher::CREATE]) {
             $this->create($entity, $currentData, $diff, $analyzer);
         } else {
             throw new InflushableException('Unable to create entity, Param::Create is false');
         }
     } else {
         if (array_key_exists($analyzer->getIndex(), $diff)) {
             // If key index is diff => rename
             if ($this->param[EntityFlusher::RENAME]) {
                 $this->rename($entity, $currentData, $diff, $analyzer);
             } else {
                 throw new InflushableException('Unable to rename entity, Param::Rename is false');
             }
         }
         if (count($diff) > 0) {
             $this->em->getClient()->update($entity->_getDn(), $diff);
         }
     }
 }
 public function testGetData()
 {
     $array = array('uid' => 'pdeparis', 'telephoneNumber' => array('03 00 00 00 00', '04 00 00 00 00'));
     $people = $this->hydrater->hydrate($array);
     $this->assertEquals($this->hydrater->getData($people), array('uid' => 'pdeparis', 'telephoneNumber' => array('03 00 00 00 00', '04 00 00 00 00'), 'cn' => array(), 'sn' => array(), 'givenName' => array(), 'mail' => array(), 'objectclass' => array('inetOrgPerson', 'organizationalPerson', 'person', 'top')));
 }
Exemplo n.º 4
0
 public function __construct()
 {
     $hydrater = new Hydrater(get_class($this));
     $hydrater->defineCollection($this);
 }
Exemplo n.º 5
0
 public function testGetData()
 {
     $array = array('uid' => 'pdeparis', 'telephoneNumber' => array('03 00 00 00 00', '04 00 00 00 00'));
     $people = $this->hydrater->hydrate($array);
     $this->assertEquals($this->hydrater->getData($people), array('uid' => 'pdeparis', 'telephoneNumber' => array('03 00 00 00 00', '04 00 00 00 00'), 'cn' => array(), 'sn' => array(), 'givenName' => array(), 'mail' => array()));
 }