コード例 #1
0
 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();
     }
 }
コード例 #2
0
 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();
 }
コード例 #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);
 }
コード例 #4
0
 /**
  * Performs the main execution sequence.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  * @return ResponseInterface
  * @throws FatalException
  * @throws FileException
  * @throws FlashMessageException
  */
 function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if (!$this->kernelSettings) {
         throw new FatalException("Class <kbd class=type>" . get_class($this) . "</kbd>'s constructor forgot to call <kbd>parent::__construct()</kbd>");
     }
     $this->request = $request;
     $this->response = $response;
     $this->redirection->setRequest($request);
     $this->currentLink = $this->navigation->currentLink();
     $this->navigation->getCurrentTrail();
     if (!$this->indexPage && $this->autoRedirectUp && $this->currentLink && ($parent = $this->currentLink->parent())) {
         $this->indexPage = $parent->url();
     }
     // remove page number parameter
     $this->URI_noPage = preg_replace('#&?' . $this->kernelSettings->pageNumberParam . '=\\d*#', '', $this->request->getUri()->getPath());
     $this->URI_noPage = preg_replace('#\\?$#', '', $this->URI_noPage);
     $this->initialize();
     //custom setup
     $this->modelController->setRequest($request);
     $this->model();
     $this->modelController->handleRequest();
     $this->model = $this->modelController->getModel();
     switch ($this->request->getMethod()) {
         /** @noinspection PhpMissingBreakStatementInspection */
         case 'POST':
             // Perform the requested action.
             $res = $this->doFormAction();
             if ($res) {
                 if (!$res instanceof ResponseInterface) {
                     throw new FatalException(sprintf("Invalid HTTP response type: %s<p>Expected: <kbd>%s</kbd>", Debug::typeInfoOf($res), Debug::formatClassName(ResponseInterface::class)));
                 }
                 $response = $res;
             }
             if (!$this->renderOnAction) {
                 if (!$res) {
                     $response = $this->autoRedirect();
                 }
                 break;
             }
             // Fall through.
         // Fall through.
         case 'GET':
             // Render the component.
             $out = $this->getRendering();
             $response->getBody()->write($out);
     }
     $this->finalize($response);
     return $response;
 }