/** * @param string $name * @param array $options * * @return bool */ public function isValid($name, array $options = []) { $options += ['referer' => null, 'token' => null]; if (null === $options['token']) { $params = $this->request->getParsedBody(); if (!isset($params[$name])) { $this->invalidate(); return false; } else { $options['token'] = $params[$name]; } } $error = false; $name .= $options['token']; $config = array_get([self::TOKEN_KEY, $name], $this->storage, []); $time = isset($config['expire']) ? $config['expire'] : 0; if (time() > $time) { $error = true; } if (!$error && null !== $options['referer']) { $params = $this->request->getServerParams(); if (!isset($params['HTTP_REFERER']) || $params['HTTP_REFERER'] !== $options['referer']) { $error = true; } } $regenerate = array_key_exists('regenerate', $config) ? $config['regenerate'] : false; if ($error || !$regenerate) { array_remove([self::TOKEN_KEY, $name], $this->storage); } elseif ($regenerate) { $config['expire'] = time() + $config['time']; array_set([self::TOKEN_KEY, $name], $config, $this->storage); } $this->invalidate(); return !$error; }
/** * {@inheritdoc} */ public function clearIdentities() { $identities = array_get(self::STORAGE_KEY, $this->session, []); foreach ($identities as $identity) { $identity->setDomain(null); $this->unObserve($identity); } array_remove(self::STORAGE_KEY, $this->session); }
/** * @param mixed $option */ public function removeOption($option) { array_remove($option, $this->options); }