/** * Materialize raw data into an entity. It {@uses self::_instantiate} to instantiate the entity. * * @param array $data The data to create an entity from * * @return AnDomainEntityAbstract */ protected function _createEntity(array $data) { //create an instance with its unique keys first $keys = array(); $description = $this->_description; $keys = $description->getIdentifyingValues($data); if (empty($keys)) { throw new AnDomainRepositoryException('Trying to create an entity witout any identiftying keys'); } //if an entity found with them same key already //instantiated then return that entity to avoid having //duplicate objects $entity = $this->find($keys, false); if ($entity) { return $entity; } $inheritance_column = $description->getInheritanceColumn(); if ($inheritance_column && isset($data[$inheritance_column->key()])) { $identifier = $data[$inheritance_column->key()]; $identifier = substr($identifier, strrpos($identifier, ',') + 1); } else { $identifier = $this->_prototype->getIdentifier(); } $entity = $this->_instantiateEntity($identifier, $data); //insert the identity $this->_space->insertEntity($entity, $keys); $context = new KCommandContext(); $context->data = $data; $context->keys = $keys; $entity->execute('after.fetch', $context); //call after fetch $entity->reset(); //reset the entity return $entity; }