Beispiel #1
0
 /**
  * Class constructor
  *
  * Creates a new MongoDB logger using [\Gleez\Mango\Client]
  *
  * Example:<br>
  * <code>
  * $writer = new Log_Mango($collection);
  * </code>
  *
  * @param   string  $collection  Collection name [Optional]
  * @param   string  $name        Database instance name [Optional]
  *
  * @throws  \Gleez\Mango\Exception
  */
 public function __construct($collection = 'logs', $name = 'default')
 {
     $this->collection = $collection;
     $this->name = $name;
     // Getting Mango instance
     $this->db = Client::instance($this->name);
 }
Beispiel #2
0
 /**
  * Constructs the Mango cache driver
  *
  * The Mango cache driver must be instantiated using the [Cache::instance] method.
  *
  * [!!] Note: This method cannot be invoked externally.
  *
  * @param   array  $config  Config for Mango cache driver
  *
  * @uses    Arr::merge
  * @uses    Mango::$default
  * @uses    Mango::instance
  * @uses    Mango::__get
  * @uses    Cache::config
  * @uses    Cache::DEFAULT_EXPIRE
  */
 public function __construct(array $config)
 {
     // Set default config
     $default = array('driver' => 'mango', 'group' => Client::$default, 'collection' => 'cache', 'default_expire' => Cache::DEFAULT_EXPIRE);
     // Merge config
     $this->config(Arr::merge($default, $config));
     // Create default prefix
     $this->_config['prefix'] = isset($config['prefix']) ? $config['prefix'] . self::SEPARATOR : NULL;
     // Get collection name
     $collection = $this->config('collection');
     // Get \Gleez\Mango\Collection instance
     $this->collection = Client::instance($this->config('group'))->{$collection};
 }
Beispiel #3
0
 /**
  * Garbage collection
  *
  * @throws Session_Exception
  */
 protected function _gc()
 {
     if ($this->_lifetime) {
         // Expire sessions when their lifetime is up
         $expires = $this->_lifetime;
     } else {
         // Expire sessions after one month
         $expires = Date::MONTH;
     }
     $expired = __('this.:column < :time', array(':column' => $this->_columns['last_active'], ':time' => time() - $expires));
     try {
         $this->_collection->safeRemove(array('$where' => $expired));
     } catch (MongoException $e) {
         throw new Session_Exception('Cannot delete old sessions :err', array(':err' => $e->getMessage()));
     } catch (Exception $e) {
         throw new Session_Exception('Cannot delete old sessions :err', array(':err' => $this->_db->lastError()));
     }
 }
Beispiel #4
0
 /**
  * Get the Mango instance used for this collection
  *
  * @since   0.3.0  Initial Mango_Collection::getDB method
  * @since   0.7.0  Renamed to Mango_Collection::getMangoInstance
  * @since   1.0.0  Renamed to \Gleez\Mango\Collection::getClientInstance
  *
  * @return  \Gleez\Mango\Client
  *
  * @uses    \Gleez\Mango\Client::instance
  */
 public function getClientInstance()
 {
     return Client::instance($this->db);
 }
Beispiel #5
0
 /**
  * Gets the collection name
  *
  * @return  string
  */
 public function getCollectionClass()
 {
     return Client::instance()->getCollectionClass();
 }