function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $settings = $this->kernelSettings;
     $session = $this->session;
     $this->redirection->setRequest($request);
     // Start the sessions engine.
     session_name($settings->name);
     $name = session_name();
     session_start();
     // Load the saved session (if any).
     /** @var AssignableInterface $savedSession */
     if (($savedSession = get($_SESSION, '#data')) && $savedSession instanceof AssignableInterface) {
         $this->session->import($savedSession->export());
     }
     // (Re)initialize some session settings.
     $session->name = $name;
     // Setup current session to be saved on shutdown.
     $_SESSION['#data'] = $session;
     $flashMessage = $session->getFlashMessage();
     if ($flashMessage) {
         $this->renderFlashMessage($flashMessage['type'], $flashMessage['message']);
     }
     // Run the next middleware, catching any flash message exceptions.
     try {
         return $next($request);
     } catch (FlashMessageException $flash) {
         $session->flashMessage($flash->getMessage(), $flash->getCode(), $flash->getTitle());
         $post = $request->getParsedBody();
         if (is_array($post)) {
             $session->flashInput($post);
         }
         return $this->redirection->refresh();
     }
 }
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $this->redirection->setRequest($request);
     switch ($request->getMethod()) {
         case 'GET':
             if (!$this->session->loggedIn()) {
                 return $this->redirection->guest($this->settings->getLoginUrl());
             }
             break;
     }
     return $next();
 }
Exemplo n.º 3
0
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $this->redirection->setRequest($request);
     $base = $this->settings->urlPrefix();
     $base = $base ? "{$base}..." : '*';
     return $this->router->set([$base => [when($this->settings->requireAuthentication(), AuthenticationMiddleware::class), '.' => page('platform/home.html'), 'settings...' => [when($this->settings->enableUsersManagement(), ['users-management...' => ['users' => factory(function (UsersPage $page) {
         // This is done here just to show off this possibility
         $page->templateUrl = 'platform/users/users.html';
         return $page;
     }), 'users/@id' => UserPage::class, 'profile' => factory(function (UserPage $page) {
         $page->editingSelf = true;
         return $page;
     })]])]]])->__invoke($request, $response, $next);
 }
 protected function autoRedirect()
 {
     if (isset($this->indexPage)) {
         return $this->redirection->to($this->indexPage);
     }
     return $this->redirection->refresh();
 }