本文整理汇总了PHP中Symfony\Component\Routing\Route::setRequirements方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::setRequirements方法的具体用法?PHP Route::setRequirements怎么用?PHP Route::setRequirements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::setRequirements方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRequirements
public function testRequirements()
{
$route = new Route('/{foo}');
$route->setRequirements(array('foo' => '\\d+'));
$this->assertEquals(array('foo' => '\\d+'), $route->getRequirements(), '->setRequirements() sets the requirements');
$this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() returns a requirement');
$this->assertNull($route->getRequirement('bar'), '->getRequirement() returns null if a requirement is not defined');
$route->setRequirements(array('foo' => '^\\d+$'));
$this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the pattern');
$this->assertEquals($route, $route->setRequirements(array()), '->setRequirements() implements a fluent interface');
}
示例2: testRequirements
public function testRequirements()
{
$route = new Route('/{foo}');
$route->setRequirements(array('foo' => '\\d+'));
$this->assertEquals(array('foo' => '\\d+'), $route->getRequirements(), '->setRequirements() sets the requirements');
$this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() returns a requirement');
$this->assertNull($route->getRequirement('bar'), '->getRequirement() returns null if a requirement is not defined');
$route->setRequirements(array('foo' => '^\\d+$'));
$this->assertEquals('\\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the pattern');
$this->assertEquals($route, $route->setRequirements(array()), '->setRequirements() implements a fluent interface');
// test that an array requirement throws an exception
$this->setExpectedException('InvalidArgumentException');
$route->setRequirements(array('foo' => array('bar', 'baz')));
}
示例3: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$requirements = $current_route->getRequirements();
// Setting _method and _schema is deprecated since 2.7. Using
// setMethods() and setSchemes() are now the recommended ways.
unset($requirements['_method']);
unset($requirements['_schema']);
$route->setRequirements($requirements);
$route->setPath($current_route->getPath());
$route->setSchemes($current_route->getSchemes());
$route->setMethods($current_route->getMethods());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheContexts(['route']);
}
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例4: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>' && ($current_route = $this->routeMatch->getRouteObject())) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
}
}
示例5: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例6: generateRouteCollection
private function generateRouteCollection(ParameterBag $routes) : RouteCollection
{
$routeCollection = new RouteCollection();
foreach ($routes as $key => $route) {
$pattern = explode('::', $route->route, 2);
$sfRoute = new Route(isset($pattern[1]) ? $pattern[1] : $pattern[0]);
if (isset($route->require)) {
$sfRoute->setRequirements((array) $route->require);
}
if (isset($pattern[1])) {
$sfRoute->setMethods(strtoupper($pattern[0]));
}
$routeCollection->add($key, $sfRoute);
}
return $routeCollection;
}
示例7: 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;
}
示例8: indexRoute
/**
* @param array $options
*
* @return Route[]
*/
protected function indexRoute(array $options)
{
$routes = [];
if ($options['index_pagination'] || $options['index_sort']) {
$path = '/index';
$defaults = [];
$requirements = [];
$sortParams = $this->indexSortParams($options['index_sort_params']);
if ($options['index_pagination']) {
$path .= '/{page}';
$defaults['page'] = '1';
$requirements['page'] = '\\d+';
}
if ($options['index_sort']) {
$path .= '/{sort}/{direction}';
}
$route = new Route($path);
$route->setMethods(['GET']);
$route->setRequirements($requirements);
$route->setDefaults($defaults);
$route->setDefault('_controller', $options['controller'] . ':index');
$this->addSortDefaults($route, $sortParams);
$routes['index'] = $route;
$root = new Route('/');
$root->setMethods(['GET']);
$root->setDefault('_controller', 'FrameworkBundle:Redirect:redirect');
$root->setDefault('route', $this->routePrefix($options['route_prefix']) . '_index');
$root->setDefault('_locale', null);
$routes['root'] = $root;
} else {
$route = new Route('/');
$route->setMethods(['GET']);
$route->setDefault('_controller', $options['controller'] . ':index');
$routes['index'] = $route;
}
return $routes;
}
示例9: 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);
}
示例10: fixRequirements
/**
* Removes some deprecated requirements which cause depreciation notices.
*
* @param Route $route
*
* @todo Remove when Symfony 3.0 is used.
*/
private function fixRequirements(Route $route)
{
$requirements = $route->getRequirements();
if (isset($requirements['_method'])) {
unset($requirements['_method']);
}
if (isset($requirements['_scheme'])) {
unset($requirements['_scheme']);
}
$route->setRequirements($requirements);
}
示例11: __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 */
}