示例#1
0
 /**
  * Build the Entity(ies)
  *
  * @param  array $results
  * @return Mappable|EntityCollection
  */
 public function build(array $results)
 {
     $entities = array();
     $prototype = $this->mapper->newInstance();
     $keyName = $this->entityMap->getKeyName();
     $tmpCache = [];
     foreach ($results as $result) {
         $instance = clone $prototype;
         $resultArray = (array) $result;
         $tmpCache[$resultArray[$keyName]] = $resultArray;
         // Hydrate any embedded Value Object
         $this->hydrateValueObjects($resultArray);
         $instance->setEntityAttributes($resultArray);
         // Hydrate relation attributes with lazyloading proxies
         if (count($this->lazyLoads) > 0) {
             $proxies = $this->getLazyLoadingProxies($instance);
             $instance->setEntityAttributes($resultArray + $proxies);
         }
         $entities[] = $instance;
     }
     $this->mapper->getEntityCache()->add($tmpCache);
     return $entities;
 }
示例#2
0
 /**
  * Get the attributes that have been modified since
  * the entity have been fetched from the database
  * 
  * @return array
  */
 public function getDirtyAttributes()
 {
     $attributes = $this->flattenEmbeddables($this->entity->getEntityAttributes());
     $id = $attributes[$this->keyName];
     $cachedAttributes = $this->mapper->getEntityCache()->get($id);
     $dirty = [];
     foreach ($attributes as $key => $value) {
         if ($this->isRelation($key) || $key == 'pivot') {
             continue;
         }
         if (!array_key_exists($key, $cachedAttributes) && !$value instanceof Pivot) {
             $dirty[$key] = $value;
         } elseif ($value !== $cachedAttributes[$key] && !$this->originalIsNumericallyEquivalent($value, $cachedAttributes[$key])) {
             $dirty[$key] = $value;
         }
     }
     return $dirty;
 }
示例#3
0
 /**
  * Cache the link between parent and related
  * into the mapper's Entity Cache.
  *
  * @param  EntityCollection|Mappable $results result of the relation query
  * @param  string $relation Name of the relation method on the parent entity
  *
  * @return void
  */
 protected function cacheRelation($results, $relation)
 {
     $cache = $this->parentMapper->getEntityCache();
     $cache->cacheLoadedRelationResult($this->parent, $relation, $results, $this);
 }