Beispiel #1
0
 /**
  * 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');
     }
 }
Beispiel #2
0
 /**
  * @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;
 }
Beispiel #3
0
 /**
  * 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));
 }