Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param string                        $configName     Name of the session config.
  * @param \YapepBase\Storage\IStorage   $storage        The storage object.
  * @param bool                          $autoRegister   If TRUE, it will automatically register as an event handler.
  *
  * @throws \YapepBase\Exception\ConfigException   On configuration problems
  * @throws \YapepBase\Exception\Exception         On other problems
  */
 public function __construct($configName, IStorage $storage, $autoRegister = true)
 {
     if (!$storage->isTtlSupported()) {
         throw new Exception('Storage without TTL support passed to session handler.');
     }
     $this->storage = $storage;
     $properties = array('namespace', 'lifetime');
     $properties = array_merge($properties, $this->getConfigProperties());
     $configData = array();
     foreach ($properties as $property) {
         try {
             $configData[$property] = Config::getInstance()->get('resource.session.' . $configName . '.' . $property);
         } catch (ConfigException $e) {
             // We just swallow this because we don't know what properties do we need in advance
         }
     }
     if (empty($configData)) {
         throw new ConfigException('Configuration not found for session handler: ' . $configName);
     }
     if (!isset($configData['namespace'])) {
         throw new ConfigException('No namespace has been set for the session handler: ' . $configName);
     }
     $this->validateConfig($configData);
     $this->namespace = $configData['namespace'];
     $this->lifetime = empty($configData['lifetime']) ? self::DEFAULT_LIFETIME : (int) $configData['lifetime'];
     if ($autoRegister) {
         $this->registerEventHandler();
     }
     $this->id = $this->getSessionId();
 }