/** * Validates token for cookie and returns values if valid * * @param string $token * * @return array */ protected function parseAndValidateToken(string $token) { try { $token = (new Parser())->parse($token); // @todo How to test: It will use the current time to validate (iat, nbf and exp) $data = new ValidationData(); $data->setIssuer(self::ISSUER); $values = []; if ($token->validate($data) && $token->verify(new Sha256(), $this->configuration->get('Cookie.Signer.Key'))) { /** * @var Claim $claim */ $ignored = array_fill_keys(['iss', 'exp'], true); foreach ($token->getClaims() as $claim) { if (isset($ignored[$claim->getName()])) { continue; } $values[$claim->getName()] = $claim->getValue(); } } return $values; } catch (\InvalidArgumentException $e) { return []; } }
/** * @covers ::get */ public function testGetNonexistent() { $this->expectException(ConfigurationNonexistentException::class); $this->expectExceptionMessage('Configuration foo is nonexistent'); $configuration = new Configuration(); $configuration->get('foo'); }
/** * Get view template * * @return string View template file path */ protected function getViewTemplate() : string { $view = $this->view; if (empty($view)) { $view = sprintf('View/%s/%s', $this->getShortName(), $this->action); } return "{$this->configuration->get('App.Path')}{$view}.view"; }