From 38ad82566af15cbb0aec1cc4f550bb9629ca2504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 22 Feb 2018 18:29:24 +0100 Subject: [PATCH 01/16] [VarDumper] Fixed PHPDoc --- src/Symfony/Component/VarDumper/Cloner/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/VarDumper/Cloner/Data.php b/src/Symfony/Component/VarDumper/Cloner/Data.php index aa06b1cfb0..75ded29121 100644 --- a/src/Symfony/Component/VarDumper/Cloner/Data.php +++ b/src/Symfony/Component/VarDumper/Cloner/Data.php @@ -227,7 +227,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate * * @param string|int $key The key to seek to * - * @return self|null A clone of $this of null if the key is not set + * @return self|null A clone of $this or null if the key is not set */ public function seek($key) { From cc68c5074e3f3d6f201e56256f1272a2832ba25a Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Fri, 23 Feb 2018 00:30:18 +0100 Subject: [PATCH 02/16] Set controller without __invoke method from invokable class --- .../Routing/AnnotatedRouteControllerLoader.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php index f5777af95a..474c725566 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php @@ -29,7 +29,11 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader */ protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) { - $route->setDefault('_controller', $class->getName().'::'.$method->getName()); + if ('__invoke' === $method->getName()) { + $route->setDefault('_controller', $class->getName()); + } else { + $route->setDefault('_controller', $class->getName().'::'.$method->getName()); + } } /** From 4d973c267681e148b3c6b79f0fa4e102edd84ed8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 23 Feb 2018 09:15:10 +0100 Subject: [PATCH 03/16] add container.autowiring.strict_mode to 3.4 docs --- UPGRADE-3.4.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index 7aa2069f46..00d6422f76 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -56,6 +56,15 @@ DependencyInjection autowire: true ``` + * Autowiring services based on the types they implement is deprecated and will not be supported anymore in Symfony 4.0 + where it will only match an alias or a service id that matches then given FQCN. You can opt in the behavior of Symfony + 4 by the enabling the `container.autowiring.strict_mode` parameter: + + ```yml + parameters: + container.autowiring.strict_mode: true + ``` + * Top-level anonymous services in XML are deprecated and will throw an exception in Symfony 4.0. * Case insensitivity of parameter names is deprecated and will be removed in 4.0. From 9587d045206c703f33ea9d198334e25eb6134a06 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 23 Feb 2018 15:02:47 +0100 Subject: [PATCH 04/16] [Routing] fix CS --- src/Symfony/Component/Routing/RouteCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index 3ae7b4147d..c80a599d9d 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -117,7 +117,7 @@ class RouteCollection implements \IteratorAggregate, \Countable * Adds a route collection at the end of the current set by appending all * routes of the added collection. */ - public function addCollection(RouteCollection $collection) + public function addCollection(self $collection) { // we need to remove all routes with the same names first because just replacing them // would not place the new route at the end of the merged array From 3cfe7d0ee358c728c1442ee6cd55cea0e1bd0af3 Mon Sep 17 00:00:00 2001 From: Tony Tran Date: Fri, 23 Feb 2018 15:40:28 +0100 Subject: [PATCH 05/16] Add missing use of Role --- .../Core/Authentication/Token/PreAuthenticatedToken.php | 2 +- .../Core/Authentication/Token/UsernamePasswordToken.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php index e2b49614df..662135a851 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Security\Core\Authentication\Token; -use Symfony\Component\Security\Core\Role\RoleInterface; +use Symfony\Component\Security\Core\Role\Role; /** * PreAuthenticatedToken implements a pre-authenticated token. diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php index 1270cc2b4c..1959a1bdf9 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Security\Core\Authentication\Token; +use Symfony\Component\Security\Core\Role\Role; + /** * UsernamePasswordToken implements a username and password token. * From 05359f310f48f2922af980fe000f711ecbb3a8d1 Mon Sep 17 00:00:00 2001 From: Tony Tran Date: Fri, 23 Feb 2018 14:42:02 +0100 Subject: [PATCH 06/16] Add missing use for RoleInterface --- .../Core/Authentication/Token/UsernamePasswordToken.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php index 45f333acdb..9c790a98d4 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Security\Core\Authentication\Token; +use Symfony\Component\Security\Core\Role\RoleInterface; + /** * UsernamePasswordToken implements a username and password token. * From ce0109793557ca374bf9d86441cb8d621f2b117c Mon Sep 17 00:00:00 2001 From: Houziaux mike Date: Wed, 14 Feb 2018 15:19:15 +0100 Subject: [PATCH 07/16] Update excluded_ajax_paths for sf4 --- .../DependencyInjection/Configuration.php | 2 +- .../Tests/DependencyInjection/ConfigurationTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php index e07b28925d..963c832cf6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php @@ -46,7 +46,7 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->booleanNode('intercept_redirects')->defaultFalse()->end() - ->scalarNode('excluded_ajax_paths')->defaultValue('^/(app(_[\\w]+)?\\.php/)?_wdt')->end() + ->scalarNode('excluded_ajax_paths')->defaultValue('^/((index|app(_[\w]+)?)\.php/)?_wdt')->end() ->end() ; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php index afbecf9b38..a341cb15e1 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -46,10 +46,10 @@ class ConfigurationTest extends TestCase public function getDebugModes() { return array( - array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')), - array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')), - array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')), - array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')), + array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')), + array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')), + array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')), + array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')), array(array('excluded_ajax_paths' => 'test'), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => 'test')), ); } From f371fd8ced1e993a74adfb7057c73d1f118d40f4 Mon Sep 17 00:00:00 2001 From: Maxim Lovchikov Date: Sat, 24 Feb 2018 16:59:02 +0000 Subject: [PATCH 08/16] Fix ArrayInput::toString() for InputArgument::IS_ARRAY args --- src/Symfony/Component/Console/Input/ArrayInput.php | 2 +- src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/ArrayInput.php b/src/Symfony/Component/Console/Input/ArrayInput.php index bf987f98e1..eb921fd19e 100644 --- a/src/Symfony/Component/Console/Input/ArrayInput.php +++ b/src/Symfony/Component/Console/Input/ArrayInput.php @@ -103,7 +103,7 @@ class ArrayInput extends Input $params[] = $param.('' != $val ? '='.$this->escapeToken($val) : ''); } } else { - $params[] = is_array($val) ? array_map(array($this, 'escapeToken'), $val) : $this->escapeToken($val); + $params[] = is_array($val) ? implode(' ', array_map(array($this, 'escapeToken'), $val)) : $this->escapeToken($val); } } diff --git a/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php index 608020a5ca..b998172e62 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php @@ -143,5 +143,8 @@ class ArrayInputTest extends TestCase $input = new ArrayInput(array('-b' => array('bval_1', 'bval_2'), '--f' => array('fval_1', 'fval_2'))); $this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input); + + $input = new ArrayInput(array('array_arg' => array('val_1', 'val_2'))); + $this->assertSame('val_1 val_2', (string) $input); } } From 77dfc9084670c6382a02b35e063c2940aee0ad4a Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Sat, 24 Feb 2018 20:41:23 +0100 Subject: [PATCH 09/16] [WebProfilerBundle] fix test after ajax path updated --- .../Tests/DependencyInjection/ConfigurationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php index a341cb15e1..8028c2cd4b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -57,8 +57,8 @@ class ConfigurationTest extends TestCase public function getPositionConfig() { return array( - array(array('position' => 'top'), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt', 'position' => 'top')), - array(array('position' => 'bottom'), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt', 'position' => 'bottom')), + array(array('position' => 'top'), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt', 'position' => 'top')), + array(array('position' => 'bottom'), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt', 'position' => 'bottom')), ); } } From 391b01393de1bb366cd0d1c8fc53a640b4367d25 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 25 Feb 2018 09:34:03 +0100 Subject: [PATCH 10/16] [Routing] Revert throwing 405 on missed slash/scheme redirections --- .../Component/Routing/Matcher/Dumper/PhpMatcherDumper.php | 2 -- .../Routing/Tests/Fixtures/dumper/url_matcher2.php | 5 ----- .../Tests/Matcher/DumpedRedirectableUrlMatcherTest.php | 8 -------- 3 files changed, 15 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index ac48ca978f..0ff82a2c93 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -264,7 +264,6 @@ EOF; if ('/' === substr(\$pathinfo, -1)) { // no-op } elseif (!in_array(\$this->context->getMethod(), array('HEAD', 'GET'))) { - \$allow[] = 'GET'; goto $gotoname; } else { return \$this->redirect(\$rawPathinfo.'/', '$name'); @@ -283,7 +282,6 @@ EOF; \$requiredSchemes = $schemes; if (!isset(\$requiredSchemes[\$this->context->getScheme()])) { if (!in_array(\$this->context->getMethod(), array('HEAD', 'GET'))) { - \$allow[] = 'GET'; goto $gotoname; } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php index 467d53b3ed..7c8e997477 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php @@ -69,7 +69,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if ('/' === substr($pathinfo, -1)) { // no-op } elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) { - $allow[] = 'GET'; goto not_baz3; } else { return $this->redirect($rawPathinfo.'/', 'baz3'); @@ -86,7 +85,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if ('/' === substr($pathinfo, -1)) { // no-op } elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) { - $allow[] = 'GET'; goto not_baz4; } else { return $this->redirect($rawPathinfo.'/', 'baz4'); @@ -185,7 +183,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if ('/' === substr($pathinfo, -1)) { // no-op } elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) { - $allow[] = 'GET'; goto not_hey; } else { return $this->redirect($rawPathinfo.'/', 'hey'); @@ -337,7 +334,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec $requiredSchemes = array ( 'https' => 0,); if (!isset($requiredSchemes[$this->context->getScheme()])) { if (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) { - $allow[] = 'GET'; goto not_secure; } @@ -353,7 +349,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec $requiredSchemes = array ( 'http' => 0,); if (!isset($requiredSchemes[$this->context->getScheme()])) { if (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) { - $allow[] = 'GET'; goto not_nonsecure; } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/DumpedRedirectableUrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/DumpedRedirectableUrlMatcherTest.php index 7ea8aa2834..28f65aeeb5 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/DumpedRedirectableUrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/DumpedRedirectableUrlMatcherTest.php @@ -19,14 +19,6 @@ use Symfony\Component\Routing\RequestContext; class DumpedRedirectableUrlMatcherTest extends RedirectableUrlMatcherTest { - /** - * @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException - */ - public function testRedirectWhenNoSlashForNonSafeMethod() - { - parent::testRedirectWhenNoSlashForNonSafeMethod(); - } - protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null) { static $i = 0; From 9d70ef0915cb2cbc8afe1bdc5edcbfc1b1b7b99e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 25 Feb 2018 22:38:00 +0100 Subject: [PATCH 11/16] [Routing] Don't throw 405 when scheme requirement doesn't match --- .../Matcher/Dumper/PhpMatcherDumper.php | 29 ++++++++++++++++--- .../Component/Routing/Matcher/UrlMatcher.php | 16 +++++----- .../Tests/Matcher/DumpedUrlMatcherTest.php | 9 ++++++ .../Routing/Tests/Matcher/UrlMatcherTest.php | 12 ++++++++ 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 0ff82a2c93..8701dfd304 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -278,7 +278,29 @@ EOF; throw new \LogicException('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.'); } $schemes = str_replace("\n", '', var_export(array_flip($schemes), true)); - $code .= <<context->getScheme()]); + if (!in_array(\$this->context->getMethod(), array('$methods'))) { + if (\$hasRequiredScheme) { + \$allow = array_merge(\$allow, array('$methods')); + } + goto $gotoname; + } + if (!\$hasRequiredScheme) { + if (!in_array(\$this->context->getMethod(), array('HEAD', 'GET'))) { + goto $gotoname; + } + + return \$this->redirect(\$rawPathinfo, '$name', key(\$requiredSchemes)); + } + + +EOF; + } else { + $code .= <<context->getScheme()])) { if (!in_array(\$this->context->getMethod(), array('HEAD', 'GET'))) { @@ -290,9 +312,8 @@ EOF; EOF; - } - - if ($methods) { + } + } elseif ($methods) { if (1 === count($methods)) { $code .= <<context->getMethod() != '$methods[0]') { diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 1ef92827dc..e2b9f14710 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -129,6 +129,12 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface continue; } + $status = $this->handleRouteRequirements($pathinfo, $name, $route); + + if (self::REQUIREMENT_MISMATCH === $status[0]) { + continue; + } + // check HTTP method requirement if ($requiredMethods = $route->getMethods()) { // HEAD and GET are equivalent as per RFC @@ -137,22 +143,18 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface } if (!in_array($method, $requiredMethods)) { - $this->allow = array_merge($this->allow, $requiredMethods); + if (self::REQUIREMENT_MATCH === $status[0]) { + $this->allow = array_merge($this->allow, $requiredMethods); + } continue; } } - $status = $this->handleRouteRequirements($pathinfo, $name, $route); - if (self::ROUTE_MATCH === $status[0]) { return $status[1]; } - if (self::REQUIREMENT_MISMATCH === $status[0]) { - continue; - } - return $this->getAttributes($route, $name, array_replace($matches, $hostMatches)); } } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/DumpedUrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/DumpedUrlMatcherTest.php index cc7eb8e2d7..e36a0220d9 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/DumpedUrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/DumpedUrlMatcherTest.php @@ -26,6 +26,15 @@ class DumpedUrlMatcherTest extends UrlMatcherTest parent::testSchemeRequirement(); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface. + */ + public function testSchemeAndMethodMismatch() + { + parent::testSchemeRequirement(); + } + protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null) { static $i = 0; diff --git a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php index 1fc78294c7..8328962ae4 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php @@ -464,6 +464,18 @@ class UrlMatcherTest extends TestCase $this->assertEquals(array('_route' => 'buz'), $matcher->match('/prefix/buz')); } + /** + * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException + */ + public function testSchemeAndMethodMismatch() + { + $coll = new RouteCollection(); + $coll->add('foo', new Route('/', array(), array(), array(), null, array('https'), array('POST'))); + + $matcher = $this->getUrlMatcher($coll); + $matcher->match('/'); + } + protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null) { return new UrlMatcher($routes, $context ?: new RequestContext()); From 239f2e21e554feb0a02c615b6da48272879d844a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 26 Feb 2018 14:41:42 +0100 Subject: [PATCH 12/16] [Routing] Fix GC control of PHP-DSL --- .../Loader/Configurator/CollectionConfigurator.php | 8 +++++--- .../Routing/Loader/Configurator/RouteConfigurator.php | 5 ++++- .../Routing/Loader/Configurator/Traits/AddTrait.php | 3 ++- src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php index 38d86cb895..8baefdd592 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php @@ -23,13 +23,15 @@ class CollectionConfigurator use Traits\RouteTrait; private $parent; + private $parentConfigurator; - public function __construct(RouteCollection $parent, $name) + public function __construct(RouteCollection $parent, $name, self $parentConfigurator = null) { $this->parent = $parent; $this->name = $name; $this->collection = new RouteCollection(); $this->route = new Route(''); + $this->parentConfigurator = $parentConfigurator; // for GC control } public function __destruct() @@ -50,7 +52,7 @@ class CollectionConfigurator { $this->collection->add($this->name.$name, $route = clone $this->route); - return new RouteConfigurator($this->collection, $route->setPath($path), $this->name); + return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this); } /** @@ -60,7 +62,7 @@ class CollectionConfigurator */ final public function collection($name = '') { - return new self($this->collection, $this->name.$name); + return new self($this->collection, $this->name.$name, $this); } /** diff --git a/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php index b8d8702543..6422bbf676 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php @@ -22,10 +22,13 @@ class RouteConfigurator use Traits\AddTrait; use Traits\RouteTrait; - public function __construct(RouteCollection $collection, Route $route, $name = '') + private $parentConfigurator; + + public function __construct(RouteCollection $collection, Route $route, $name = '', CollectionConfigurator $parentConfigurator = null) { $this->collection = $collection; $this->route = $route; $this->name = $name; + $this->parentConfigurator = $parentConfigurator; // for GC control } } diff --git a/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php b/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php index 7171fd241f..01a082aed3 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php @@ -34,9 +34,10 @@ trait AddTrait */ final public function add($name, $path) { + $parentConfigurator = $this instanceof RouteConfigurator ? $this->parentConfigurator : null; $this->collection->add($this->name.$name, $route = new Route($path)); - return new RouteConfigurator($this->collection, $route); + return new RouteConfigurator($this->collection, $route, $parentConfigurator); } /** diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php b/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php index 04f6d7ed6e..0780c9fa80 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php @@ -4,6 +4,7 @@ namespace Symfony\Component\Routing\Loader\Configurator; return function (RoutingConfigurator $routes) { $routes + ->collection() ->add('foo', '/foo') ->condition('abc') ->options(array('utf8' => true)) From 2abb8a4fd1da266b3af2f54920f8991f4b9728c7 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Mon, 26 Feb 2018 15:27:04 +0100 Subject: [PATCH 13/16] Use long array syntax --- .../Tests/Compiler/MergeExtensionConfigurationPassTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php index fccda7e129..77872720aa 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php @@ -110,7 +110,7 @@ class MergeExtensionConfigurationPassTest extends TestCase { $container = new ContainerBuilder(); $container->registerExtension(new BarExtension()); - $container->prependExtensionConfig('bar', []); + $container->prependExtensionConfig('bar', array()); (new MergeExtensionConfigurationPass())->process($container); } From 04b56d6ddf83223fb011c0813578588c6bbb7f6e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 26 Feb 2018 15:56:38 +0100 Subject: [PATCH 14/16] [appveyor] Workaround GitHub disabling of low versions of TLS --- appveyor.yml | 8 +++++--- src/Symfony/Component/Routing/Tests/RouterTest.php | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 9ff140b0a2..5cbbb67386 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,10 +18,10 @@ install: - mkdir c:\php && cd c:\php - appveyor DownloadFile https://raw.githubusercontent.com/symfony/binary-utils/master/cacert.pem - appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php-5.3.9-nts-Win32-VC9-x86.zip - - 7z x php-5.3.9-nts-Win32-VC9-x86.zip -y >nul - appveyor DownloadFile https://raw.githubusercontent.com/symfony/binary-utils/master/ICU-51.2-dlls.zip - 7z x ICU-51.2-dlls.zip -y >nul - appveyor DownloadFile https://github.com/symfony/binary-utils/releases/download/v0.1/php-7.1.3-Win32-VC14-x86.zip + - 7z x php-7.1.3-Win32-VC14-x86.zip -y >nul - cd ext - appveyor DownloadFile https://raw.githubusercontent.com/symfony/binary-utils/master/php_intl-3.0.0-5.3-nts-vc9-x86.zip - 7z x php_intl-3.0.0-5.3-nts-vc9-x86.zip -y >nul @@ -47,19 +47,21 @@ install: - echo extension=php_pdo_sqlite.dll >> php.ini-max - echo extension=php_curl.dll >> php.ini-max - echo curl.cainfo=c:\php\cacert.pem >> php.ini-max - - copy /Y php.ini-max php.ini + - copy /Y php.ini-min php.ini + - echo extension=php_openssl.dll >> php.ini - cd c:\projects\symfony - IF NOT EXIST composer.phar (appveyor DownloadFile https://getcomposer.org/download/1.3.0/composer.phar) - php composer.phar self-update - copy /Y .composer\* %APPDATA%\Composer\ - php .github/build-packages.php "HEAD^" src\Symfony\Bridge\PhpUnit - IF %APPVEYOR_REPO_BRANCH%==master (SET COMPOSER_ROOT_VERSION=dev-master) ELSE (SET COMPOSER_ROOT_VERSION=%APPVEYOR_REPO_BRANCH%.x-dev) + - php composer.phar config platform.php 5.3.9 - php composer.phar update --no-progress --no-suggest --ansi - php phpunit install test_script: - SET X=0 - - cd c:\php && 7z x php-7.1.3-Win32-VC14-x86.zip -y >nul && copy /Y php.ini-min php.ini + - cd c:\php && copy /Y php.ini-min php.ini - cd c:\projects\symfony - php phpunit src\Symfony --exclude-group benchmark,intl-data || SET X=!errorlevel! - cd c:\php && 7z x php-5.3.9-nts-Win32-VC9-x86.zip -y >nul && copy /Y php.ini-min php.ini diff --git a/src/Symfony/Component/Routing/Tests/RouterTest.php b/src/Symfony/Component/Routing/Tests/RouterTest.php index 409959eec0..4fba383a7c 100644 --- a/src/Symfony/Component/Routing/Tests/RouterTest.php +++ b/src/Symfony/Component/Routing/Tests/RouterTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Routing\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Router; use Symfony\Component\HttpFoundation\Request; @@ -83,7 +84,7 @@ class RouterTest extends TestCase { $this->router->setOption('resource_type', 'ResourceType'); - $routeCollection = $this->getMockBuilder('Symfony\Component\Routing\RouteCollection')->getMock(); + $routeCollection = new RouteCollection(); $this->loader->expects($this->once()) ->method('load')->with('routing.yml', 'ResourceType') From 87bbe5ef5fe1221887c9c58560694b6496419695 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 26 Feb 2018 16:48:14 +0100 Subject: [PATCH 15/16] [Routing] remove useless failing mocks --- src/Symfony/Component/Routing/Tests/RouterTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/RouterTest.php b/src/Symfony/Component/Routing/Tests/RouterTest.php index 4fba383a7c..3e3d43f82c 100644 --- a/src/Symfony/Component/Routing/Tests/RouterTest.php +++ b/src/Symfony/Component/Routing/Tests/RouterTest.php @@ -102,7 +102,7 @@ class RouterTest extends TestCase $this->loader->expects($this->once()) ->method('load')->with('routing.yml', null) - ->will($this->returnValue($this->getMockBuilder('Symfony\Component\Routing\RouteCollection')->getMock())); + ->will($this->returnValue(new RouteCollection())); $this->assertInstanceOf('Symfony\\Component\\Routing\\Matcher\\UrlMatcher', $this->router->getMatcher()); } @@ -124,7 +124,7 @@ class RouterTest extends TestCase $this->loader->expects($this->once()) ->method('load')->with('routing.yml', null) - ->will($this->returnValue($this->getMockBuilder('Symfony\Component\Routing\RouteCollection')->getMock())); + ->will($this->returnValue(new RouteCollection())); $this->assertInstanceOf('Symfony\\Component\\Routing\\Generator\\UrlGenerator', $this->router->getGenerator()); } From 80f993fdba9c35c8178415f67b85032a7f2b3e7a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 26 Feb 2018 16:57:04 +0100 Subject: [PATCH 16/16] Fix typos --- .../Component/Routing/Loader/Configurator/Traits/AddTrait.php | 2 +- .../Component/Routing/Matcher/Dumper/PhpMatcherDumper.php | 2 +- .../Component/Routing/Tests/Fixtures/dumper/url_matcher2.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php b/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php index 01a082aed3..e8b8fa2680 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php @@ -37,7 +37,7 @@ trait AddTrait $parentConfigurator = $this instanceof RouteConfigurator ? $this->parentConfigurator : null; $this->collection->add($this->name.$name, $route = new Route($path)); - return new RouteConfigurator($this->collection, $route, $parentConfigurator); + return new RouteConfigurator($this->collection, $route, '', $parentConfigurator); } /** diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index e79542d829..a17fc5a08f 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -347,7 +347,7 @@ EOF; } else { $code .= <<context->getScheme()])) { + if (!isset(\$requiredSchemes[\$context->getScheme()])) { if ('GET' !== \$canonicalMethod) { goto $gotoname; } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php index d9fe0e0a29..97070e1c54 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php @@ -343,7 +343,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if ('/secure' === $pathinfo) { $ret = array('_route' => 'secure'); $requiredSchemes = array ( 'https' => 0,); - if (!isset($requiredSchemes[$this->context->getScheme()])) { + if (!isset($requiredSchemes[$context->getScheme()])) { if ('GET' !== $canonicalMethod) { goto not_secure; } @@ -359,7 +359,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if ('/nonsecure' === $pathinfo) { $ret = array('_route' => 'nonsecure'); $requiredSchemes = array ( 'http' => 0,); - if (!isset($requiredSchemes[$this->context->getScheme()])) { + if (!isset($requiredSchemes[$context->getScheme()])) { if ('GET' !== $canonicalMethod) { goto not_nonsecure; }