symfony/symfony — pull request #4268 by snc (2012-05-12 17:36:06+00:00)
Title: [WIP] PhpMatcherDumper enhancement for "static" routes

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: not yet, tests will be updated if PR will be accepted
Fixes the following tickets: -
Todo: Don't generate code for "static" routes in the `generateMatchMethod` function
License of the code: MIT

This PR looks for "static" routes (routes without requirements and without variables) and adds them to an array in the `UrlMatcher` that is used for `isset` lookups inside the `match()` method.

Given the current `symfony-standard` routing the array would look like this:

``` php
static private $staticRoutes = array(
'/' => array ( '_controller' => 'Acme\\DemoBundle\\Controller\\WelcomeController::indexAction', '_route' => '_welcome',),
'/demo/secured/login' => array ( '_controller' => 'Acme\\DemoBundle\\Controller\\SecuredController::loginAction', '_route' => '_demo_login',),
'/demo/secured/login_check' => array ( '_controller' => 'Acme\\DemoBundle\\Controller\\SecuredController::securityCheckAction', '_route' => '_security_check',),
'/demo/secured/logout' => array ( '_controller' => 'Acme\\DemoBundle\\Controller\\SecuredController::logoutAction', '_route' => '_demo_logout',),
'/demo/secured/hello' => array ( 'name' => 'World', '_controller' => 'Acme\\DemoBundle\\Controller\\SecuredController::helloAction', '_route' => 'acme_demo_secured_hello',),
'/demo/' => array ( '_controller' => 'Acme\\DemoBundle\\Controller\\DemoController::indexAction', '_route' => '_demo',),
'/demo/contact' => array ( '_controller' => 'Acme\\DemoBundle\\Controller\\DemoController::contactAction', '_route' => '_demo_contact',),
'/_profiler/search' => array ( '_controller' => 'Symfony\\Bundle\\WebProfilerBundle\\Controller\\ProfilerController::searchAction', '_route' => '_profiler_search',),
'/_profiler/purge' => array ( '_controller' => 'Symfony\\Bundle\\WebProfilerBundle\\Controller\\ProfilerController::purgeAction', '_route' => '_profiler_purge',),
'/_profiler/import' => array ( '_controller' => 'Symfony\\Bundle\\WebProfilerBundle\\Controller\\ProfilerController::importAction', '_route' => '_profiler_import',),
'/_profiler/phpinfo' => array ( '_controller' => 'Symfony\\Bundle\\WebProfilerBundle\\Controller\\ProfilerController::phpinfoAction', '_route' => '_profiler_phpinfo',),
'/_profiler/' => array ( '_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::redirectAction', 'route' => '_profiler_search_results', 'token' => 'empty', 'ip' => '', 'url' => '', 'method' => '', 'limit' => '10', '_route' => '_profiler_redirect',),
'/_configurator/' => array ( '_controller' => 'Sensio\\Bundle\\DistributionBundle\\Controller\\ConfiguratorController::checkAction', '_route' => '_configurator_home',),
'/_configurator/final' => array ( '_controller' => 'Sensio\\Bundle\\DistributionBundle\\Controller\\ConfiguratorController::finalAction', '_route' => '_configurator_final',),
);
```

If the idea gets accepted I will enhance the code so that the "old" match code for the "static" routes will be removed. It should also be possible to add even more routes without variables which only have the `_method`requirement etc.