From 0b37f82e393c3a1ff59cbf1572738d7d08252926 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 29 Mar 2013 11:44:17 +0100 Subject: [PATCH] starting version 1.1 with symfony 2.2 only. fix #50 --- .travis.yml | 1 - ChainRouter.php | 2 +- DynamicRouter.php | 2 + NestedMatcher/ConfigurableUrlMatcher.php | 70 --------- ProviderBasedGenerator.php | 8 +- .../ConfigurableUrlMatcherTest.php | 137 ------------------ composer.json | 6 +- 7 files changed, 7 insertions(+), 219 deletions(-) delete mode 100644 NestedMatcher/ConfigurableUrlMatcher.php delete mode 100644 Tests/NestedMatcher/ConfigurableUrlMatcherTest.php diff --git a/.travis.yml b/.travis.yml index ff056a0f..9c9cce93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ php: - 5.4 env: - - SYMFONY_VERSION=2.1.* - SYMFONY_VERSION=2.2.* - SYMFONY_VERSION=dev-master diff --git a/ChainRouter.php b/ChainRouter.php index b40fb0e8..85e3f314 100644 --- a/ChainRouter.php +++ b/ChainRouter.php @@ -30,7 +30,7 @@ class ChainRouter implements RouterInterface, RequestMatcherInterface, WarmableI private $context; /** - * @var Symfony\Component\Routing\RouterInterface[] + * @var \Symfony\Component\Routing\RouterInterface[] */ private $routers = array(); diff --git a/DynamicRouter.php b/DynamicRouter.php index ace3fbd3..13851fb6 100644 --- a/DynamicRouter.php +++ b/DynamicRouter.php @@ -10,7 +10,9 @@ use Symfony\Component\Routing\Matcher\RequestMatcherInterface; use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\RequestContextAwareInterface; +use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; +use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; diff --git a/NestedMatcher/ConfigurableUrlMatcher.php b/NestedMatcher/ConfigurableUrlMatcher.php deleted file mode 100644 index d488d277..00000000 --- a/NestedMatcher/ConfigurableUrlMatcher.php +++ /dev/null @@ -1,70 +0,0 @@ -matcherClass = $matcherClass; - } - - /** - * {@inheritdoc} - */ - public function finalMatch(RouteCollection $collection, Request $request) - { - $context = new RequestContext(); - $context->fromRequest($request); - $matcher = $this->getMatcher($collection, $context); - $attributes = $matcher->match($request->getPathInfo()); - - // SYMFONY 2.1 COMPATIBILITY: cleanup route attributes - if (! isset($attributes[RouteObjectInterface::ROUTE_OBJECT]) - || ! $attributes[RouteObjectInterface::ROUTE_OBJECT] instanceof Route - ) { - $name = $attributes['_route']; // this is the field coming from symfony core - $route = $collection->get($name); - $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route; - - if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) { - $name = $route->getRouteKey(); - } - - if (is_string($name)) { - $attributes[RouteObjectInterface::ROUTE_NAME] = $name; - } - } - - return $attributes; - } - - /** - * @param RouteCollection $collection the route collection to match - * @param RequestContext $context the context to match in - * - * @return \Symfony\Component\Routing\Matcher\UrlMatcherInterface - */ - protected function getMatcher(RouteCollection $collection, RequestContext $context) - { - return new $this->matcherClass($collection, $context); - } -} diff --git a/ProviderBasedGenerator.php b/ProviderBasedGenerator.php index f705bb20..21979a8c 100644 --- a/ProviderBasedGenerator.php +++ b/ProviderBasedGenerator.php @@ -43,13 +43,7 @@ public function generate($name, $parameters = array(), $absolute = false) // the Route has a cache of its own and is not recompiled as long as it does not get modified $compiledRoute = $route->compile(); - - // handle symfony 2.1 and 2.2 - // getHostTokens exists only since 2.2 - $hostTokens = null; - if (method_exists($compiledRoute, 'getHostTokens')) { - $hostTokens = $compiledRoute->getHostTokens(); - } + $hostTokens = $compiledRoute->getHostTokens(); return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $absolute, $hostTokens); } diff --git a/Tests/NestedMatcher/ConfigurableUrlMatcherTest.php b/Tests/NestedMatcher/ConfigurableUrlMatcherTest.php deleted file mode 100644 index 1d672ad4..00000000 --- a/Tests/NestedMatcher/ConfigurableUrlMatcherTest.php +++ /dev/null @@ -1,137 +0,0 @@ -routeDocument = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RouteMock', array('getDefaults', 'getRouteKey', 'compile')); - $this->routeCompiled = $this->buildMock('Symfony\\Component\\Routing\\CompiledRoute'); - - $this->context = $this->buildMock('Symfony\\Component\\Routing\\RequestContext'); - $this->request = Request::create($this->url); - - $this->matcher = new ConfigurableUrlMatcher(); - } - - public function testMatch() - { - $this->routeCompiled->expects($this->atLeastOnce()) - ->method('getStaticPrefix') - ->will($this->returnValue($this->url)) - ; - $this->routeCompiled->expects($this->atLeastOnce()) - ->method('getRegex') - ->will($this->returnValue('#'.str_replace('/', '\\/', $this->url).'#')) - ; - $this->routeDocument->expects($this->atLeastOnce()) - ->method('compile') - ->will($this->returnValue($this->routeCompiled)) - ; - $this->routeDocument->expects($this->atLeastOnce()) - ->method('getDefaults') - ->will($this->returnValue(array('foo' => 'bar'))) - ; - $this->routeDocument->expects($this->any()) - ->method('getRouteKey') - ->will($this->returnValue('/routes/company/more')) - ; - - // add some other routes to the collection - $mockCompiled = $this->buildMock('Symfony\\Component\\Routing\\CompiledRoute'); - $mockCompiled->expects($this->any()) - ->method('getStaticPrefix') - ->will($this->returnValue('/no/match')) - ; - $mockRoute = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); - $mockRoute->expects($this->any()) - ->method('compile') - ->will($this->returnValue($mockCompiled)) - ; - - $routeCollection = new RouteCollection(); - $routeCollection->add('some', $mockRoute); - $routeCollection->add('_company_more', $this->routeDocument); - $routeCollection->add('other', $mockRoute); - - $results = $this->matcher->finalMatch($routeCollection, $this->request); - - // the matched route returns a key - $expected = array( - RouteObjectInterface::ROUTE_NAME => '/routes/company/more', - RouteObjectInterface::ROUTE_OBJECT => $this->routeDocument, - 'foo' => 'bar', - ); - - $this->assertEquals($expected, $results); - } - - public function testMatchNoRouteObject() - { - $this->routeCompiled->expects($this->atLeastOnce()) - ->method('getStaticPrefix') - ->will($this->returnValue($this->url)) - ; - $this->routeCompiled->expects($this->atLeastOnce()) - ->method('getRegex') - ->will($this->returnValue('#'.str_replace('/', '\\/', $this->url).'#')) - ; - $this->routeDocument = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); - $this->routeDocument->expects($this->atLeastOnce()) - ->method('compile') - ->will($this->returnValue($this->routeCompiled)) - ; - $this->routeDocument->expects($this->never()) - ->method('getRouteKey') - ; - $this->routeDocument->expects($this->atLeastOnce()) - ->method('getDefaults') - ->will($this->returnValue(array('foo' => 'bar'))) - ; - - $mockCompiled = $this->buildMock('Symfony\\Component\\Routing\\CompiledRoute'); - $mockCompiled->expects($this->any()) - ->method('getStaticPrefix') - ->will($this->returnValue('/no/match')) - ; - $mockRoute = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); - $mockRoute->expects($this->any()) - ->method('compile') - ->will($this->returnValue($mockCompiled)) - ; - $routeCollection = new RouteCollection(); - $routeCollection->add('some', $mockRoute); - $routeCollection->add('_company_more', $this->routeDocument); - $routeCollection->add('other', $mockRoute); - - $results = $this->matcher->finalMatch($routeCollection, $this->request); - - // the matched route does not return a key - $expected = array( - RouteObjectInterface::ROUTE_NAME => '_company_more', - RouteObjectInterface::ROUTE_OBJECT => $this->routeDocument, - 'foo' => 'bar', - ); - - $this->assertEquals($expected, $results); - } -} diff --git a/composer.json b/composer.json index 7f0a2639..2912d075 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "minimum-stability": "dev", "require": { "php": ">=5.3.2", - "symfony/routing": ">=2.1,<2.3-dev", - "symfony/http-kernel": ">=2.1,<2.3-dev" + "symfony/routing": ">=2.2,<2.3-dev", + "symfony/http-kernel": ">=2.2,<2.3-dev" }, "autoload": { "psr-0": { "Symfony\\Cmf\\Component\\Routing": "" } @@ -23,7 +23,7 @@ "target-dir": "Symfony/Cmf/Component/Routing", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.1-dev" } } }