/**
  * 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;
 }