/** * * @return Mongo */ protected function _get_mongo() { $instance_name = $this->_mongo_instance_name; $config = Mongostar_Model::getConfig()[$instance_name]; $options = isset($config['options']) ? $config['options'] : array(); $connection = "mongodb://" . $config['connection']['server']; self::$_mongos[$this->_mongo_instance_name] = new MongoClient($connection, $options); return self::$_mongos[$this->_mongo_instance_name]; }
<?php ini_set("display_errors", 1); error_reporting(E_ALL); require_once "vendor/autoload.php"; Mongostar_Model::setConfig(array('default' => array('connection' => array('server' => "localhost:27017", 'db' => 'hitman')))); /** * @property MongoId $id * @property string $name * @property int $age * * @method static User[] fetchAll(array $cond = null, array $sort = null, $count = null, $offset = null, $hint = NULL) * @method static User|null fetchOne(array $cond = null, array $sort = null) * @method static User fetchObject(array $cond = null, array $sort = null) */ class User extends Mongostar_Model { } $newUser = User::fetchObject(array('id' => null)); echo $newUser->name . "<br>"; die("lsjdlksj"); if (rand(0, 1)) { // User::remove(); } $user = User::fetchOne(array('id' => '54de8e1e9cd81ebf330041bc')); echo $user->name . "<br>"; $user->name = "User_name - " . rand(1000, 9999); $user->save(); $user = User::fetchOne(array('id' => '54de8e1e9cd81ebf330041bc')); echo $user->name . "<br>"; die;
/** * @throws Zend_Exception */ protected function _initDb() { $config = Zend_Registry::get('config'); Mongostar_Model::setConfig($config['db']); }
/** * @param string $name */ protected function __construct($name) { $this->_name = $name; $this->_config = Mongostar_Model::getConfig()[$name]; }
/** * Clear mappers */ public static function clearMappers() { self::$_mappers = array(); }