/** * 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; }
/** * Set the proxies attribute on a freshly stored entity * * @param \Analogue\ORM\Entity */ protected function setProxies($entity) { if (!$this->entityMap->relationsParsed()) { $initializer = new MapInitializer($this->mapper->getEntityMap()); $initializer->splitRelationsTypes($entity); } $attributes = $entity->getEntityAttributes(); $singleRelations = $this->entityMap->getSingleRelationships(); $manyRelations = $this->entityMap->getManyRelationships(); $proxies = []; foreach ($this->entityMap->getRelationships() as $relation) { if (!array_key_exists($relation, $attributes) || is_null($attributes[$relation])) { if (in_array($relation, $singleRelations)) { $proxies[$relation] = new EntityProxy($entity, $relation); } if (in_array($relation, $manyRelations)) { $proxies[$relation] = new CollectionProxy($entity, $relation); } } } foreach ($proxies as $key => $value) { $entity->setEntityAttribute($key, $value); } }
/** * Deduce the relationships that will be lazy loaded from the eagerLoads array * * @return array */ protected function prepareLazyLoading() { $entityMap = $this->entityMap; if (!$entityMap->relationsParsed()) { $initializer = new MapInitializer($entityMap); $initializer->splitRelationsTypes($this->mapper->newInstance()); } $singleRelations = $entityMap->getSingleRelationships(); $manyRelations = $entityMap->getManyRelationships(); $allRelations = array_merge($manyRelations, $singleRelations); return array_diff($allRelations, $this->eagerLoads); }