Esempio n. 1
0
 /**
  * Creates a new collection
  */
 public function __construct()
 {
     $arguments = func_get_args();
     if (!empty($arguments) && $arguments[0] instanceof \MongoCollection) {
         $this->_collection = $arguments[0];
     } else {
         $class = new \ReflectionClass('\\MongoCollection');
         $this->_collection = $class->newInstanceArgs($arguments);
     }
     $name = Inflector::getInstance()->camelize($this->_collection->getName());
     $searchKeys = array('{{mongo.coll}}');
     $searchVars = array(Inflector::getInstance()->camelize($name));
     $collectionClass = str_replace($searchKeys, $searchVars, Config::$collectionClass);
     $documentClass = str_replace($searchKeys, $searchVars, Config::$documentClass);
     $this->_collectionModel = '\\' . Config::$collectionNS . '\\' . $collectionClass;
     if (!class_exists($this->_collectionModel)) {
         throw new \RuntimeException($this->_collectionModel . ' was not found. Must have a collection model.');
     }
     $this->_documentModel = '\\' . Config::$documentNS . '\\' . $documentClass;
     if (!class_exists($this->_documentModel)) {
         $this->_documentModel = false;
     }
 }
Esempio n. 2
0
 /**
  * Getter
  */
 protected function _getter($name)
 {
     if ($name === '_id') {
         $camelName = 'Id';
     }
     if (!isset($this->_doc[$name])) {
         return null;
     }
     $method = 'get' . Inflector::getInstance()->camelize($name);
     if (method_exists($this, $method)) {
         $value = $this->{$method}();
     }
     $value = $this->_doc[$name];
     return $this->_stdDataType($value);
 }