getContext() public method

Gets the request context.
public getContext ( ) : Symfony\Component\Routing\RequestContext
return Symfony\Component\Routing\RequestContext The context
Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 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();
 }
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }