本文整理汇总了PHP中Symfony\Component\Routing\Route::setCondition方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::setCondition方法的具体用法?PHP Route::setCondition怎么用?PHP Route::setCondition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::setCondition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCondition
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testCondition()
{
$coll = new RouteCollection();
$route = new Route('/foo');
$route->setCondition('context.getMethod() == "POST"');
$coll->add('foo', $route);
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher->match('/foo');
}
示例2: testCondition
public function testCondition()
{
$route = new Route('/');
$this->assertEquals(null, $route->getCondition());
$route->setCondition('context.getMethod() == "GET"');
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
}
示例3: getRouteCollections
//.........这里部分代码省略.........
$collection1->add('bar1', new Route('/{bar}'));
$collection1->addPrefix('/b\'b');
$collection2 = new RouteCollection();
$collection2->addCollection($collection1);
$collection2->add('overridden', new Route('/{var}', array(), array('var' => '.*')));
$collection1 = new RouteCollection();
$collection1->add('foo2', new Route('/{foo1}'));
$collection1->add('bar2', new Route('/{bar1}'));
$collection1->addPrefix('/b\'b');
$collection2->addCollection($collection1);
$collection2->addPrefix('/a');
$collection->addCollection($collection2);
// overridden through addCollection() and multiple sub-collections with no own prefix
$collection1 = new RouteCollection();
$collection1->add('overridden2', new Route('/old'));
$collection1->add('helloWorld', new Route('/hello/{who}', array('who' => 'World!')));
$collection2 = new RouteCollection();
$collection3 = new RouteCollection();
$collection3->add('overridden2', new Route('/new'));
$collection3->add('hey', new Route('/hey/'));
$collection2->addCollection($collection3);
$collection1->addCollection($collection2);
$collection1->addPrefix('/multi');
$collection->addCollection($collection1);
// "dynamic" prefix
$collection1 = new RouteCollection();
$collection1->add('foo3', new Route('/{foo}'));
$collection1->add('bar3', new Route('/{bar}'));
$collection1->addPrefix('/b');
$collection1->addPrefix('{_locale}');
$collection->addCollection($collection1);
// route between collections
$collection->add('ababa', new Route('/ababa'));
// collection with static prefix but only one route
$collection1 = new RouteCollection();
$collection1->add('foo4', new Route('/{foo}'));
$collection1->addPrefix('/aba');
$collection->addCollection($collection1);
// prefix and host
$collection1 = new RouteCollection();
$route1 = new Route('/route1', array(), array(), array(), 'a.example.com');
$collection1->add('route1', $route1);
$collection2 = new RouteCollection();
$route2 = new Route('/c2/route2', array(), array(), array(), 'a.example.com');
$collection1->add('route2', $route2);
$route3 = new Route('/c2/route3', array(), array(), array(), 'b.example.com');
$collection1->add('route3', $route3);
$route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
$collection1->add('route4', $route4);
$route5 = new Route('/route5', array(), array(), array(), 'c.example.com');
$collection1->add('route5', $route5);
$route6 = new Route('/route6', array(), array(), array(), null);
$collection1->add('route6', $route6);
$collection->addCollection($collection1);
// host and variables
$collection1 = new RouteCollection();
$route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com');
$collection1->add('route11', $route11);
$route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com');
$collection1->add('route12', $route12);
$route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com');
$collection1->add('route13', $route13);
$route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com');
$collection1->add('route14', $route14);
$route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com');
$collection1->add('route15', $route15);
$route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null);
$collection1->add('route16', $route16);
$route17 = new Route('/route17', array(), array(), array(), null);
$collection1->add('route17', $route17);
$collection->addCollection($collection1);
// multiple sub-collections with a single route and a prefix each
$collection1 = new RouteCollection();
$collection1->add('a', new Route('/a...'));
$collection2 = new RouteCollection();
$collection2->add('b', new Route('/{var}'));
$collection3 = new RouteCollection();
$collection3->add('c', new Route('/{var}'));
$collection3->addPrefix('/c');
$collection2->addCollection($collection3);
$collection2->addPrefix('/b');
$collection1->addCollection($collection2);
$collection1->addPrefix('/a');
$collection->addCollection($collection1);
/* test case 2 */
$redirectCollection = clone $collection;
// force HTTPS redirection
$redirectCollection->add('secure', new Route('/secure', array(), array('_scheme' => 'https')));
// force HTTP redirection
$redirectCollection->add('nonsecure', new Route('/nonsecure', array(), array('_scheme' => 'http')));
/* test case 3 */
$rootprefixCollection = new RouteCollection();
$rootprefixCollection->add('static', new Route('/test'));
$rootprefixCollection->add('dynamic', new Route('/{var}'));
$rootprefixCollection->addPrefix('rootprefix');
$route = new Route('/with-condition');
$route->setCondition('context.getMethod() == "GET"');
$rootprefixCollection->add('with-condition', $route);
return array(array($collection, 'url_matcher1.php', array()), array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\\Component\\Routing\\Tests\\Fixtures\\RedirectableUrlMatcher')), array($rootprefixCollection, 'url_matcher3.php', array()));
}
示例4: __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 */
}