Exemplo n.º 1
0
 /**
  * Construct the validation chain
  *
  * Retrieves validators from session storage and attaches them.
  *
  * @param Storage $storage
  */
 public function __construct(Storage $storage)
 {
     $this->storage = $storage;
     $validators = $storage->getMetadata('_VALID');
     if ($validators) {
         foreach ($validators as $validator => $data) {
             $this->attach('session.validate', array(new $validator($data), 'isValid'));
         }
     }
 }
 /**
  * Construct the validation chain
  *
  * Retrieves validators from session storage and attaches them.
  *
  * Duplicated in ValidatorChainEM3 to prevent trait collision with parent.
  *
  * @param StorageInterface $storage
  */
 public function __construct(StorageInterface $storage)
 {
     parent::__construct();
     $this->storage = $storage;
     $validators = $storage->getMetadata('_VALID');
     if ($validators) {
         foreach ($validators as $validator => $data) {
             $this->attachValidator('session.validate', [new $validator($data), 'isValid'], 1);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Expire key by session hops
  *
  * Determines whether the container or an individual key within it has
  * expired based on session hops
  *
  * @param  Storage $storage
  * @param  string $name
  * @param  string $key
  * @return bool
  */
 protected function expireByHops(Storage $storage, $name, $key)
 {
     $ts = $storage->getRequestAccessTime();
     $metadata = $storage->getMetadata($name);
     // Global container expiry
     if (is_array($metadata) && isset($metadata['EXPIRE_HOPS']) && $ts > $metadata['EXPIRE_HOPS']['ts']) {
         $metadata['EXPIRE_HOPS']['hops']--;
         if (-1 === $metadata['EXPIRE_HOPS']['hops']) {
             unset($metadata['EXPIRE_HOPS']);
             $storage->setMetadata($name, $metadata, true);
             $storage[$name] = $this->createContainer();
             return true;
         }
         $metadata['EXPIRE_HOPS']['ts'] = $ts;
         $storage->setMetadata($name, $metadata, true);
         return false;
     }
     // Single key expiry
     if (null !== $key && is_array($metadata) && isset($metadata['EXPIRE_HOPS_KEYS']) && isset($metadata['EXPIRE_HOPS_KEYS'][$key]) && $ts > $metadata['EXPIRE_HOPS_KEYS'][$key]['ts']) {
         $metadata['EXPIRE_HOPS_KEYS'][$key]['hops']--;
         if (-1 === $metadata['EXPIRE_HOPS_KEYS'][$key]['hops']) {
             unset($metadata['EXPIRE_HOPS_KEYS'][$key]);
             $storage->setMetadata($name, $metadata, true);
             unset($storage[$name][$key]);
             return true;
         }
         $metadata['EXPIRE_HOPS_KEYS'][$key]['ts'] = $ts;
         $storage->setMetadata($name, $metadata, true);
         return false;
     }
     // Find all expired keys
     if (null === $key && is_array($metadata) && isset($metadata['EXPIRE_HOPS_KEYS'])) {
         foreach (array_keys($metadata['EXPIRE_HOPS_KEYS']) as $key) {
             if ($ts > $metadata['EXPIRE_HOPS_KEYS'][$key]['ts']) {
                 $metadata['EXPIRE_HOPS_KEYS'][$key]['hops']--;
                 if (-1 === $metadata['EXPIRE_HOPS_KEYS'][$key]['hops']) {
                     unset($metadata['EXPIRE_HOPS_KEYS'][$key]);
                     $storage->setMetadata($name, $metadata, true);
                     unset($storage[$name][$key]);
                     continue;
                 }
                 $metadata['EXPIRE_HOPS_KEYS'][$key]['ts'] = $ts;
             }
         }
         $storage->setMetadata($name, $metadata, true);
         return false;
     }
     return false;
 }