/** * @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 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 testListField() { $this->assertEquals($this->entityAnalyzer->listColumns(), array('uid' => array('type' => 'string', 'index' => true, 'strict' => true), 'cn' => array('type' => 'string', 'index' => false, 'strict' => true), 'sn' => array('type' => 'string', 'index' => false, 'strict' => true), 'givenName' => array('type' => 'string', 'index' => false, 'strict' => true), 'mail' => array('type' => 'string', 'index' => false, 'strict' => true), 'telephoneNumber' => array('type' => 'array', 'index' => false, 'strict' => true))); }
public function testListField() { $this->assertEquals($this->entityAnalyzer->listColumns(), array('cn' => array('type' => 'string', 'index' => true, 'strict' => true), 'member' => array('type' => 'entity', 'index' => false, 'strict' => true, 'relation' => array('classname' => 'OpenLdapObject\\Tests\\Manager\\People', 'multi' => true, 'ignore_errors' => false)))); }