__construct() public method

Creates a new collection
public __construct ( MongoDB $db, string $name )
$db MongoDB Parent database.
$name string Name for this collection.
示例#1
0
 /**
  * @param \MongoDB $db
  * @param string   $name
  * @param string   $documentClass
  */
 public function __construct(\MongoDB $db, $name, $documentClass = null)
 {
     if (isset($documentClass) && !is_a($documentClass, Entity::class, true)) {
         throw new \LogicException("Class {$documentClass} is not a " . Entity::class);
     }
     $this->documentClass = $documentClass;
     parent::__construct($db, $name);
 }
示例#2
0
 /**
  * Creates new file collections
  *
  * @param mongodb $db - Database.
  * @param string $prefix -
  * @param mixed $chunks -
  */
 public function __construct(MongoDB $db, $prefix = 'fs', $chunks = 'fs')
 {
     $this->db = $db;
     $thisName = $prefix . '.files';
     $this->chunksName = $prefix . '.chunks';
     $this->chunks = $db->selectCollection($this->chunksName);
     parent::__construct($db, $thisName);
 }
示例#3
0
 /**
  * Files as stored across two collections, the first containing file meta
  * information, the second containing chunks of the actual file. By default,
  * fs.files and fs.chunks are the collection names used.
  *
  * @link http://php.net/manual/en/mongogridfs.construct.php
  * @param MongoDB $db Database
  * @param string $prefix [optional] <p>Optional collection name prefix.</p>
  * @param mixed $chunks  [optional]
  * @throws \Exception
  */
 public function __construct(MongoDB $db, $prefix = "fs", $chunks = null)
 {
     if ($chunks) {
         trigger_error("The 'chunks' argument is deprecated and ignored", E_DEPRECATED);
     }
     if (empty($prefix)) {
         throw new \Exception('MongoGridFS::__construct(): invalid prefix');
     }
     $this->database = $db;
     $this->prefix = (string) $prefix;
     $this->filesName = $prefix . '.files';
     $this->chunksName = $prefix . '.chunks';
     $this->chunks = $db->selectCollection($this->chunksName);
     parent::__construct($db, $this->filesName);
 }
示例#4
0
 /**
  * @param \MongoDB $db
  * @param string $name
  * @param CacheInterface $cache
  * @throws Exception
  * @return MongoCollection
  */
 public function __construct(\MongoDB $db, $name, CacheInterface $cache)
 {
     parent::__construct($db, $name);
     $this->cache = $cache;
 }
示例#5
0
 /**
  * Constructor.
  *
  * @param \Mandango\Logger\LoggableMongoDB $db             A LoggableMongoDB instance.
  * @param string                           $collectionName The collection name.
  */
 public function __construct(LoggableMongoDB $db, $collectionName)
 {
     $this->db = $db;
     $this->time = new Time();
     parent::__construct($db, $collectionName);
 }
示例#6
0
 public function __construct($db, $name)
 {
     $this->db = $db;
     parent::__construct($db, $name);
 }
示例#7
0
 function __construct(&$provider, $tableName)
 {
     $this->provider = $provider;
     parent::__construct($this->provider->database, $tableName);
 }
示例#8
0
 /**
  * 构造函数
  *
  * @param Config $config            
  * @param string $collection            
  * @param string $database            
  * @param string $cluster            
  * @param string $collectionOptions            
  * @throws \Exception
  */
 public function __construct(Config $config, $collection = null, $database = DEFAULT_DATABASE, $cluster = DEFAULT_CLUSTER, $collectionOptions = null)
 {
     // 检测是否加载了FirePHP
     if (!class_exists("FirePHP")) {
         throw new \Exception('请安装FirePHP');
     }
     if (!class_exists("MongoClient")) {
         throw new \Exception('请安装MongoClient');
     }
     if ($collection === null) {
         throw new \Exception('$collection集合为空');
     }
     $this->_collection = $collection;
     $this->_database = $database;
     $this->_cluster = $cluster;
     $this->_collectionOptions = $collectionOptions;
     $this->_configInstance = $config;
     $this->_config = $config->toArray();
     if (!isset($this->_config[$this->_cluster])) {
         throw new \Exception('Config error:no cluster key');
     }
     if (!isset($this->_config[$this->_cluster]['dbs'][$this->_database])) {
         throw new \Exception('Config error:no database init');
     }
     if (!isset($this->_config[$this->_cluster]['dbs'][DB_ADMIN])) {
         throw new \Exception('Config error:admin database init');
     }
     if (!isset($this->_config[$this->_cluster]['dbs'][DB_BACKUP])) {
         throw new \Exception('Config error:backup database init');
     }
     if (!isset($this->_config[$this->_cluster]['dbs'][DB_MAPREDUCE])) {
         throw new \Exception('Config error:mapreduce database init');
     }
     $this->_db = $this->_config[$this->_cluster]['dbs'][$this->_database];
     if (!$this->_db instanceof \MongoDB) {
         throw new \Exception('$this->_db is not instanceof \\MongoDB');
     }
     $this->_admin = $this->_config[$this->_cluster]['dbs'][DB_ADMIN];
     if (!$this->_admin instanceof \MongoDB) {
         throw new \Exception('$this->_admin is not instanceof \\MongoDB');
     }
     $this->_backup = $this->_config[$this->_cluster]['dbs'][DB_BACKUP];
     if (!$this->_backup instanceof \MongoDB) {
         throw new \Exception('$this->_backup is not instanceof \\MongoDB');
     }
     $this->_mapreduce = $this->_config[$this->_cluster]['dbs'][DB_MAPREDUCE];
     if (!$this->_mapreduce instanceof \MongoDB) {
         throw new \Exception('$this->_mapreduce is not instanceof \\MongoDB');
     }
     $this->_fs = new \MongoGridFS($this->_db, GRIDFS_PREFIX);
     // 默认执行几个操作
     // 第一个操作,判断集合是否创建,如果没有创建,则进行分片处理(目前采用_ID作为片键)
     if (APPLICATION_ENV === 'production') {
         $this->shardingCollection();
     }
     parent::__construct($this->_db, $this->_collection);
     /**
      * 设定读取优先级
      * MongoClient::RP_PRIMARY 只读取主db
      * MongoClient::RP_PRIMARY_PREFERRED 读取主db优先
      * MongoClient::RP_SECONDARY 只读从db优先
      * MongoClient::RP_SECONDARY_PREFERRED 读取从db优先
      */
     // $this->db->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED);
     $this->db->setReadPreference(\MongoClient::RP_PRIMARY_PREFERRED);
 }
 public function __construct(MongoDB $mongoDB, $collection_name)
 {
     $this->mongodb = $mongoDB;
     parent::__construct($this->mongodb, $collection_name);
 }