當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Router::getContext方法代碼示例

本文整理匯總了PHP中Symfony\Component\Routing\Router::getContext方法的典型用法代碼示例。如果您正苦於以下問題:PHP Router::getContext方法的具體用法?PHP Router::getContext怎麽用?PHP Router::getContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Routing\Router的用法示例。


在下文中一共展示了Router::getContext方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: url

 /**
  * @throws \RunTimeException
  * @param null|\Sonata\PageBundle\Model\PageInterface|string $page
  * @param bool $absolute
  * @return string
  */
 public function url($page = null, $absolute = false)
 {
     if (!$page) {
         return '';
     }
     $context = $this->router->getContext();
     if ($page instanceof PageInterface) {
         if ($page->isDynamic()) {
             if ($this->environment->isDebug()) {
                 throw new \RunTimeException('Unable to generate path for dynamic page');
             }
             return '';
         }
         $url = $page->getCustomUrl() ?: $page->getUrl();
     } else {
         $url = $page;
     }
     $url = sprintf('%s%s', $context->getBaseUrl(), $url);
     if ($absolute && $context->getHost()) {
         $scheme = $context->getScheme();
         $port = '';
         if ('http' === $scheme && 80 != $context->getHttpPort()) {
             $port = ':' . $context->getHttpPort();
         } elseif ('https' === $scheme && 443 != $context->getHttpsPort()) {
             $port = ':' . $context->getHttpsPort();
         }
         $url = $scheme . '://' . $context->getHost() . $port . $url;
     }
     return $url;
 }
開發者ID:norfil,項目名稱:SonataPageBundle,代碼行數:36,代碼來源:PageExtension.php

示例2: loadRoutes

 public function loadRoutes($path, $options = array())
 {
     $filelocator = new FileLocator($path);
     $routeloader = new YamlFileLoader($filelocator);
     $router = new Router($routeloader, $path, $options);
     $matcher = $router->getMatcher();
     $routeCollection = $router->getRouteCollection();
     $context = $router->getContext();
     $this->dispatcher->addSubscriber(new HttpKernel\EventListener\RouterListener($matcher));
     $this->shared['url.generator'] = new UrlGenerator($routeCollection, $context);
     $this->router = $router;
     return $router->getRouteCollection();
 }
開發者ID:ubick,項目名稱:glue,代碼行數:13,代碼來源:Application.php

示例3: setBaseUrl

 /**
  * Sets the base URL.
  *
  * @param string $baseUrl Base URL.
  *
  * @return RouteRenderer
  */
 public function setBaseUrl($baseUrl)
 {
     $this->baseUrl = '/' . trim(trim($baseUrl), '/');
     $this->router->getContext()->setBaseUrl($this->baseUrl);
     return $this;
 }
開發者ID:braincrafted,項目名稱:static-site-bundle,代碼行數:13,代碼來源:RouteRenderer.php

示例4: getBaseUrl

 /**
  * Get curent request base url path.
  *
  * @param string $path path to be appended to base url
  *
  * @return string composed path
  */
 public function getBaseUrl($path = '')
 {
     $context = $this->symfonyRouter->getContext();
     $baseUrl = $context->getScheme() . '://' . $context->getHost() . $path;
     return $baseUrl;
 }
開發者ID:sourcefabric,項目名稱:newscoop,代碼行數:13,代碼來源:LinkService.php


注:本文中的Symfony\Component\Routing\Router::getContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。