Esempio n. 1
0
 public function testToArray()
 {
     $obj = new ZFE_Model_Base();
     $obj->init($this->testArray);
     $this->assertEquals($obj->toArray(), $this->testArray);
 }
Esempio n. 2
0
 public function getTranslation($key, $lang = null)
 {
     $translation = parent::getTranslation($key, $lang);
     return static::getObject($translation);
 }
Esempio n. 3
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);
 }