function url($url = null)
 {
     if (is_null($url)) {
         if (isset($this->cachedUrl)) {
             return $this->cachedUrl;
         }
         if (is_callable($url = $this->url)) {
             $url = $url();
         }
         if (isset($url) && $this->parent && ($url === '' || $url[0] != '/') && !preg_match('/^\\w+:/', $url)) {
             $base = $this->parent->url();
             $url = exists($base) ? exists($url) ? "{$base}/{$url}" : $base : $url;
         } else {
             if ($url && $url[0] == '/') {
                 $url = $this->getRequest()->getAttribute('baseUri') . $url;
             }
         }
         $this->url = $url;
         if (exists($url)) {
             $url = $this->evaluateUrl($url);
         }
         return $this->cachedUrl = $url;
     }
     //else DO NOT CACHE IT YET!
     $this->url = $url;
     return $this;
 }
 /**
  * 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;
 }
예제 #3
0
 private function linkIsActive(NavigationLinkInterface $link, $url)
 {
     $linkUrl = $link->url();
     if ($linkUrl === $url) {
         return true;
     }
     foreach ($link->links() as $sub) {
         if ($this->linkIsActive($sub, $url)) {
             return true;
         }
     }
     return false;
 }