LeanMapper\IEntityFactory::createEntity PHP Method

createEntity() public method

Creates entity instance from given entity class name and argument
public createEntity ( string $entityClass, Row | Traversabl\Traversable | array | null $arg = null ) : Entity
$entityClass string
$arg Row | Traversabl\Traversable | array | null
return Entity
    public function createEntity($entityClass, $arg = null);

Usage Example

Beispiel #1
0
 /**
  * Creates new set of Entity's instances from given array of \Dibi\Row instances
  *
  * @param \Dibi\Row[] $rows
  * @param string|null $entityClass
  * @param string|null $table
  * @return array
  */
 protected function createEntities(array $rows, $entityClass = null, $table = null)
 {
     if ($table === null) {
         $table = $this->getTable();
     }
     $entities = [];
     $collection = Result::createInstance($rows, $table, $this->connection, $this->mapper);
     $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
     if ($entityClass !== null) {
         foreach ($rows as $dibiRow) {
             $entity = $this->entityFactory->createEntity($entityClass, $collection->getRow($dibiRow->{$primaryKey}));
             $entity->makeAlive($this->entityFactory);
             $entities[$dibiRow->{$primaryKey}] = $entity;
         }
     } else {
         foreach ($rows as $dibiRow) {
             $row = $collection->getRow($dibiRow->{$primaryKey});
             $entityClass = $this->mapper->getEntityClass($this->getTable(), $row);
             $entity = $this->entityFactory->createEntity($entityClass, $row);
             $entity->makeAlive($this->entityFactory);
             $entities[$dibiRow->{$primaryKey}] = $entity;
         }
     }
     return $this->entityFactory->createCollection($entities);
 }
All Usage Examples Of LeanMapper\IEntityFactory::createEntity