/** * Executes the stored middleware routine. * * @param RequestInterface $request * @param TaskInterface $task * @param callable $next * * @return ResponseInterface */ public function execute(RequestInterface $request, TaskInterface $task, callable $next) : ResponseInterface { $collection = new Collection($_COOKIE); $accessor = new CookieAccessor($collection); $this->container->bind($accessor); /** * @var ResponseInterface $response */ $response = $next($request, $task); /* * Update the response to include new cookies and * delete existing ones by overriding them. */ foreach ($collection->all() as $name => $cookie) { /* * Check if the cookie has an 'expiration' key. Only new cookies * has this attribute and therefore only those should be added to the * response headers. */ if (!array_key_exists('expiration', $cookie)) { continue; } $response->headers()->write('Set-Cookie', $this->build($name, $cookie), false); } return $response; }
/** * Invokes the application. * * @param TaskInterface $task * * @return string */ private function dispatch(TaskInterface $task) : string { $handler = $task->handler(); $args = $task->args(); $instance = $this->container->create($handler); $payload = $this->container->call([$instance, 'execute'], $args); return $payload; }
/** * Executes the stored middleware routine. * * @param RequestInterface $request * @param TaskInterface $task * @param callable $next * * @return ResponseInterface */ public function execute(RequestInterface $request, TaskInterface $task, callable $next) : ResponseInterface { $handler = new PDOSessionHandler($this->pdo); $handler->register(false); $handler->start(); $this->persistent = new \ArrayObject($_SESSION['__PERSISTENT'] ?? []); $this->temporary = new \ArrayObject($_SESSION['__TEMPORARY__'] ?? []); $accessor = new SessionAccessor($this->persistent, new TemporarySessionAccessor($this->temporary)); /* * Bind the accessor instance to the request * application wide. */ $this->container->bind($accessor); return $next($request, $task); }
/** * {@inheritdoc} */ public function expand(ContainerInterface $container) { return $container->create($this->class, $this->args); }
/** * Builds the view and executes the methods. * * @param string $class * @param array $args * * @return mixed */ private function build(string $class, array $args) { $instance = $this->container->create($class, $args); $payload = $this->container->call([$instance, 'execute'], $args); return $payload; }
/** * Handles the given exception. * * @param \Exception $exception * @param ResponseInterface $response * @param array $args * * @return ResponseInterface */ public function handle(\Exception $exception, ResponseInterface $response, array $args = []) : ResponseInterface { $type = get_class($exception); $args = array_merge(['exception' => $exception, 'response' => $response], $args); return $this->container->call($this->callbacks[$type], $args); }