fixed CS (missing or misplaced license blocks)
performance improvement in PhpMatcherDumper
merged branch Tobion/PhpMatcherDumper-Improvement (PR #3763)

Commits
-------

56c1e31 performance improvement in PhpMatcherDumper

Discussion
----------

performance improvement in PhpMatcherDumper

Tests pass: yes

The code generation uses a string internally instead of an array. The array wasn't used for random access anyway.
I also removed 4 unneeded iterations this way (when imploding, when merging and twice when applying the extra indention). A `preg_replace` could also be saved under certain circumstances by moving it.
And there was a small code errror in line 139.
[Routing] Added the possibility to define options for imported resources

Closes #2772
[Routing] improved exception message when giving an invalid route name.
[Routing] fixed exception message.
merged 2.0
[Routing] Request methods always return a raw path, fix the matcher to decode only once

sq
[Routing] Fixes to handle spaces in route pattern

- The route compiler does not add extra space or line-feed,
- The generated regex does not use the 'x' modified any more,
- The PHP and apache matchers do not need to strip any chars (vs space and line feed before),
- The space characters are escaped according to the apache format
merged branch vicb/routing_dumpers (PR #3858)

Commits
-------

77185e0 [Routing] Allow spaces in the script name for the apache dumper
6465a69 [Routing] Fixes to handle spaces in route pattern

Discussion
----------

[Routing] Handling of space characters in the dumpers

The compiler was using the 'x' modifier in order to ignore extra spaces and line feeds but the code was flawed:

- it was actually ignoring all the spaces, not only the extra ones added by the compiler,
- all the spaces were stripped in the php and apache matchers.

The proposed fix:

- do not use the 'x' modifier any more (and then do no add extra spaces / line feeds),
- do not strip the spaces in the matchers,
- escapes the spaces (both in regexs and script name) for the apache matcher.

It also include [a small optimization](https://github.com/vicb/symfony/pull/new#L9L89) when the only token of a route is an optional variable token - the idea is to make the regex easier to read.

---------------------------------------------------------------------------

by vicb at 2012-04-10T13:59:45Z

@Baachi fixed now. Thanks.

---------------------------------------------------------------------------

by Tobion at 2012-04-10T16:01:31Z

+1, I saw no reason for pretty printing the regex in the first place (just for debugging I guess).
@vicb since you want to make the regex easier to read, I propose the remove the `P` from the variable regex `?P<bar>`, which is not needed anymore in PHP 5.3 (and we only support PHP 5.3+ anyway).

---------------------------------------------------------------------------

by vicb at 2012-04-10T16:08:36Z

@Tobion could you make a PR to this branch for the named parameters ?

---------------------------------------------------------------------------

by Tobion at 2012-04-10T16:12:34Z

I can include it in #3754 because I'm about the add 2 more fixes to it anyway.
But when I proposed to apply these fixes to 2.0 Fabien rejected it. So not sure what branch you want me to apply this.

---------------------------------------------------------------------------

by vicb at 2012-04-10T16:25:38Z

May be the best is to put it on hold while I am reviewing your PRs. There are already enough changes, we'll make an other PR after all have been sorted out.

What's the difference between 3754 and 3810 ? (3810 + 3763 = 3754 ?)

---------------------------------------------------------------------------

by Tobion at 2012-04-10T16:39:32Z

Lol you forget to link the PR numbers. At first sight I thought it's some sort of mathematical riddle. Haha
#3810 is for 2.0 =  #3763 (already merged) + #3754 for master

---------------------------------------------------------------------------

by vicb at 2012-04-10T16:52:18Z

I didn't link on purpose... the question is if '=' means strictly or loosely equal (any diffs - beside master vs 2.0) ?

---------------------------------------------------------------------------

by Tobion at 2012-04-10T17:06:04Z

It just applies my changes to 2.0. Nothing more. So master still differs from 2.0 by the addional features that were already implemented (e.g. `RouteCollection->addCollection` with optional requirements and options). But since my changes are bug fixes (except the performance improvement in #3763 but that doesn't break anything and makes 2.0 easier to maintain) I thought they should go into 2.0 as well.

---------------------------------------------------------------------------

by vicb at 2012-04-10T17:14:27Z

@Tobion only bug fixes mean "only bug fixes". You should re-open a PR for 2.0 with "only bug fixes", you might want to wait for me to review 3754.

---------------------------------------------------------------------------

by Tobion at 2012-04-10T17:21:00Z

Without #3763 it's much harder to apply the bug fixes. And now that I found 2 more bugs which requiresome rewriting of the PhpMatcherDumper, I don't want to apply all the commits by hand again for 2.0...
merged 2.0
[Routing] Implement bug fixes and enhancements
[Routing] simplified regex with named variables
[Routing] remove duplicated cache of compiled routes
[Routing] small optimization of PhpGeneratorDumper
[Routing] improved generated class by PhpGeneratorDumper
merged branch Tobion/generator-dumper (PR #3894)

Commits
-------

382b083 [Routing] improved generated class by PhpGeneratorDumper
27a05f4 [Routing] small optimization of PhpGeneratorDumper

Discussion
----------

[Routing] improved PhpGeneratorDumper

Test pass: yes
BC break: no

The first commit only replaces arrays with strings and makes some cosmetic changes, so that it's more readable. This makes the `PhpGeneratorDumper` consistent in style with `PhpMatcherDumper` that I fixed recently and should slightly improve performance of the generation of the class.

The second commit changes the output of the `PhpGeneratorDumper->dump` and tries to optimize the resulting class that is used to generate URLs. It's best explained with an example.

Before my changes:

```php
class ProjectUrlGenerator extends Symfony\Component\Routing\Generator\UrlGenerator
{
    static private $declaredRouteNames = array(
       'Test' => true,
       'Test2' => true,
    );

    /**
     * Constructor.
     */
    public function __construct(RequestContext $context)
    {
        $this->context = $context;
    }

    public function generate($name, $parameters = array(), $absolute = false)
    {
        if (!isset(self::$declaredRouteNames[$name])) {
            throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
        }

        $escapedName = str_replace('.', '__', $name);

        list($variables, $defaults, $requirements, $tokens) = $this->{'get'.$escapedName.'RouteInfo'}();

        return $this->doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute);
    }

    private function getTestRouteInfo()
    {
        return array(array (  0 => 'foo',), array (), array (), array (  0 =>   array (    0 => 'variable',    1 => '/',    2 => '[^/]+?',    3 => 'foo',  ),  1 =>   array (    0 => 'text',    1 => '/testing',  ),));
    }

    private function getTest2RouteInfo()
    {
        return array(array (), array (), array (), array (  0 =>   array (    0 => 'text',    1 => '/testing2',  ),));
    }
}
```

After my changes in second commit:

```php
class ProjectUrlGenerator extends Symfony\Component\Routing\Generator\UrlGenerator
{
    static private $declaredRoutes = array(
        'Test' => array (  0 =>   array (    0 => 'foo',  ),  1 =>   array (  ),  2 =>   array (  ),  3 =>   array (    0 =>     array (      0 => 'variable',      1 => '/',      2 => '[^/]+?',      3 => 'foo',    ),    1 =>     array (      0 => 'text',      1 => '/testing',    ),  ),),
        'Test2' => array (  0 =>   array (  ),  1 =>   array (  ),  2 =>   array (  ),  3 =>   array (    0 =>     array (      0 => 'text',      1 => '/testing2',    ),  ),),
    );

    /**
     * Constructor.
     */
    public function __construct(RequestContext $context)
    {
        $this->context = $context;
    }

    public function generate($name, $parameters = array(), $absolute = false)
    {
        if (!isset(self::$declaredRoutes[$name])) {
            throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
        }

        list($variables, $defaults, $requirements, $tokens) = self::$declaredRoutes[$name];

        return $this->doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute);
    }
}
```

As you can see, there is no need to escape the route name and invoke a special method anymore. Instead the route properties are included in the static route array directly, that existed anyway. Is also easier to read as defined routes and their properties are in the same place.
[Routing] small refactoring + language fixes
merged branch Tobion/route-compiler (PR #3891)

Commits
-------

cb47b03 [Routing] small refactoring + language fixes

Discussion
----------

[Routing] small refactoring + language fixes

tests pass, no bc break

---------------------------------------------------------------------------

by vicb at 2012-04-12T06:42:19Z

@Tobion could you squash your commits ?

---------------------------------------------------------------------------

by Tobion at 2012-04-12T19:25:03Z

done
fixed CS