/** * Constructor * @param Entity|string $entity */ public function __construct($entity) { if (is_string($entity) && \class_exists($entity)) { $this->entity = $entity; } elseif ($entity instanceof Entity) { $this->entity = $entity->getEntityClass(); } else { throw new Exception("'{$entity}' is neither entity class name nor entity itself."); } $entity = $this->entity; try { $this->reflection = $entity::getReflection(); } catch (Exception $e) { throw new Exception("Can't create reflection for entity '{$entity}'", 0, $e); } $this->alias = '$' . $this->getName(); $this->dataSource = new DataSource\Database(); $this->dataSource->setRowClass($this->entity); if ($this->reflection->isExtendingEntity()) { $this->extends = new self($this->reflection->getParentEntity()); } if (isset($this->extends)) { $this->join($this->extends, Entity::EXTENDED); } }