本文整理汇总了PHP中Symfony\Component\Routing\RequestContext::setHttpsPort方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::setHttpsPort方法的具体用法?PHP RequestContext::setHttpsPort怎么用?PHP RequestContext::setHttpsPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RequestContext
的用法示例。
在下文中一共展示了RequestContext::setHttpsPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
/**
* Holds information about the current request
*
* @return RequestContext
*/
$app['request_context'] = function () use($app) {
$context = new RequestContext();
// set default http & https ports if not set
$context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
$context->setHttpsPort(isset($app['request.https_port']) ? $app['request.https_port'] : 443);
return $context;
};
/**
* Matches URL based on a set of routes.
*
* @return UrlMatcher
*/
$app['matcher'] = function () use($app) {
return new UrlMatcher($app['router'], $app['request_context']);
};
/**
* Router
*/
$options = array('cache_dir' => true === $app['use_cache'] ? __DIR__ . '/' . self::CACHE_DIRECTORY : null, 'debug' => true);
$app['router'] = function () use($app, $options) {
$router = new Router($app['config.loader'], sprintf(self::CONFIG_ROUTES_FILE, $app['env']), $options);
return $router->getRouteCollection();
};
}
示例2: testPort
/**
* @dataProvider getPortData
*/
public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort)
{
$listener = new RouterListener($this->router, $defaultHttpPort, $defaultHttpsPort);
$expectedContext = new RequestContext();
$expectedContext->setHttpPort($expectedHttpPort);
$expectedContext->setHttpsPort($expectedHttpsPort);
$expectedContext->setScheme(0 === strpos($uri, 'https') ? 'https' : 'http');
$this->router->expects($this->once())->method('setContext')->with($expectedContext);
$event = $this->createGetResponseEventForUri($uri);
$listener->onEarlyCoreRequest($event);
}
示例3: testNonStandHttpsRedirect
public function testNonStandHttpsRedirect()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array('_scheme' => 'https')));
$context = new RequestContext();
$context->setHttpsPort(9000);
$context->setScheme('http');
$matcher = new UrlMatcher($coll, $context);
$result = $matcher->match('/foo');
$this->assertArrayHasKey('url', $result);
$this->assertSame($result['url'], 'https://localhost:9000/foo');
}
示例4: testPort
/**
* @dataProvider getPortData
*/
public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort)
{
$urlMatcher = $this->getMockBuilder('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface')->disableOriginalConstructor()->getMock();
$context = new RequestContext();
$context->setHttpPort($defaultHttpPort);
$context->setHttpsPort($defaultHttpsPort);
$urlMatcher->expects($this->any())->method('getContext')->will($this->returnValue($context));
$routerListener = new RouterListener($urlMatcher, null, null, $this->requestStack);
$request = $this->createRequestForUri($uri);
$routerListener->match($request);
$this->assertEquals($expectedHttpPort, $context->getHttpPort());
$this->assertEquals($expectedHttpsPort, $context->getHttpsPort());
$this->assertEquals(0 === strpos($uri, 'https') ? 'https' : 'http', $context->getScheme());
}
示例5: initRouting
protected function initRouting()
{
$this['routes-collection'] = function () {
return new RouteCollection();
};
$this['request-context'] = function ($container) {
$context = new RequestContext();
$context->setHttpPort($container['http_port']);
$context->setHttpsPort($container['https_port']);
return $context;
};
$this['url-matcher'] = function ($container) {
return new UrlMatcher($container['routes-collection'], $container['request-context']);
};
$this['url-generator'] = function ($container) {
return new UrlGenerator($container['routes-collection'], $container['request-context'], $container['logger.logger']);
};
$this['resolver'] = function ($container) {
return new ControllerResolver($container, $container['logger.logger']);
};
}
示例6: testFromRequest
public function testFromRequest()
{
$request = Request::create('https://test.com:444/foo?bar=baz');
$requestContext = new RequestContext();
$requestContext->setHttpPort(123);
$requestContext->fromRequest($request);
$this->assertEquals('', $requestContext->getBaseUrl());
$this->assertEquals('GET', $requestContext->getMethod());
$this->assertEquals('test.com', $requestContext->getHost());
$this->assertEquals('https', $requestContext->getScheme());
$this->assertEquals('/foo', $requestContext->getPathInfo());
$this->assertEquals('bar=baz', $requestContext->getQueryString());
$this->assertSame(123, $requestContext->getHttpPort());
$this->assertSame(444, $requestContext->getHttpsPort());
$request = Request::create('http://test.com:8080/foo?bar=baz');
$requestContext = new RequestContext();
$requestContext->setHttpsPort(567);
$requestContext->fromRequest($request);
$this->assertSame(8080, $requestContext->getHttpPort());
$this->assertSame(567, $requestContext->getHttpsPort());
}
示例7: register
public function register(Container $app)
{
$app['url_generator'] = function ($app) {
return new UrlGenerator($app['routes'], $app['request_context']);
};
$app['request_matcher'] = function ($app) {
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
};
$app['request_context'] = function ($app) {
$context = new RequestContext();
$context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
$context->setHttpsPort(isset($app['request.https_port']) ? $app['request.https_port'] : 443);
return $context;
};
$app['routing.listener'] = function ($app) {
$urlMatcher = new LazyRequestMatcher(function () use($app) {
return $app['request_matcher'];
});
return new RouterListener($urlMatcher, $app['request_context'], $app['logger'], $app['request_stack']);
};
}
示例8: register
public function register(Container $app)
{
$app['route_class'] = 'Silex\\Route';
$app['route_factory'] = $app->factory(function ($app) {
return new $app['route_class']();
});
$app['routes_factory'] = $app->factory(function () {
return new RouteCollection();
});
$app['routes'] = function ($app) {
return $app['routes_factory'];
};
$app['url_generator'] = function ($app) {
return new UrlGenerator($app['routes'], $app['request_context']);
};
$app['request_matcher'] = function ($app) {
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
};
$app['request_context'] = function ($app) {
$context = new RequestContext();
$context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
$context->setHttpsPort(isset($app['request.https_port']) ? $app['request.https_port'] : 443);
return $context;
};
$app['controllers'] = function ($app) {
return $app['controllers_factory'];
};
$app['controllers_factory'] = $app->factory(function ($app) {
return new ControllerCollection($app['route_factory'], $app['routes_factory']);
});
$app['routing.listener'] = function ($app) {
$urlMatcher = new LazyRequestMatcher(function () use($app) {
return $app['request_matcher'];
});
if (Kernel::VERSION_ID >= 20800) {
return new RouterListener($urlMatcher, $app['request_stack'], $app['request_context'], $app['logger']);
}
return new RouterListener($urlMatcher, $app['request_context'], $app['logger'], $app['request_stack']);
};
}
示例9: __construct
/**
* Instantiate a new Application.
*
* Objects and parameters can be passed as argument to the constructor.
*
* @param array $values The parameters or objects.
*/
public function __construct(array $values = array())
{
parent::__construct();
$app = $this;
$this['logger'] = null;
$this['routes'] = $this->share(function () {
return new RouteCollection();
});
$this['controllers'] = $this->share(function () use($app) {
return $app['controllers_factory'];
});
$this['controllers_factory'] = function () use($app) {
return new ControllerCollection($app['route_factory']);
};
$this['route_class'] = 'Silex\\Route';
$this['route_factory'] = function () use($app) {
return new $app['route_class']();
};
$this['exception_handler'] = $this->share(function () use($app) {
return new ExceptionHandler($app['debug']);
});
$this['dispatcher_class'] = 'Symfony\\Component\\EventDispatcher\\EventDispatcher';
$this['dispatcher'] = $this->share(function () use($app) {
/*
* @var EventDispatcherInterface
*/
$dispatcher = new $app['dispatcher_class']();
$urlMatcher = new LazyUrlMatcher(function () use($app) {
return $app['url_matcher'];
});
$dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['request_context'], $app['logger'], $app['request_stack']));
$dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher, $app['request_stack']));
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
$dispatcher->addSubscriber(new ResponseListener($app['charset']));
$dispatcher->addSubscriber(new MiddlewareListener($app));
$dispatcher->addSubscriber(new ConverterListener($app['routes'], $app['callback_resolver']));
$dispatcher->addSubscriber(new StringToResponseListener());
return $dispatcher;
});
$this['callback_resolver'] = $this->share(function () use($app) {
return new CallbackResolver($app);
});
$this['resolver'] = $this->share(function () use($app) {
return new ControllerResolver($app, $app['logger']);
});
$this['kernel'] = $this->share(function () use($app) {
return new HttpKernel($app['dispatcher'], $app['resolver'], $app['request_stack']);
});
$this['request_stack'] = $this->share(function () use($app) {
if (class_exists('Symfony\\Component\\HttpFoundation\\RequestStack')) {
return new RequestStack();
}
});
$this['request_context'] = $this->share(function () use($app) {
$context = new RequestContext();
$context->setHttpPort($app['request.http_port']);
$context->setHttpsPort($app['request.https_port']);
return $context;
});
$this['url_matcher'] = $this->share(function () use($app) {
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
});
$this['request_error'] = $this->protect(function () {
throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
});
$this['request'] = $this['request_error'];
$this['request.http_port'] = 80;
$this['request.https_port'] = 443;
$this['debug'] = false;
$this['charset'] = 'UTF-8';
$this['locale'] = 'en';
foreach ($values as $key => $value) {
$this[$key] = $value;
}
}
示例10: __construct
/**
* Constructor.
*/
public function __construct()
{
$app = $this;
$this['autoloader'] = $this->share(function () {
$loader = new UniversalClassLoader();
$loader->register();
return $loader;
});
$this['routes'] = $this->share(function () {
return new RouteCollection();
});
$this['controllers'] = $this->share(function () use($app) {
return new ControllerCollection();
});
$this['exception_handler'] = $this->share(function () {
return new ExceptionHandler();
});
$this['dispatcher'] = $this->share(function () use($app) {
$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber($app);
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
$dispatcher->addSubscriber(new ResponseListener($app['charset']));
$dispatcher->addSubscriber(new RouterListener($app['url_matcher']));
return $dispatcher;
});
$this['resolver'] = $this->share(function () use($app) {
return new ControllerResolver($app);
});
$this['kernel'] = $this->share(function () use($app) {
return new HttpKernel($app['dispatcher'], $app['resolver']);
});
$this['request_context'] = $this->share(function () use($app) {
$context = new RequestContext();
$context->setHttpPort($app['request.http_port']);
$context->setHttpsPort($app['request.https_port']);
return $context;
});
$this['url_matcher'] = $this->share(function () use($app) {
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
});
$this['request.http_port'] = 80;
$this['request.https_port'] = 443;
$this['debug'] = false;
$this['charset'] = 'UTF-8';
}
示例11: 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);
}
示例12: 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);
}
示例13: addHostToContext
/**
* Sets the context from the domain.
*
* @param RequestContext $context
* @param array $parameters
* @param string $referenceType
*/
private function addHostToContext(RequestContext $context, array $parameters, &$referenceType)
{
list($host, $port) = $this->getHostAndPort($parameters['_domain']);
if ($context->getHost() === $host) {
return;
}
$context->setHost($host);
$referenceType = UrlGeneratorInterface::ABSOLUTE_URL;
if (!$port) {
return;
}
if (isset($parameters['_ssl']) && true === $parameters['_ssl']) {
$context->setHttpsPort($port);
} else {
$context->setHttpPort($port);
}
}
示例14: 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));
}
示例15: __construct
/**
* Constructor.
*/
public function __construct()
{
$app = $this;
$this['logger'] = null;
$this['routes'] = $this->share(function () {
return new RouteCollection();
});
$this['controllers'] = $this->share(function () use($app) {
return new ControllerCollection();
});
$this['exception_handler'] = $this->share(function () {
return new ExceptionHandler();
});
$this['dispatcher'] = $this->share(function () use($app) {
$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber($app);
$urlMatcher = new LazyUrlMatcher(function () use($app) {
return $app['url_matcher'];
});
$dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['logger']));
return $dispatcher;
});
$this['resolver'] = $this->share(function () use($app) {
return new ControllerResolver($app, $app['logger']);
});
$this['kernel'] = $this->share(function () use($app) {
return new HttpKernel($app['dispatcher'], $app['resolver']);
});
$this['request_context'] = $this->share(function () use($app) {
$context = new RequestContext();
$context->setHttpPort($app['request.http_port']);
$context->setHttpsPort($app['request.https_port']);
return $context;
});
$this['url_matcher'] = $this->share(function () use($app) {
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
});
$this['route_middlewares_trigger'] = $this->protect(function (KernelEvent $event) use($app) {
$request = $event->getRequest();
$routeName = $request->attributes->get('_route');
if (!($route = $app['routes']->get($routeName))) {
return;
}
foreach ((array) $route->getOption('_middlewares') as $callback) {
$ret = call_user_func($callback, $request);
if ($ret instanceof Response) {
$event->setResponse($ret);
return;
} elseif (null !== $ret) {
throw new \RuntimeException(sprintf('Middleware for route "%s" returned an invalid response value. Must return null or an instance of Response.', $routeName));
}
}
});
$this['request.default_locale'] = 'en';
$this['request_error'] = $this->protect(function () {
throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
});
$this['request'] = $this['request_error'];
$this['request.http_port'] = 80;
$this['request.https_port'] = 443;
$this['debug'] = false;
$this['charset'] = 'UTF-8';
}