From dbb0f2ad77f41e5ae754f949074a3cc57d7d2a06 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 20 Nov 2018 17:47:12 +0100 Subject: [PATCH 1/3] [Bridge/PhpUnit] fix the fix --- src/Symfony/Bridge/PhpUnit/bin/simple-phpunit | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit index 83a3afc901..af60eb0f8c 100755 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit @@ -60,6 +60,9 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ @mkdir($PHPUNIT_DIR, 0777, true); chdir($PHPUNIT_DIR); + if (file_exists("phpunit-$PHPUNIT_VERSION")) { + passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION")); + } passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); chdir("phpunit-$PHPUNIT_VERSION"); if ($SYMFONY_PHPUNIT_REMOVE) { From 640ccdf06924bed2f05bdfcfd9cc9379e266e566 Mon Sep 17 00:00:00 2001 From: Claude Dioudonnat Date: Wed, 21 Nov 2018 20:04:39 +0100 Subject: [PATCH 2/3] [Routing] Remove duplicate schemes and methods for invokable controllers --- .../Routing/Loader/AnnotationClassLoader.php | 31 +++++++++------- .../Loader/AnnotationClassLoaderTest.php | 37 ++++++++++++++++++- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 8c96835826..76a120b8ef 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -120,11 +120,9 @@ abstract class AnnotationClassLoader implements LoaderInterface } if (0 === $collection->count() && $class->hasMethod('__invoke')) { + $globals = $this->resetGlobals(); foreach ($this->reader->getClassAnnotations($class) as $annot) { if ($annot instanceof $this->routeAnnotationClass) { - $globals['path'] = ''; - $globals['name'] = ''; - $this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke')); } } @@ -212,17 +210,7 @@ abstract class AnnotationClassLoader implements LoaderInterface protected function getGlobals(\ReflectionClass $class) { - $globals = array( - 'path' => '', - 'requirements' => array(), - 'options' => array(), - 'defaults' => array(), - 'schemes' => array(), - 'methods' => array(), - 'host' => '', - 'condition' => '', - 'name' => '', - ); + $globals = $this->resetGlobals(); if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) { if (null !== $annot->getName()) { @@ -265,6 +253,21 @@ abstract class AnnotationClassLoader implements LoaderInterface return $globals; } + private function resetGlobals() + { + return array( + 'path' => '', + 'requirements' => array(), + 'options' => array(), + 'defaults' => array(), + 'schemes' => array(), + 'methods' => array(), + 'host' => '', + 'condition' => '', + 'name' => '', + ); + } + protected function createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition) { return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition); diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php index beab0b2e83..a0230ada88 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php @@ -181,7 +181,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest $this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods'); } - public function testInvokableClassRouteLoad() + public function testInvokableClassRouteLoadWithMethodAnnotation() { $classRouteData = array( 'name' => 'route1', @@ -209,6 +209,41 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest $this->assertEquals($classRouteData['methods'], $route->getMethods(), '->load preserves class route methods'); } + public function testInvokableClassRouteLoadWithClassAnnotation() + { + $classRouteData = array( + 'name' => 'route1', + 'path' => '/', + 'schemes' => array('https'), + 'methods' => array('GET'), + ); + + $this->reader + ->expects($this->exactly(1)) + ->method('getClassAnnotation') + ->will($this->returnValue($this->getAnnotatedRoute($classRouteData))) + ; + + $this->reader + ->expects($this->exactly(1)) + ->method('getClassAnnotations') + ->will($this->returnValue(array($this->getAnnotatedRoute($classRouteData)))) + ; + + $this->reader + ->expects($this->once()) + ->method('getMethodAnnotations') + ->will($this->returnValue(array())) + ; + + $routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass'); + $route = $routeCollection->get($classRouteData['name']); + + $this->assertSame($classRouteData['path'], $route->getPath(), '->load preserves class route path'); + $this->assertEquals($classRouteData['schemes'], $route->getSchemes(), '->load preserves class route schemes'); + $this->assertEquals($classRouteData['methods'], $route->getMethods(), '->load preserves class route methods'); + } + public function testInvokableClassMultipleRouteLoad() { $classRouteData1 = array( From 9f4032d20f5293a644bf5440c9695f2e24c564dc Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 22 Nov 2018 08:01:54 +0100 Subject: [PATCH 3/3] fix authorization checker variable name --- .../Component/Workflow/EventListener/GuardListener.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Workflow/EventListener/GuardListener.php b/src/Symfony/Component/Workflow/EventListener/GuardListener.php index 4d3cfac57e..b2e6b8c7b3 100644 --- a/src/Symfony/Component/Workflow/EventListener/GuardListener.php +++ b/src/Symfony/Component/Workflow/EventListener/GuardListener.php @@ -27,17 +27,17 @@ class GuardListener private $configuration; private $expressionLanguage; private $tokenStorage; - private $authenticationChecker; + private $authorizationChecker; private $trustResolver; private $roleHierarchy; private $validator; - public function __construct(array $configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authenticationChecker, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null, ValidatorInterface $validator = null) + public function __construct(array $configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null, ValidatorInterface $validator = null) { $this->configuration = $configuration; $this->expressionLanguage = $expressionLanguage; $this->tokenStorage = $tokenStorage; - $this->authenticationChecker = $authenticationChecker; + $this->authorizationChecker = $authorizationChecker; $this->trustResolver = $trustResolver; $this->roleHierarchy = $roleHierarchy; $this->validator = $validator; @@ -92,7 +92,7 @@ class GuardListener return $role->getRole(); }, $roles), // needed for the is_granted expression function - 'auth_checker' => $this->authenticationChecker, + 'auth_checker' => $this->authorizationChecker, // needed for the is_* expression function 'trust_resolver' => $this->trustResolver, // needed for the is_valid expression function