From 53aaf76ad0cb357238248101c429c93a95657c4c Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 22 May 2012 02:28:43 +0200 Subject: [PATCH 1/3] [Routing] removed unused property of Router --- .../Bundle/FrameworkBundle/Routing/Router.php | 4 +--- src/Symfony/Component/Routing/Router.php | 13 +++++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php index 230a760f29..10133346e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php @@ -33,15 +33,13 @@ class Router extends BaseRouter implements WarmableInterface * @param mixed $resource The main resource to load * @param array $options An array of options * @param RequestContext $context The context - * @param array $defaults The default values */ - public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, array $defaults = array()) + public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null) { $this->container = $container; $this->resource = $resource; $this->context = null === $context ? new RequestContext() : $context; - $this->defaults = $defaults; $this->setOptions($options); } diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 3497029039..bf4d61fc5b 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -24,7 +24,6 @@ class Router implements RouterInterface { protected $matcher; protected $generator; - protected $defaults; protected $context; protected $loader; protected $collection; @@ -38,14 +37,12 @@ class Router implements RouterInterface * @param mixed $resource The main resource to load * @param array $options An array of options * @param RequestContext $context The context - * @param array $defaults The default values */ - public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, array $defaults = array()) + public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null) { $this->loader = $loader; $this->resource = $resource; $this->context = null === $context ? new RequestContext() : $context; - $this->defaults = $defaults; $this->setOptions($options); } @@ -195,7 +192,7 @@ class Router implements RouterInterface } if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) { - return $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context, $this->defaults); + return $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context); } $class = $this->options['matcher_cache_class']; @@ -213,7 +210,7 @@ class Router implements RouterInterface require_once $cache; - return $this->matcher = new $class($this->context, $this->defaults); + return $this->matcher = new $class($this->context); } /** @@ -228,7 +225,7 @@ class Router implements RouterInterface } if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) { - return $this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context, $this->defaults); + return $this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context); } $class = $this->options['generator_cache_class']; @@ -246,6 +243,6 @@ class Router implements RouterInterface require_once $cache; - return $this->generator = new $class($this->context, $this->defaults); + return $this->generator = new $class($this->context); } } From d81fdfe823c83afdd8e0ff802c6e108587d3e72b Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 22 May 2012 02:35:07 +0200 Subject: [PATCH 2/3] [Routing] fixed namespace of test classes --- .../Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php index 7a3dabe4d0..e5a14a509d 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Tests\Generator\Dumper\PhpGeneratorDumper; +namespace Symfony\Component\Routing\Tests\Generator\Dumper; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; From bc7043f106f9498640d7dd400606572867dc9c22 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 22 May 2012 03:13:14 +0200 Subject: [PATCH 3/3] [Routing] removed unused constructor arguments in test classes --- .../Dumper/PhpGeneratorDumperTest.php | 2 +- .../Tests/Matcher/ApacheUrlMatcherTest.php | 4 +-- .../Matcher/Dumper/PhpMatcherDumperTest.php | 4 +-- .../Routing/Tests/Matcher/UrlMatcherTest.php | 30 +++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php index e5a14a509d..6a86736abb 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php @@ -38,7 +38,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase parent::setUp(); $this->routeCollection = new RouteCollection(); - $this->generatorDumper = new PhpGeneratorDumper($this->routeCollection, new RequestContext()); + $this->generatorDumper = new PhpGeneratorDumper($this->routeCollection); $this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.php'; @unlink($this->testTmpFilepath); } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php index 9cae8b8a26..e68b61804c 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php @@ -22,8 +22,8 @@ class ApacheUrlMatcherTest extends \PHPUnit_Framework_TestCase */ public function testMatch($name, $pathinfo, $server, $expect) { - $collection = new RouteCollection; - $context = new RequestContext; + $collection = new RouteCollection(); + $context = new RequestContext(); $matcher = new ApacheUrlMatcher($collection, $context); $_SERVER = $server; diff --git a/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php b/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php index 0aea0396b6..3677c7e324 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php @@ -29,7 +29,7 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase array(), array('_scheme' => 'https') )); - $dumper = new PhpMatcherDumper($collection, new RequestContext()); + $dumper = new PhpMatcherDumper($collection); $dumper->dump(); } @@ -40,7 +40,7 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase { $basePath = __DIR__.'/../../Fixtures/dumper/'; - $dumper = new PhpMatcherDumper($collection, new RequestContext()); + $dumper = new PhpMatcherDumper($collection); $this->assertStringEqualsFile($basePath.$fixture, $dumper->dump($options), '->dump() correctly dumps routes as optimized PHP code.'); } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php index 3e9f49d071..f069239129 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php @@ -74,7 +74,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase // test the patterns are matched and parameters are returned $collection = new RouteCollection(); $collection->add('foo', new Route('/foo/{bar}')); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); try { $matcher->match('/no-match'); $this->fail(); @@ -84,45 +84,45 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase // test that defaults are merged $collection = new RouteCollection(); $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'))); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'def' => 'test'), $matcher->match('/foo/baz')); // test that route "method" is ignored if no method is given in the context $collection = new RouteCollection(); $collection->add('foo', new Route('/foo', array(), array('_method' => 'GET|head'))); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertInternalType('array', $matcher->match('/foo')); // route does not match with POST method context - $matcher = new UrlMatcher($collection, new RequestContext('', 'post'), array()); + $matcher = new UrlMatcher($collection, new RequestContext('', 'post')); try { $matcher->match('/foo'); $this->fail(); } catch (MethodNotAllowedException $e) {} // route does match with GET or HEAD method context - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertInternalType('array', $matcher->match('/foo')); - $matcher = new UrlMatcher($collection, new RequestContext('', 'head'), array()); + $matcher = new UrlMatcher($collection, new RequestContext('', 'head')); $this->assertInternalType('array', $matcher->match('/foo')); // route with an optional variable as the first segment $collection = new RouteCollection(); $collection->add('bar', new Route('/{bar}/foo', array('bar' => 'bar'), array('bar' => 'foo|bar'))); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/bar/foo')); $this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo/foo')); $collection = new RouteCollection(); $collection->add('bar', new Route('/{bar}', array('bar' => 'bar'), array('bar' => 'foo|bar'))); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo')); $this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/')); // route with only optional variables $collection = new RouteCollection(); $collection->add('bar', new Route('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar'), array())); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'), $matcher->match('/')); $this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'), $matcher->match('/a')); $this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'b'), $matcher->match('/a/b')); @@ -139,7 +139,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $collection = new RouteCollection(); $collection->addCollection($collection2, '/a'); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'foo', 'foo' => 'foo'), $matcher->match('/a/b/foo')); } @@ -154,7 +154,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $collection = new RouteCollection(); $collection->addCollection($collection2, '/{_locale}'); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo')); } @@ -164,7 +164,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $chars = '!"$%éà &\'()*+,./:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[]^_`abcdefghijklmnopqrstuvwxyz{|}~-'; $collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '['.preg_quote($chars).']+'))); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.rawurlencode($chars).'/bar')); $this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.strtr($chars, array('%' => '%25')).'/bar')); } @@ -174,7 +174,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $collection = new RouteCollection(); $collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '.+'))); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched'); } @@ -188,7 +188,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $collection->addCollection($collection1); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); $this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1')); $this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); @@ -206,7 +206,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $collection = new RouteCollection(); $collection->add('foo', new Route('/{bar}')); - $matcher = new UrlMatcher($collection, new RequestContext(), array()); + $matcher = new UrlMatcher($collection, new RequestContext()); try { $matcher->match('/'); $this->fail();