/** * 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); }
/** * 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}; }
/** * Gets the collection name * * @return string */ public function getCollectionClass() { return Client::instance()->getCollectionClass(); }
/** * 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); }
/** * Class constructor * * List of available options for `$config` array: * * * `group`: Mango config group name * * `collection`: The name of the collection * * `gc`: Number of requests before gc is invoked * * `fields`: Custom field names, array of: * * `session_id`: Session identifier * * `last_active`: Timestamp of the last activity * * `contents`: Serialized session data * * `hostname`: Host name * * `user_id`: The used ID * * [!!] Note: Sessions can only be created using the [Session::instance] method. * * @param array $config Configuration array [Optional] * @param string $id Session id [Optional] */ public function __construct(array $config = NULL, $id = NULL) { if (!isset($config['group'])) { // Use the default group $config['group'] = Client::$default; } // Create Mango instance $this->_db = Client::instance($config['group']); if (isset($config['collection'])) { // Save the collection name for later use $this->_collection = (string) $config['collection']; } if (isset($config['gc'])) { // Set the gc chance $this->_gc = (int) $config['gc']; } if (isset($config['columns'])) { // Overload column names $this->_columns = $config['columns']; } // Load the collection $this->_collection = $this->_db->selectCollection($this->_collection); parent::__construct($config, $id); if (mt_rand(0, $this->_gc) === $this->_gc) { // Run garbage collection // This will average out to run once every X requests $this->_gc(); } }