Example #1
0
 /**
  * @param $entityName
  * @return EntityManager
  * @throws Exception
  */
 protected function getEntityManager($entityName)
 {
     $classPaths = Utils\Reflection::getClassPathsByEntityName($entityName);
     $entity = $classPaths->getEntityPath();
     $mapper = $classPaths->getMapperPath();
     return new EntityManager(new $entity(), new $mapper());
 }
 /**
  *
  * @param \Vindication\Abstracts\Mapper $mapper
  * @param string $entityName
  * @throws \Exception
  */
 public function __construct(Abstracts\Mapper $mapper, $entityName)
 {
     if (is_string($entityName)) {
         $classPaths = Utils\Reflection::getClassPathsByEntityName($entityName);
         $entityClass = $classPaths->getEntityPath();
         if (false === ($entity = new $entityClass()) instanceof Abstracts\Entity) {
             throw new \Exception('Class ' . $entityClass . ' must be instance of Abstracts\\Entity!');
         }
     } else {
         if ($entityName instanceof Abstracts\Entity) {
             $entity = $entityName;
         } else {
             throw new \Exception('$entityName not valid!');
         }
     }
     $this->entity = $entity;
     $this->mapper = $mapper;
 }