Beispiel #1
0
 /**
  * Constructor
  * @param array         $aggregateProto  Entity ids or prototypes array
  * @param Mapper    $mapper          Mapper Object
  * @param null|string   $cacheKey        Cache key for aggregate
  * @param bool          $loadEntities    Should load aggregate entities
  * @throws BaseException
  */
 public function __construct(array $aggregateProto, Mapper $mapper, $cacheKey = null, $loadEntities = false)
 {
     $this->mapper = $mapper;
     $this->cacheKey = $cacheKey;
     $this->entities = array();
     $idField = $this->mapper->getIdField();
     foreach ($aggregateProto as $entityProto) {
         if (false === is_array($entityProto)) {
             $entityProto = array($idField => $entityProto);
         } else {
             if (false === array_key_exists($idField, $entityProto)) {
                 throw new BaseException('Entity proto does not contain id');
             }
         }
         $this->listEntityId[] = $entityProto[$idField];
         if (count($entityProto) > 1) {
             $entity = $mapper->createEntity($entityProto);
             $this->entities[$entity->getId()] = $entity;
             $this->loadedListEntityId[$entity->getId()] = $entity->getId();
         }
     }
     if ($loadEntities && false === $this->isAllEntitiesLoaded()) {
         $this->loadEntities();
     }
 }
Beispiel #2
0
 /**
  * Return entity id
  * @return int
  */
 public function getId()
 {
     return $this->proto[$this->mapper->getIdField()];
 }