/**
  * Returns the definition of the persistent object with the class $class.
  *
  * If a definition has been requested already the definition will be served from
  * the cache.
  *
  * @throws ezcPersistentDefinitionNotFoundException if no such definition can be found.
  * @param string $class
  * @return ezcPersistentObjectDefinition
  */
 public function fetchDefinition($class)
 {
     if (isset($this->cache[$class])) {
         return $this->cache[$class];
     }
     $def = $this->manager->fetchDefinition($class);
     // cache it
     $this->cache[$class] = $def;
     return $def;
 }
Example #2
0
 /**
  * Removes all references to $set from the objects in $set.
  *
  * Maintains the {@link ezcPersistentIdentity::$references} attribute by
  * removing all refereneces to $set from all object identities contained in
  * $set.
  *
  * @param ArrayObject $set 
  */
 protected function removeReferences(ArrayObject $set)
 {
     foreach ($set as $obj) {
         $class = get_class($obj);
         $def = $this->definitionManager->fetchDefinition($class);
         $state = $obj->getState();
         $id = $state[$def->idProperty->propertyName];
         if ($this->identities[$class][$id]->references->contains($set)) {
             $this->identities[$class][$id]->references->detach($set);
         }
     }
 }
 /**
  * Fetches the needed definitions for $relations and stores them.
  *
  * Fetches {@link ezcPersistentObjectDefinition} and relation definitions
  * for all relations defined in $relations. $srcDef is the the object
  * definition, where $relations should be fetched for. The definitions are
  * stored inside the {@link ezcPersistentRelationFindDefinition} objects
  * the correspond to.
  *
  * @param ezcPersistentObjectDefinition $srcDef 
  * @param array(string=>ezcPersistentRelationFindDefinition) $relations 
  */
 protected function fetchDefinitions(ezcPersistentObjectDefinition $srcDef, array $relations)
 {
     foreach ($relations as $relation) {
         if (!isset($srcDef->relations[$relation->relatedClass])) {
             throw new ezcPersistentRelationNotFoundException($srcDef->class, $relation->relatedClass);
         }
         $srcRelDef = $srcDef->relations[$relation->relatedClass];
         if ($relation->relationName !== null) {
             $srcRelDef = $srcRelDef[$relation->relationName];
         }
         $relation->relationDefinition = $srcRelDef;
         $relation->definition = $this->defManager->fetchDefinition($relation->relatedClass);
         if ($relation->furtherRelations !== array()) {
             $this->fetchDefinitions($relation->definition, $relation->furtherRelations);
         }
     }
 }
 /**
  * Extracts all objects and their related objects from $stmt.
  *
  * Extracts all objects of the $class defined in $q from $stmt, including
  * all related objects as defined in the $relations property of $q. Returns
  * the set of base objects found by $q.
  * 
  * @param PDOStatement $stmt 
  * @param ezcPersistentFindWithRelationsQuery $q
  * @return array(ezcPersistentObject)
  */
 public function extractObjectsWithRelatedObjects(PDOStatement $stmt, ezcPersistentFindWithRelationsQuery $q)
 {
     $class = $q->className;
     $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $def = $this->defManager->fetchDefinition($class);
     $extractedBaseObjects = array();
     foreach ($results as $row) {
         $baseObjId = $row[$def->idProperty->propertyName];
         if (!isset($extractedBaseObjects[$baseObjId])) {
             $object = new $class();
             $this->setObjectState($object, $def, $row);
             $this->idMap->setIdentity($object);
             $extractedBaseObjects[$baseObjId] = $object;
         }
         $this->extractObjectsRecursive($row, $q->relations, $extractedBaseObjects[$baseObjId], $q->isRestricted);
     }
     return $extractedBaseObjects;
 }