Merge branch '3.4' into 4.1

* 3.4:
  fix authorization checker variable name
  [Routing] Remove duplicate schemes and methods for invokable controllers
  [Bridge/PhpUnit] fix the fix
This commit is contained in:
Fabien Potencier 2018-11-24 08:45:31 +01:00
commit b178266bcd
5 changed files with 29 additions and 22 deletions

View File

@ -89,6 +89,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) {

View File

@ -120,12 +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'] = '';
$globals['localized_paths'] = array();
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
}
}
@ -254,18 +251,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
protected function getGlobals(\ReflectionClass $class)
{
$globals = array(
'path' => null,
'localized_paths' => array(),
'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()) {
@ -310,6 +296,22 @@ abstract class AnnotationClassLoader implements LoaderInterface
return $globals;
}
private function resetGlobals()
{
return array(
'path' => null,
'localized_paths' => array(),
'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);

View File

@ -5,7 +5,7 @@ namespace Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/here", name="lol")
* @Route("/here", name="lol", methods={"GET", "POST"}, schemes={"https"})
*/
class InvokableController
{

View File

@ -92,6 +92,8 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$routes = $this->loader->load(InvokableController::class);
$this->assertCount(1, $routes);
$this->assertEquals('/here', $routes->get('lol')->getPath());
$this->assertEquals(array('GET', 'POST'), $routes->get('lol')->getMethods());
$this->assertEquals(array('https'), $routes->get('lol')->getSchemes());
}
public function testInvokableLocalizedControllerLoading()
@ -134,7 +136,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$this->assertEquals('/the/path', $routes->get('post')->getPath());
}
public function testLocalizedMethodActionControllers()
public function testInvokableClassRouteLoadWithMethodAnnotation()
{
$routes = $this->loader->load(LocalizedMethodActionControllers::class);
$this->assertCount(4, $routes);

View File

@ -28,17 +28,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;
@ -94,7 +94,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