public function create($data)
{
if ($this->storagePrimaryKey === NULL) {
$this->storageReflection = $this->repository->getMapper()->getStorageReflection();
$this->storagePrimaryKey = (array) $this->storageReflection->getStoragePrimaryKey();
}
$id = [];
foreach ($this->storagePrimaryKey as $key) {
if (!isset($data[$key])) {
throw new InvalidArgumentException("Data returned from storage does not contain primary value(s) for '{$key}' key.");
}
$id[] = $data[$key];
}
$id = implode(',', $id);
if (isset($this->entities[$id]) && $this->entities[$id]) {
return $this->entities[$id];
}
$data = $this->storageReflection->convertStorageToEntity($data);
$entityClass = $this->repository->getEntityClassName($data);
if (!isset($this->entityReflections[$entityClass])) {
$this->entityReflections[$entityClass] = ClassType::from($entityClass);
$this->entityMetadata[$entityClass] = MetadataStorage::get($entityClass);
}
/** @var $entity IEntity */
$entity = $this->entities[$id] = $this->entityReflections[$entityClass]->newInstanceWithoutConstructor();
$entity->fireEvent('onLoad', [$this->repository, $this->entityMetadata[$entityClass], $data]);
return $entity;
}