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()); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Determine if an entity attribute is a relationship. * * @param strin $key * @return boolean */ protected function isRelation($key) { return in_array($key, $this->entityMap->getRelationships()); }
/** * Get the name of the "updated at" column. * * @return string */ public function getUpdatedAtColumn() { return $this->parentMap->getUpdatedAtColumn(); }
/** * Get the key for comparing against the parent key in "has" query. * * @return string */ public function getHasCompareKey() { return $this->farParentMap->getQualifiedKeyName(); }