本文整理汇总了PHP中Mongo::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Mongo::getInstance方法的具体用法?PHP Mongo::getInstance怎么用?PHP Mongo::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mongo
的用法示例。
在下文中一共展示了Mongo::getInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* Establishes a Config instance for all children to enjoy
*/
public function __construct()
{
// @todo Lazy load these so we're not loading them on every instance
$this->config = Config::getInstance();
$this->mongo = Mongo::getInstance();
//$this->redis = Redis::getInstance();
// Optionally logs the constructor to the profiler
if ($this->config['profiler']) {
Profiler::log($this, '__construct');
}
}
示例2: find
/**
* @param array $query
* @param array $sort
* @param null|int $limit
* @param null|int $skip
* @return array
*/
public function find(array $query = array(), array $sort = array(), $limit = null, $skip = null)
{
if (!Mongo::getInstance()->isAuthDisabled()) {
// TODO: add support for $and and $or queries
if (isset($query['className'])) {
if (is_array($query['className']) && !empty($query['className']['$in'])) {
$newIn = array();
foreach ($query['className']['$in'] as $className) {
if (Mongo::getInstance()->getUser()->can($className, 'read')) {
$newIn[] = $className;
}
}
if (empty($newIn)) {
return array();
}
$query['className']['$in'] = $newIn;
} elseif (is_string($query['className']) && !Mongo::getInstance()->getUser()->can($query['className'], 'read')) {
return array();
}
} else {
$query['className'] = array('$in' => Mongo::getInstance()->getUser()->getPermissions('read'));
}
}
$cursor = $this->_getCollection()->find($query);
if (!empty($sort)) {
try {
$cursor->sort($sort);
} catch (\Exception $e) {
// continue with unsorted cursor
}
}
if (!is_null($limit)) {
$cursor->limit(intval($limit));
}
if (!is_null($skip)) {
$cursor->skip(intval($skip));
}
$results = array();
foreach ($cursor as $r) {
if (empty($r['className'])) {
// TODO: logging
continue;
}
$results[] = Mongo::factory($r['className'], $r);
}
return $results;
}
示例3: can
/**
* Checks if user can perform an operation.
*
* @param string $className
* @param string $operation
* @return bool
*/
public function can($className, $operation)
{
if (Mongo::getInstance()->isAuthDisabled()) {
return true;
}
return in_array($className, $this->getPermissions($operation));
}