本文整理汇总了PHP中Symfony\Component\Routing\Route::setHost方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::setHost方法的具体用法?PHP Route::setHost怎么用?PHP Route::setHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::setHost方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHostPlaceholders
public function testHostPlaceholders()
{
$routes = new RouteCollection();
$route = new Route('foo');
$route->setHost('/before/%parameter.foo%/after/%%escaped%%');
$routes->add('foo', $route);
$sc = $this->getServiceContainer($routes);
$sc->setParameter('parameter.foo', 'foo');
$router = new Router($sc, 'foo');
$route = $router->getRouteCollection()->get('foo');
$this->assertEquals('/before/foo/after/%escaped%', $route->getHost());
}
示例2: testHostPlaceholders
public function testHostPlaceholders()
{
$routes = new RouteCollection();
$route = new Route('foo');
$route->setHost('/before/%parameter.foo%/after/%%unescaped%%');
$routes->add('foo', $route);
$sc = $this->getServiceContainer($routes);
$sc->expects($this->at(1))->method('hasParameter')->with('parameter.foo')->will($this->returnValue(true));
$sc->expects($this->at(2))->method('getParameter')->with('parameter.foo')->will($this->returnValue('foo'));
$router = new Router($sc, 'foo');
$route = $router->getRouteCollection()->get('foo');
$this->assertEquals('/before/foo/after/%unescaped%', $route->getHost());
}
示例3: load
public function load(RouteCollection $collection)
{
$i18nCollection = new RouteCollection();
foreach ($collection->getResources() as $resource) {
$i18nCollection->addResource($resource);
}
$this->patternGenerationStrategy->addResources($i18nCollection);
$existedHomepage = [];
foreach ($collection->all() as $name => $route) {
if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
$i18nCollection->add($name, $route);
continue;
}
$patters = $this->patternGenerationStrategy->generateI18nPatterns($name, $route);
foreach ($patters as $pattern => $hostLocales) {
// If this pattern is used for more than one locale, we need to keep the original route.
// We still add individual routes for each locale afterwards for faster generation.
foreach ($hostLocales as $host => $locales) {
if (count($locales) > 1) {
$catchMultipleRoute = clone $route;
$catchMultipleRoute->setPath($pattern);
$catchMultipleRoute->setHost($host);
$catchMultipleRoute->setRequirement('_locale', implode('|', $locales));
$catchMultipleRoute->setOption('original_name', $name)->setOption('locales', $locales);
$i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchMultipleRoute);
} elseif (count($locales) == 1) {
$catchRoute = clone $route;
$catchRoute->setPath($pattern);
$catchRoute->setHost($host);
$catchRoute->setDefault('_locale', $locales[0]);
$catchRoute->setRequirement('_locale', $locales[0]);
$catchRoute->setOption('original_name', $name)->setOption('locales', $locales);
$i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchRoute);
}
if ($pattern == '/') {
$existedHomepage[] = $host;
}
}
}
}
$offices = $this->entityManager->getRepository('OctavaMuiBundle:Office')->getRoutingOffices();
foreach ($offices as $locale => $office) {
if ($office->getIncludeLangInUrl() && !in_array($office->getHost(), $existedHomepage)) {
$redirectRoute = new Route('/', ['_controller' => 'FrameworkBundle:Redirect:urlRedirect', 'path' => '/' . $locale . '/', 'permanent' => true]);
$redirectRoute->setHost($office->getHost());
$i18nCollection->add($locale . I18nLoader::ROUTING_PREFIX . 'redirect_to_root', $redirectRoute);
}
}
return $i18nCollection;
}
示例4: createRoute
private function createRoute($path, array $globals, array $options = [])
{
foreach ($globals as $k => $v) {
if (is_array($v) && isset($options[$k])) {
$options[$k] = array_merge($v, $options[$k]);
} else {
$options[$k] = isset($options[$k]) ? $options[$k] : $v;
}
}
$route = new Route($path);
if (isset($options['host'])) {
$route->setHost($options['host']);
}
if (isset($options['defaults'])) {
$route->setDefaults($options['defaults']);
}
if (isset($options['requirements'])) {
$route->setRequirements($options['requirements']);
}
if (isset($options['methods'])) {
$route->setMethods($options['methods']);
}
return $route;
}
示例5: testHost
public function testHost()
{
$route = new Route('/');
$route->setHost('{locale}.example.net');
$this->assertEquals('{locale}.example.net', $route->getHost(), '->setHost() sets the host pattern');
}
示例6: testSerializedRepresentationKeepsWorking
/**
* Tests that the serialized representation of a route in one symfony version
* also works in later symfony versions, i.e. the unserialized route is in the
* same state as another, semantically equivalent, route.
*/
public function testSerializedRepresentationKeepsWorking()
{
$serialized = 'C:31:"Symfony\\Component\\Routing\\Route":934:{a:8:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\\Component\\Routing\\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:8:"compiled";C:39:"Symfony\\Component\\Routing\\CompiledRoute":569:{a:8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:30:"#^/prefix(?:/(?P<foo>\\d+))?$#s";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:39:"#^(?P<locale>[^\\.]++)\\.example\\.net$#si";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}}}';
$unserialized = unserialize($serialized);
$route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\\d+'));
$route->setHost('{locale}.example.net');
$route->compile();
$this->assertEquals($route, $unserialized);
$this->assertNotSame($route, $unserialized);
}
示例7: refreshEntity
/**
* Refresh the entity
*
* @ORM\PostLoad
*/
public function refreshEntity()
{
parent::setPath($this->path);
parent::setDefaults($this->defaults);
parent::setRequirements($this->requirements);
parent::setOptions($this->options);
parent::setHost($this->host);
parent::setMethods($this->methods);
parent::setSchemes($this->schemes);
}
示例8: route
/**
* Add an endpiont/application to the server
* @param string $path The URI the client will connect to
* @param ComponentInterface $controller Your application to server for the route. If not specified, assumed to be for a WebSocket
* @param array $allowedOrigins An array of hosts allowed to connect (same host by default), ['*'] for any
* @param string $httpHost Override the $httpHost variable provided in the __construct
* @return ComponentInterface|WsServer
*/
public function route($path, ComponentInterface $controller, array $allowedOrigins = array(), $httpHost = null)
{
if ($controller instanceof HttpServerInterface || $controller instanceof WsServer) {
$decorated = $controller;
} elseif ($controller instanceof WampServerInterface) {
$decorated = new WsServer(new WampServer($controller));
} elseif ($controller instanceof MessageComponentInterface) {
$decorated = new WsServer($controller);
} else {
$decorated = $controller;
}
if ($httpHost === null) {
$httpHost = $this->httpHost;
}
$allowedOrigins = array_values($allowedOrigins);
if (0 === count($allowedOrigins)) {
$allowedOrigins[] = $httpHost;
}
if ('*' !== $allowedOrigins[0]) {
$decorated = new OriginCheck($decorated, $allowedOrigins);
}
$route = null;
if ($path instanceof Route) {
$route = $path;
$route->setDefault('_controller', $decorated);
} else {
$route = new Route($path, array('_controller' => $decorated));
}
if ('*' !== $httpHost) {
$route->addRequirements(array('Origin' => $httpHost));
$route->setHost($httpHost);
}
$this->routes->add('rr-' . ++$this->_routeCounter, $route);
return $decorated;
}
示例9: __construct
public function __construct()
{
$this->request = Request::createFromGlobals();
$this->container = Container::getInstance();
/* Parse params file - Begin */
$params = $this->parseYamlFile(APP_DIR . DS . 'configs' . DS . 'params.yml');
$isDev = $params['environment'] === 'development';
if ($isDev) {
Debug::enable(E_STRICT);
}
date_default_timezone_set($params['timezone']);
/* Parse params file - End */
/* Parse routes file - Begin */
$routes = $this->parseYamlFile(APP_DIR . DS . 'configs' . DS . 'routes.yml');
$collection = new RouteCollection();
foreach ($routes as $name => $options) {
$parts = explode(':', $options['defaults']['_controller']);
$options['defaults'] = array('_controller' => "{$parts[0]}\\Controllers\\{$parts[1]}Controller::{$parts[2]}Action");
$route = new Route($options['path']);
$route->setDefaults($options['defaults']);
$route->setRequirements(isset($options['requirements']) ? $options['requirements'] : array());
$route->setOptions(isset($options['options']) ? $options['options'] : array());
$route->setHost(isset($options['host']) ? $options['host'] : '');
$route->setSchemes(isset($options['schemes']) ? $options['schemes'] : array());
$route->setMethods(isset($options['methods']) ? $options['methods'] : array());
$route->setCondition(isset($options['condition']) ? $options['condition'] : '');
$collection->add($name, $route);
}
$this->container->setParameter('routes', $collection);
/* Parse routes file - End */
/* Composer ClassLoader - Begin */
$composer_loader = new ClassLoader();
$composer_loader->addPsr4('Application\\Controllers\\', APP_DIR . DS . 'layers' . DS . 'controllers');
$composer_loader->addPsr4('Application\\Models\\', APP_DIR . DS . 'layers' . DS . 'models');
$composer_loader->register();
/* Composer ClassLoader - End */
/* Set error controller - Begin */
$namespace = $isDev ? 'Hideks\\Controller\\' : 'Application\\Controllers\\';
$this->container->setParameter('exception.controller', $namespace . 'ErrorController::exceptionAction');
/* Set error controller - End */
/* Assetic configuration setup - Begin */
$filter_manager = new FilterManager();
$filter_manager->set('css_min', new CssMinFilter());
$filter_manager->set('lessphp', new LessphpFilter());
$filter_manager->set('js_min', new JSMinFilter());
$asset_factory = new AssetFactory(APP_DIR . DS . 'assets' . DS);
$asset_factory->setDebug($isDev);
$asset_factory->setFilterManager($filter_manager);
$asset_factory->addWorker(new CacheBustingWorker());
$this->container->setParameter('assetic.factory', $asset_factory);
/* Assetic configuration setup - End */
/* Twig configuration setup - Begin */
$this->container->setParameter('twig.debug', $isDev);
$this->container->setParameter('twig.cache', $isDev ? false : APP_DIR . DS . 'cache' . DS . 'twig');
$twig_loader = $this->container->get('twig.loader');
$twig_loader->addPath(APP_DIR . DS . 'layers' . DS . 'views');
/* Twig configuration setup - End */
/* Active Record configuration setup - Begin */
$active_record = \ActiveRecord\Config::instance();
$active_record->set_model_directory(APP_DIR . DS . 'layers' . DS . 'models');
$active_record->set_connections($params['connections']);
$active_record->set_default_connection($params['environment']);
/* Active Record configuration setup - End */
}