Example #1
0
 /**
  * Performs the internal steps of initialising a session
  *
  * @author Art <*****@*****.**>
  *
  * @param Alo\Db\MySQL|Alo\Cache\AbstractCache $dependcyObject Session handlers have a dependency, e.g. a MySQL
  *                                                             instance for MySQLSession, a RedisWrapper instance
  *                                                             for RedisSession etc. You can provide an object
  *                                                             reference containing such an instance here,
  *                                                             otherwise Alo::$db/Alo::$cache will be used.
  * @param string                               $handler        If you want to test a session with a different
  *                                                             handler you can overwrite it here by passing a
  *                                                             class name
  */
 protected static function initSession(&$dependcyObject = null, $handler = ALO_SESSION_HANDLER)
 {
     if (session_status() !== PHP_SESSION_ACTIVE) {
         session_set_cookie_params(ALO_SESSION_TIMEOUT, '/', null, ALO_SESSION_SECURE, true);
         session_name(ALO_SESSION_COOKIE);
         /** @var Alo\Session\AbstractSession $handler */
         $handler = new $handler($dependcyObject);
         session_set_save_handler($handler, true);
         session_start();
         $handler->identityCheck();
     } else {
         phpWarning('A session has already been started');
     }
 }
 /**
  * Instantiates the class
  *
  * @author Art <*****@*****.**>
  *
  * @param boolean $initDefaultServer Whether to add a server on construct
  */
 function __construct($initDefaultServer = true)
 {
     if (self::$loaded === null) {
         if (class_exists('\\Memcached', false)) {
             self::$loaded = self::CLASS_MEMCACHED;
         } elseif (class_exists('\\Memcache')) {
             self::$loaded = self::CLASS_MEMCACHE;
         } else {
             self::$loaded = false;
         }
     }
     if (self::$loaded !== null) {
         $this->client = self::$loaded === self::CLASS_MEMCACHED ? new Memcached() : new Memcache();
         if ($initDefaultServer) {
             $this->addServer();
         }
     } else {
         phpWarning('Memcached extension not loaded - caching ' . 'functions will not work');
     }
     parent::__construct();
     \Log::debug(self::$loaded ? 'Loaded MemcachedWrapper' : 'MemcachedWrapper not loaded: extension unavailable');
 }
Example #3
0
 /**
  * Applies a callback to the rows matching the filter. This will modify the data in the object.
  * @author Art <*****@*****.**>
  *
  * @param callable $callable The callback function. It should accept the first parameter which is the
  *                           array of associative arrays that matches the filter.
  * @param array    $where
  *
  * @return bool|mixed false if $callable isn't callable or whatever your callback returns.
  */
 function applyCallbackWhere($callable, $where = null)
 {
     if (!is_callable($callable)) {
         phpWarning('The supplied callback isn\'t callable');
         return false;
     } else {
         if ($where) {
             $get =& $this->getWhereReferential($where);
         } else {
             $get =& $this->data;
         }
         return call_user_func($callable, $get);
     }
 }
Example #4
0
 /**
  * Removes a token from session data
  *
  * @author Art <*****@*****.**>
  *
  * @param string $tokenName The token's name
  *
  * @return bool TRUE if the session handler was loaded, false if not
  */
 static function tokenRemove($tokenName)
 {
     if (AbstractSession::isActive()) {
         unset($_SESSION[$tokenName]);
         return true;
     } else {
         phpWarning('Session not initialised - tokens unavailable.');
         return false;
     }
 }