Example #1
0
 /**
  * Manipulate a namespace.
  * If session has not been previously started, it will be done
  * automatically.
  *
  * @param   string  $namespace      Namespace.
  * @param   string  $cache          Cache value (please, see static::*CACHE*
  *                                  constants).
  * @param   int     $cacheExpire    Cache expire (in seconds).
  * @return  void
  * @throws  \Hoa\Session\Exception
  * @throws  \Hoa\Session\Exception\Locked
  */
 public function __construct($namespace = '_default', $cache = null, $cacheExpire = null)
 {
     if (false !== strpos($namespace, '/')) {
         throw new Exception('Namespace must not contain a slash (/); given %s.', 0, $namespace);
     }
     $this->_namespace = $namespace;
     if (false === array_key_exists($namespace, static::$_lock)) {
         static::$_lock[$namespace] = false;
     }
     if (true === $this->isLocked()) {
         throw new Exception\Locked('Namespace %s is locked because it has been unset.', 1, $namespace);
     }
     static::start($cache, $cacheExpire);
     $this->initialize();
     $channel = static::EVENT_CHANNEL . $namespace;
     $expired = $channel . ':expired';
     if (false === Core\Event::eventExists($channel)) {
         Core\Event::register($channel, 'Hoa\\Session');
     }
     if (false === Core\Event::eventExists($expired)) {
         Core\Event::register($expired, 'Hoa\\Session');
     }
     if (true === $this->isExpired()) {
         $this->hasExpired();
     }
     $this->_profile['last_used']->setTimestamp(time());
     return;
 }
Example #2
0
 /**
  * Create an exception.
  * An exception is built with a formatted message, a code (an ID), and an
  * array that contains the list of formatted string for the message. If
  * chaining, we can add a previous exception.
  *
  * @param   string          $message      Formatted message.
  * @param   int             $code         Code (the ID).
  * @param   array           $arguments    Arguments to format message.
  * @param   \BaseException  $previous     Previous exception in chaining.
  * @return  void
  */
 public function __construct($message, $code = 0, $arguments = [], $previous = null)
 {
     parent::__construct($message, $code, $arguments, $previous);
     if (false === Core\Event::eventExists('hoa://Event/Exception')) {
         Core\Event::register('hoa://Event/Exception', __CLASS__);
     }
     $this->send();
     return;
 }