/** * Check authenticate. * * @param ExecuteActionEvent $event * @param Config $config * @throws ValueNotFoundException * @throws PermissionDeniedException */ private function execute(ExecuteActionEvent $event, $config) { $request = $event->getRequest(); $session = $request->getSession(); try { $session->get('authenticate.user_id'); if ($this->maxTime > 0) { if ($session->get('authenticate.epoch') < time()) { //deprecated session $session->clear(); throw new ValueNotFoundException('authenticate.epoch'); } $session->set('authenticate.epoch', time() + $this->maxTime); } if ($config->getAttribute('auth-redirect') !== false) { $response = $this->createResponseRedirect($config->getAttribute('auth-redirect'), $request); $event->setResponse($response); } } catch (ValueNotFoundException $e) { if ($config->getAttribute('unauth-redirect') !== false) { $response = $this->createResponseRedirect($config->getAttribute('unauth-redirect'), $request); $event->setResponse($response); } else { if ($config->getAttribute('auth-redirect') !== false) { //ignore } else { throw new PermissionDeniedException(); } } } }
/** * Constructor. * * @param Config $config * @param Container $container * @param Request $request * @param Environment $environment * @param Presenter[] $presenters */ public function __construct(Config $config, Container $container, Request $request, Environment $environment, array $presenters) { $this->config = $config; $this->className = $config->getAttribute('class'); $this->methodName = $config->getAttribute('method'); $this->presenterName = $config->getAttribute('presenter'); $this->presenters = $presenters; $this->request = $request; $this->container = $container; $this->environment = $environment; }
/** * Constructor. * * @param Config $config * @param DependencyInjection $dependencyInjection * @param mixed[] $arguments */ public function __construct(Config $config, DependencyInjection $dependencyInjection, $arguments) { $this->config = $config; $this->className = $config->getAttribute('class'); $this->dependencyInjection = $dependencyInjection; $this->arguments = $arguments; }
/** * * @param Config $methodNode * @return MetadataMethod */ private function getMetadataDependencyMethod(Config $methodNode) { $metadataMethod = new MetadataMethod($methodNode->getAttribute('name')); foreach ($methodNode->getNodes('argument') as $argumentNode) { /** * @var Config $argumentNode */ $metadataMethod->addArgument($argumentNode->getAttribute('type'), $argumentNode->getAttribute('value')); } return $metadataMethod; }
/** * Validate GET. * * @param string[] $data http post/get data * @param Config $config argument * @param int $position * @return string * @throws RequiredArgumentException */ private function validateGetPost($data, $config, $position) { $argumentName = $config->getAttribute('name'); $default = $config->getAttribute('default'); if (!isset($data[$argumentName])) { if ($default !== false) { return $default; } else { throw new RequiredArgumentException($position, $argumentName); } } return $data[$argumentName]; }