示例#1
0
 /**
  * Get a stream in the register.
  * If the stream does not exist, try to open it by calling the
  * $handler->_open() method.
  *
  * @param   string       $streamName    Stream name.
  * @param   \Hoa\Stream  $handler       Stream handler.
  * @param   string       $context       Context ID (please, see the
  *                                      \Hoa\Stream\Context class).
  * @return  array
  * @throws  \Hoa\Stream\Exception
  */
 private static final function &_getStream($streamName, Stream $handler, $context = null)
 {
     $name = md5($streamName);
     if (null !== $context) {
         if (false === Context::contextExists($context)) {
             throw new Exception('Context %s was not previously declared, cannot retrieve ' . 'this context.', 0, $context);
         }
         $context = Context::getInstance($context);
     }
     if (!isset(self::$_register[$name])) {
         self::$_register[$name] = [self::NAME => $streamName, self::HANDLER => $handler, self::RESOURCE => $handler->_open($streamName, $context), self::CONTEXT => $context];
         Core\Event::register('hoa://Event/Stream/' . $streamName, $handler);
         // Add :open-ready?
         Core\Event::register('hoa://Event/Stream/' . $streamName . ':close-before', $handler);
     } else {
         $handler->_borrowed = true;
     }
     if (null === self::$_register[$name][self::RESOURCE]) {
         self::$_register[$name][self::RESOURCE] = $handler->_open($streamName, $context);
     }
     return self::$_register[$name];
 }
示例#2
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;
 }
示例#3
0
文件: Log.php 项目: Grummfy/Central
 /**
  * Make a multiton.
  *
  * @access  public
  * @param   string      $id        Channel ID (i.e. singleton ID)
  * @return  \Hoa\Log
  * @throw   \Hoa\Log\Exception
  */
 public static function getChannel($id = null)
 {
     if (null === self::$_currentId && null === $id) {
         throw new Exception('Must precise a singleton index once.', 0);
     }
     if (!isset(self::$_instances[$id])) {
         self::$_instances[$id] = new self();
         \Hoa\Core\Event::register('hoa://Event/Log/' . $id, self::$_instances[$id]);
     }
     if (null !== $id) {
         self::$_currentId = $id;
     }
     $handle = self::$_instances[self::$_currentId];
     return $handle;
 }
示例#4
0
文件: Dal.php 项目: Grummfy/Central
 /**
  * Create a DAL instance, representing a connection to a database.
  * The constructor is private to make a multiton.
  *
  * @param   string  $dalName          The database abstract layer name.
  * @param   string  $dsn              The DSN of database.
  * @param   string  $username         The username to connect to database.
  * @param   string  $password         The password to connect to database.
  * @param   array   $driverOptions    The driver options.
  * @return  void
  * @throws  \Hoa\Database\Exception
  */
 private function __construct($dalName, $dsn, $username, $password, array $driverOptions = [])
 {
     // Please see https://bugs.php.net/55154.
     if (0 !== preg_match('#^sqlite:(.+)$#i', $dsn, $matches)) {
         $dsn = 'sqlite:' . resolve($matches[1]);
     }
     $id = $this->__id = self::$_id;
     $event = 'hoa://Event/Database/' . $id;
     Core\Event::register($event . ':opened', $this);
     Core\Event::register($event . ':closed', $this);
     $this->setDal(dnew('\\Hoa\\Database\\Layer\\' . $dalName, [$dsn, $username, $password, $driverOptions]));
     Core\Event::notify($event . ':opened', $this, new Core\Event\Bucket(['id' => $id, 'dsn' => $dsn, 'username' => $username, 'driverOptions' => $driverOptions]));
     return;
 }
示例#5
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;
 }
示例#6
0
文件: Window.php 项目: alexpw/Console
 /**
  * Set the event channel.
  * We need to declare(ticks = 1) in the main script to ensure that the event
  * is fired. Also, we need the pcntl_signal() function enabled.
  *
  * @access  public
  * @return  void
  */
 public function __construct()
 {
     \Hoa\Core\Event::register('hoa://Event/Console/Window:resize', $this);
     return;
 }