Ejemplo n.º 1
0
 /**
  * If the accessed data entry is a MongoDB reference, fetch the
  * reference data and turn it into an object of the reference data
  * class.
  *
  * By default, it will create an object with the class name based on the
  * reference collection, but if it is mentioned in the mapping configuration,
  * it will use the mapping's setting instead. If the class does not exist,
  * an explanatory exception will be thrown.
  *
  * Other conversions: MongoDate to DateTime
  */
 public function __get($key)
 {
     $val = parent::__get($key);
     if ($val === null && !isset($this->_data[$key])) {
         return null;
     }
     if (MongoDBRef::isRef($val)) {
         $objectId = (string) $val['$id'];
         if (!isset(static::$_refCache[$objectId])) {
             static::$_refCache[$objectId] = static::getObject($val);
         }
         return static::$_refCache[$objectId];
     } elseif ($val instanceof MongoDate) {
         $val = self::getDate($val);
     }
     return $val;
 }
Ejemplo n.º 2
0
 /**
  * If the accessed data entry is a MongoDB reference, fetch the
  * reference data and turn it into an object of the reference data
  * class.
  *
  * By default, it will create an object with the class name based on the
  * reference collection, but if it is mentioned in the mapping configuration,
  * it will use the mapping's setting instead. If the class does not exist,
  * an explanatory exception will be thrown.
  *
  * Other conversions: MongoDate to DateTime
  */
 public function __get($key)
 {
     if (!isset($this->_data[$key])) {
         return null;
     }
     if (MongoDBRef::isRef($this->_data[$key])) {
         if (isset($this->_refCache[$key])) {
             return $this->_refCache[$key];
         }
         $resource = ZFE_Model_Mongo::getResource();
         $ref = $this->_data[$key]['$ref'];
         $cls = $resource->getClass($ref);
         if (!class_exists($cls)) {
             throw new ZFE_Model_Mongo_Exception("There is no model for the referred entity '" . $ref . "'.\n                    Consider creating {$cls} or add a class mapping in resources.mongo.mapping[].");
         }
         $val = $cls::map(MongoDBRef::get(self::getDatabase(), $this->_data[$key]));
         $this->_refCache[$key] = $val;
         return $val;
     }
     if ($this->_data[$key] instanceof MongoDate) {
         $val = new DateTime('@' . $this->_data[$key]->sec);
         $val->setTimeZone(new DateTimeZone(date_default_timezone_get()));
         return $val;
     }
     return parent::__get($key);
 }