本文整理汇总了PHP中Symfony\Component\Routing\RequestContext::setHttpPort方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::setHttpPort方法的具体用法?PHP RequestContext::setHttpPort怎么用?PHP RequestContext::setHttpPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RequestContext
的用法示例。
在下文中一共展示了RequestContext::setHttpPort方法的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: testNonStandHttpRedirect
public function testNonStandHttpRedirect()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array('_scheme' => 'http')));
$context = new RequestContext();
$context->setHttpPort(8000);
$context->setScheme('https');
$matcher = new UrlMatcher($coll, $context);
$result = $matcher->match('/foo');
$this->assertArrayHasKey('url', $result);
$this->assertSame($result['url'], 'http://localhost:8000/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: 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);
}
示例10: __construct
public function __construct($container, $config, array $values = array())
{
$this->container = $container;
$defaultConfig = ['config.path' => null, 'view.path' => null, 'http.cache.path' => null, 'view.cache.path' => null, 'view.compile.path' => null, 'routes.yml' => 'routes.yml', 'services.yml' => 'services.yml'];
$realConfig = array_merge($defaultConfig, $config);
$this->container['config'] = $realConfig;
$this->container['callback_resolver'] = function ($c) {
return new \Vicus\Component\CallbackResolver($c);
};
$this->container['controller_resolver'] = function ($c) {
return new HttpKernel\Controller\ControllerResolver();
};
$this->container['resolver'] = function ($c) {
return new \Vicus\Component\HttpKernel\Controller\ServiceControllerResolver($c['controller_resolver'], $c['callback_resolver']);
};
$this->container['routes'] = function ($c) {
return new RouteCollection();
};
$this->container['routes'] = $this->container->extend('routes', function (RouteCollection $routes, $c) {
$collection = $c['routing_yaml_file_loader']->load($c['config']['routes.yml']);
$routes->addCollection($collection);
return $routes;
});
$this->container['config_file_locator'] = function ($c) {
return new FileLocator($c['config']['config.path']);
};
$this->container['routing_yaml_file_loader'] = function ($c) {
$loader = new RoutingYamlFileLoader($c['config_file_locator']);
return $loader;
};
$this->container['container_builder'] = function ($c) {
return new ContainerBuilder($c);
};
$this->container['container_yaml_file_loader'] = function ($c) {
return new ContainerYamlFileLoader($c['container_builder'], $c['config_file_locator']);
};
$this->container['services'] = function ($c) {
return $c['container_yaml_file_loader']->load($c['config']['services.yml']);
};
$this->container['context'] = function ($c) {
$context = new Routing\RequestContext();
$context->setHttpPort($c['request.http_port']);
$context->setHttpsPort($c['request.https_port']);
return $context;
};
$this->container['matcher'] = function ($c) {
return new Routing\Matcher\UrlMatcher($c['routes'], $c['context']);
};
$this->container['event_dispatcher'] = function ($c) {
return new EventDispatcher();
};
$this->container['exception_handler'] = function ($c) {
return new ExceptionHandler($c['debug']);
};
$this->container['event_dispatcher_add_listeners'] = function ($c) {
$exceptionController = $c['exception_controller'] ? $c['exception_controller'] : '\\\\Vicus\\Controller\\ErrorController::exceptionAction';
$c['event_dispatcher']->addSubscriber(new HttpKernel\EventListener\RouterListener($c['matcher']));
$c['event_dispatcher']->addSubscriber(new \Vicus\Listener\StringResponseListener());
$c['event_dispatcher']->addSubscriber(new \Vicus\Listener\ContentLengthListener());
$c['event_dispatcher']->addSubscriber(new HttpKernel\EventListener\StreamedResponseListener());
$c['event_dispatcher']->addSubscriber(new HttpKernel\EventListener\RouterListener($c['matcher']));
$listener = new HttpKernel\EventListener\ExceptionListener($exceptionController);
$c['event_dispatcher']->addSubscriber($listener);
if (isset($c['exception_handler'])) {
$c['event_dispatcher']->addSubscriber($c['exception_handler']);
}
};
$this->container['kernel'] = function ($c) {
return new \Vicus\Kernel($c['event_dispatcher'], $c['resolver']);
};
$this->container->extends['kernel'] = function ($c) {
return new HttpCache($c['kernel'], new Store($c['config']['http.cache.path']));
};
$this->container['request_error'] = $this->container->protect(function () {
throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
});
//request is already used in bootstrap. Any silex documentations that askes for request replace with request_state (for now)
$this->container['request'] = $this->container['request_error'];
$this->container['request.http_port'] = 80;
$this->container['request.https_port'] = 443;
$this->container['debug'] = false;
$this->container['charset'] = 'UTF-8';
$this->container['locale'] = 'en';
//Build services list in container
$this->container['services'];
foreach ($values as $key => $value) {
$this->container[$key] = $value;
}
}
示例11: __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';
}
示例12: testComposeSchemaHttpAndCustomPortAndFileUrlOnResolve
public function testComposeSchemaHttpAndCustomPortAndFileUrlOnResolve()
{
$requestContext = new RequestContext();
$requestContext->setScheme('http');
$requestContext->setHost('thehost');
$requestContext->setHttpPort(88);
$resolver = new WebPathResolver($this->createFilesystemMock(), $requestContext, '/aWebRoot', 'aCachePrefix');
$this->assertEquals('http://thehost:88/aCachePrefix/aFilter/aPath', $resolver->resolve('aPath', 'aFilter'));
}
示例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: __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';
}
示例15: __construct
/**
* Constructor.
*/
public function __construct()
{
$app = $this;
$this['logger'] = null;
$this['autoloader'] = function () {
throw new \RuntimeException('You tried to access the autoloader service. The autoloader has been removed from Silex. It is recommended that you use Composer to manage your dependencies and handle your autoloading. See http://getcomposer.org for more information.');
};
$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) {
$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']));
$dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher));
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']));
$dispatcher->addSubscriber(new StringToResponseListener());
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['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';
}