Ejemplo n.º 1
0
 public function __construct(Mappable $entity, Mapper $mapper, QueryAdapter $query)
 {
     $this->entity = $entity;
     $this->mapper = $mapper;
     $this->entityState = new StateChecker($entity, $mapper);
     $this->entityMap = $mapper->getEntityMap();
     $this->query = $query->from($this->entityMap->getTable());
 }
Ejemplo n.º 2
0
 /**
  * Return a new Mapper instance
  * 
  * @param  string       $entityClass 
  * @param  string       $entityMap
  * @return Mapper                     
  */
 public function make($entityClass, EntityMap $entityMap)
 {
     $driver = $entityMap->getDriver();
     $connection = $entityMap->getConnection();
     $adapter = $this->drivers->getAdapter($driver, $connection);
     $entityMap->setDateFormat($adapter->getDateFormat());
     $mapper = new Mapper($entityMap, $adapter, $this->dispatcher, $this->manager);
     // Fire Initializing Event
     $mapper->fireEvent('initializing', $mapper);
     $mapInitializer = new MapInitializer($entityMap);
     $mapInitializer->init();
     // Fire Initialized Event
     $mapper->fireEvent('initialized', $mapper);
     return $mapper;
 }
Ejemplo n.º 3
0
 /**
  * Add the Entity primary key if not in requested columns
  * 
  * @param  array $columns 
  * @return array
  */
 protected function enforceIdColumn($columns)
 {
     if (!in_array($this->entityMap->getKeyName(), $columns)) {
         $columns[] = $this->entityMap->getKeyName();
     }
     return $columns;
 }
Ejemplo n.º 4
0
 /**
  * Create a new instance of the mapped entity class
  * 
  * @param  array  $attributes 
  * @return mixed
  */
 public function newInstance($attributes = array())
 {
     $class = $this->entityMap->getClass();
     if ($this->entityMap->activator() != null) {
         $entity = $this->entityMap->activator();
     } else {
         $entity = $this->customClassInstance($class);
     }
     // prevent hydrating with an empty array
     if (count($attributes) > 0) {
         $entity->setEntityAttributes($attributes);
     }
     return $entity;
 }
Ejemplo n.º 5
0
 /**
  * Build lazy loading proxies for the current entity
  *
  * @param \Analogue\ORM\Mappable $entity
  *
  * @return array
  */
 protected function getLazyLoadingProxies(Mappable $entity)
 {
     $proxies = [];
     $singleRelations = $this->entityMap->getSingleRelationships();
     $manyRelations = $this->entityMap->getManyRelationships();
     foreach ($this->lazyLoads as $relation) {
         if (in_array($relation, $singleRelations)) {
             $proxies[$relation] = new EntityProxy($entity, $relation);
         }
         if (in_array($relation, $manyRelations)) {
             $proxies[$relation] = new CollectionProxy($entity, $relation);
         }
     }
     return $proxies;
 }
Ejemplo n.º 6
0
 /**
  * Determine if an entity attribute is a relationship.
  * 
  * @param  strin $key 
  * @return boolean      
  */
 protected function isRelation($key)
 {
     return in_array($key, $this->entityMap->getRelationships());
 }
Ejemplo n.º 7
0
 /**
  * Get the name of the "updated at" column.
  *
  * @return string
  */
 public function getUpdatedAtColumn()
 {
     return $this->parentMap->getUpdatedAtColumn();
 }
Ejemplo n.º 8
0
 /**
  * Get the key for comparing against the parent key in "has" query.
  *
  * @return string
  */
 public function getHasCompareKey()
 {
     return $this->farParentMap->getQualifiedKeyName();
 }