本文整理汇总了PHP中MongoCollection::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::__construct方法的具体用法?PHP MongoCollection::__construct怎么用?PHP MongoCollection::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::__construct方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @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: __construct
/**
* 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: __construct
/**
* 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: __construct
/**
* @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: __construct
/**
* 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: __construct
public function __construct($db, $name)
{
$this->db = $db;
parent::__construct($db, $name);
}
示例7:
function __construct(&$provider, $tableName)
{
$this->provider = $provider;
parent::__construct($this->provider->database, $tableName);
}
示例8: __construct
/**
* 构造函数
*
* @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);
}
示例9: __construct
public function __construct(MongoDB $mongoDB, $collection_name)
{
$this->mongodb = $mongoDB;
parent::__construct($this->mongodb, $collection_name);
}