Ejemplo n.º 1
0
 /**
  * Vytvori entity, nebo vrati tuto existujici.
  * @param array
  * @return IEntity
  * @see IRepository::hydrateEntity()
  */
 public function create($data)
 {
     if ($this->conventional === NULL) {
         $this->conventional = $this->repository->getMapper()->getConventional();
         // speedup
         $this->primaryKey = $this->conventional->getPrimaryKey();
     }
     if (!isset($data[$this->primaryKey])) {
         throw new BadReturnException("Data, that is returned from storage, doesn't contain id.");
     }
     $id = $data[$this->primaryKey];
     if (!isset($this->entities[$id]) or !$this->entities[$id]) {
         $data = (array) $this->conventional->formatStorageToEntity($data);
         $entityName = $this->repository->getEntityClassName($data);
         $this->checkEntityClassName($entityName);
         $entity = unserialize("O:" . strlen($entityName) . ":\"{$entityName}\":0:{}");
         if (!$entity instanceof IEntity) {
             throw new InvalidEntityException('Unserialize error');
         }
         $args = array('data' => $data);
         $this->events->fireEvent(Events::HYDRATE_BEFORE, $entity, $args);
         $id = $entity->id;
         $this->entities[$id] = $entity;
         $this->events->fireEvent(Events::HYDRATE_AFTER, $entity, $args);
     }
     return $this->entities[$id];
 }
Ejemplo n.º 2
0
 /**
  * Loads collection of entities for this association.
  * @param IRepository
  * @param array of scalar
  * @return IEntityCollection
  */
 protected function loadCollection(IRepository $repository, array $ids)
 {
     if (!$ids) {
         return new ArrayCollection(array());
     }
     return $repository->getMapper()->findById($ids);
 }