コード例 #1
0
ファイル: document.php プロジェクト: enormego/EightPHP
 /**
  * Gets one of the following:
  *
  *  - A referenced object
  *  - A search() result
  *  - A field's value
  *
  * @param   string  field name
  * @return  mixed
  */
 public function __get($name)
 {
     $name = $this->get_field_name($name, FALSE);
     // Auto-loading for special references
     if (array_key_exists($name, $this->_references)) {
         if (!isset($this->_related_objects[$name])) {
             $model = isset($this->_references[$name]['model']) ? $this->_references[$name]['model'] : $name;
             $foreign_field = isset($this->_references[$name]['foreign_field']) ? $this->_references[$name]['foreign_field'] : FALSE;
             if ($foreign_field) {
                 $this->_related_objects[$name] = MongoDB_Document::factory($model)->collection(TRUE)->find($foreign_field, $this->id);
                 return $this->_related_objects[$name];
             }
             $id_field = isset($this->_references[$name]['field']) ? $this->_references[$name]['field'] : "_{$name}";
             $value = $this->__get($id_field);
             if (!empty($this->_references[$name]['multiple'])) {
                 $this->_related_objects[$name] = MongoDB_Document::factory($model)->collection(TRUE)->find(array('_id' => array('$in' => (array) $value)));
             } else {
                 // Extract just id if value is a DBRef
                 if (is_array($value) && isset($value['$id'])) {
                     $value = $value['$id'];
                 }
                 $this->_related_objects[$name] = MongoDB_Document::factory($model, $value);
             }
         }
         return $this->_related_objects[$name];
     }
     // Reload when retrieving dirty data
     if ($this->_loaded && empty($this->_operations) && !empty($this->_dirty[$name])) {
         $this->load();
     } else {
         if ($this->_loaded === NULL && isset($this->_object['_id']) && !isset($this->_changed['_id']) && $name != '_id') {
             $this->load();
         }
     }
     return isset($this->_object[$name]) ? $this->_object[$name] : NULL;
 }
コード例 #2
0
ファイル: collection.php プロジェクト: enormego/EightPHP
 /**
  * Instantiate an object conforming to Mongo_Collection conventions.
  *
  * @param   string  $name The model name to instantiate
  * @return  Mongo_Collection
  * @deprecated
  */
 public static function factory($name)
 {
     return MongoDB_Document::factory($name)->collection(TRUE);
 }