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();
     }
 }
 protected function autoRedirect()
 {
     if (isset($this->indexPage)) {
         return $this->redirection->to($this->indexPage);
     }
     return $this->redirection->refresh();
 }