当前位置: 首页>>代码示例>>PHP>>正文


PHP RequestContext::setBaseUrl方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\RequestContext::setBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::setBaseUrl方法的具体用法?PHP RequestContext::setBaseUrl怎么用?PHP RequestContext::setBaseUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\RequestContext的用法示例。


在下文中一共展示了RequestContext::setBaseUrl方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($BaseUrl = '')
 {
     AutoLoader::getNamespaceAutoLoader('Symfony\\Component', __DIR__ . '/../../../Vendor/');
     AutoLoader::getNamespaceAutoLoader('Symfony\\Component', __DIR__ . '/../../../../../Core/HttpKernel/Vendor/');
     $this->SymfonyRouteCollection = new RouteCollection();
     $this->SymfonyRequestContext = new RequestContext();
     $this->SymfonyRequestContext->setBaseUrl($BaseUrl);
     $this->SymfonyUrlMatcher = new UrlMatcher($this->SymfonyRouteCollection, $this->SymfonyRequestContext);
     $this->SymfonyEventDispatcher = new EventDispatcher();
     $this->SymfonyEventDispatcher->addSubscriber(new RouterListener($this->SymfonyUrlMatcher));
     $this->SymfonyHttpKernel = new HttpKernel($this->SymfonyEventDispatcher, new ControllerResolver());
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:12,代码来源:SymfonyRouter.php

示例2: init

 protected function init(RouteCollection $routes)
 {
     $context = new RequestContext();
     $context->fromRequest($this->request);
     $context->setBaseUrl($this->options['basepath']);
     $this->matcher = new UrlMatcher($routes, $context);
     $this->generator = new UrlGenerator($routes, $context);
 }
开发者ID:keeko,项目名称:framework,代码行数:8,代码来源:AbstractRouter.php

示例3: testComposeSchemaHostAndBasePathWithBackSplashOnResolve

 public function testComposeSchemaHostAndBasePathWithBackSplashOnResolve()
 {
     $requestContext = new RequestContext();
     $requestContext->setScheme('theSchema');
     $requestContext->setHost('thehost');
     $requestContext->setBaseUrl('\\');
     $resolver = new WebPathResolver($this->createFilesystemMock(), $requestContext, '/aWebRoot', 'aCachePrefix');
     $this->assertEquals('theschema://thehost/aCachePrefix/aFilter/aPath', $resolver->resolve('aPath', 'aFilter'));
 }
开发者ID:umanit,项目名称:LiipImagineBundle,代码行数:9,代码来源:WebPathResolverTest.php

示例4: route

 /**
  * Generate a URL to a route
  *
  * @param string	$route		Name of the route to travel
  * @param array	$params		String or array of additional url parameters
  * @param bool	$is_amp		Is url using & (true) or & (false)
  * @param string|bool		$session_id	Possibility to use a custom session id instead of the global one
  * @param bool|string		$reference_type The type of reference to be generated (one of the constants)
  * @return string The URL already passed through append_sid()
  */
 public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     $anchor = '';
     if (isset($params['#'])) {
         $anchor = '#' . $params['#'];
         unset($params['#']);
     }
     $context = new RequestContext();
     $context->fromRequest($this->symfony_request);
     if ($this->config['force_server_vars']) {
         $context->setHost($this->config['server_name']);
         $context->setScheme(substr($this->config['server_protocol'], 0, -3));
         $context->setHttpPort($this->config['server_port']);
         $context->setHttpsPort($this->config['server_port']);
         $context->setBaseUrl(rtrim($this->config['script_path'], '/'));
     }
     $script_name = $this->symfony_request->getScriptName();
     $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name);
     $base_url = $context->getBaseUrl();
     // Append page name if base URL does not contain it
     if (!empty($page_name) && strpos($base_url, '/' . $page_name) === false) {
         $base_url .= '/' . $page_name;
     }
     // If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it.
     $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url);
     // We need to update the base url to move to the directory of the app.php file if the current script is not app.php
     if ($page_name !== 'app.php' && !$this->config['force_server_vars']) {
         if (empty($this->config['enable_mod_rewrite'])) {
             $base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url);
         } else {
             $base_url .= preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), '$2', $this->phpbb_root_path);
         }
     }
     $base_url = $this->request->escape($this->filesystem->clean_path($base_url), true);
     $context->setBaseUrl($base_url);
     $this->router->setContext($context);
     $route_url = $this->router->generate($route, $params, $reference_type);
     if ($is_amp) {
         $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url);
     }
     if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite'])) {
         $route_url = 'app.' . $this->php_ext . '/' . $route_url;
     }
     return append_sid($route_url . $anchor, false, $is_amp, $session_id, true);
 }
开发者ID:phpbb,项目名称:phpbb-core,代码行数:55,代码来源:helper.php

示例5: testMatchWithRequestMatchersAndContext

 /**
  * Call match on ChainRouter that has RequestMatcher in the chain.
  *
  * @dataProvider provideBaseUrl
  */
 public function testMatchWithRequestMatchersAndContext($baseUrl)
 {
     $url = '//test';
     list($low) = $this->createRouterMocks();
     $high = $this->getMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RequestMatcher');
     $high->expects($this->once())->method('matchRequest')->with($this->callback(function (Request $r) use($url, $baseUrl) {
         return true === $r->isSecure() && 'foobar.com' === $r->getHost() && 4433 === $r->getPort() && $baseUrl === $r->getBaseUrl() && $url === $r->getPathInfo();
     }))->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException()));
     $low->expects($this->once())->method('match')->with($url)->will($this->returnValue(array('test')));
     $this->router->add($low, 10);
     $this->router->add($high, 20);
     $requestContext = new RequestContext();
     $requestContext->setScheme('https');
     $requestContext->setHost('foobar.com');
     $requestContext->setHttpsPort(4433);
     $requestContext->setBaseUrl($baseUrl);
     $this->router->setContext($requestContext);
     $result = $this->router->match($url);
     $this->assertEquals(array('test'), $result);
 }
开发者ID:frogriotcom,项目名称:Routing,代码行数:25,代码来源:ChainRouterTest.php

示例6: setUrlInContext

 /**
  * @param $url
  * @param RequestContext $context
  * @return array
  */
 private function setUrlInContext($url, RequestContext $context)
 {
     $parts = parse_url($url);
     if (false === (bool) $parts) {
         throw new \RuntimeException('Invalid Application URL configured. Unable to generate links');
     }
     if (isset($parts['schema'])) {
         $context->setScheme($parts['schema']);
     }
     if (isset($parts['host'])) {
         $context->setHost($parts['host']);
     }
     if (isset($parts['port'])) {
         $context->setHttpPort($parts['port']);
         $context->setHttpsPort($parts['port']);
     }
     if (isset($parts['path'])) {
         $context->setBaseUrl(rtrim($parts['path'], '/'));
     }
     if (isset($parts['query'])) {
         $context->setQueryString($parts['query']);
     }
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:28,代码来源:PortalURLExtension.php

示例7: getInstallToolUrl

 /**
  * Returns the install tool URL.
  *
  * @return string
  */
 private function getInstallToolUrl()
 {
     $routes = new RouteCollection();
     $routes->add('contao_install', new Route('/contao/install'));
     $context = new RequestContext();
     $context->fromRequest($this->request);
     $context->setBaseUrl('');
     return str_replace('/install.php/', '/', (new UrlGenerator($routes, $context))->generate('contao_install'));
 }
开发者ID:contao,项目名称:installation-bundle,代码行数:14,代码来源:InstallationKernel.php

示例8: testGenerateWithSiteAccess

 /**
  * @dataProvider providerGenerateWithSiteAccess
  *
  * @param string $urlGenerated The URL generated by the standard UrLGenerator
  * @param string $relevantUri The relevant URI part of the generated URL (without host and basepath)
  * @param string $expectedUrl The URL we're expecting to be finally generated, with siteaccess
  * @param string $saName The SiteAccess name
  * @param bool $isMatcherLexer True if the siteaccess matcher is URILexer
  * @param bool $absolute True if generated link needs to be absolute
  * @param string $routeName
  */
 public function testGenerateWithSiteAccess($urlGenerated, $relevantUri, $expectedUrl, $saName, $isMatcherLexer, $absolute, $routeName)
 {
     $routeName = $routeName ?: __METHOD__;
     $nonSiteAccessAwareRoutes = array('_dontwantsiteaccess');
     $generator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
     $generator->expects($this->once())->method('generate')->with($routeName)->will($this->returnValue($urlGenerated));
     /** @var DefaultRouter|\PHPUnit_Framework_MockObject_MockObject $router */
     $router = $this->generateRouter(array('getGenerator'));
     $router->expects($this->any())->method('getGenerator')->will($this->returnValue($generator));
     // If matcher is URILexer, we make it act as it's supposed to, prepending the siteaccess.
     if ($isMatcherLexer) {
         $matcher = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\URILexer');
         // Route is siteaccess aware, we're expecting analyseLink() to be called
         if (!in_array($routeName, $nonSiteAccessAwareRoutes)) {
             $matcher->expects($this->once())->method('analyseLink')->with($relevantUri)->will($this->returnValue("/{$saName}{$relevantUri}"));
         } else {
             $matcher->expects($this->never())->method('analyseLink');
         }
     } else {
         $matcher = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\Matcher');
     }
     $sa = new SiteAccess($saName, 'test', $matcher);
     $router->setSiteAccess($sa);
     $requestContext = new RequestContext();
     $urlComponents = parse_url($urlGenerated);
     if (isset($urlComponents['host'])) {
         $requestContext->setHost($urlComponents['host']);
         $requestContext->setScheme($urlComponents['scheme']);
         if (isset($urlComponents['port']) && $urlComponents['scheme'] === 'http') {
             $requestContext->setHttpPort($urlComponents['port']);
         } else {
             if (isset($urlComponents['port']) && $urlComponents['scheme'] === 'https') {
                 $requestContext->setHttpsPort($urlComponents['port']);
             }
         }
     }
     $requestContext->setBaseUrl(substr($urlComponents['path'], 0, strpos($urlComponents['path'], $relevantUri)));
     $router->setContext($requestContext);
     $router->setNonSiteAccessAwareRoutes($nonSiteAccessAwareRoutes);
     $this->assertSame($expectedUrl, $router->generate($routeName, array(), $absolute));
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:52,代码来源:DefaultRouterTest.php


注:本文中的Symfony\Component\Routing\RequestContext::setBaseUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。