Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Fixed Symfony 4.3 deprecations. #625

Merged
merged 1 commit into from Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions EventListener/ControllerListener.php
Expand Up @@ -13,10 +13,10 @@

use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Persistence\Proxy;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* The ControllerListener class parses annotation blocks located in
Expand All @@ -41,7 +41,7 @@ public function __construct(Reader $reader)
* controllers annotations like the template to render or HTTP caching
* configuration.
*/
public function onKernelController(FilterControllerEvent $event)
public function onKernelController(ControllerEvent $event)
{
$controller = $event->getController();

Expand Down
12 changes: 6 additions & 6 deletions EventListener/HttpCacheListener.php
Expand Up @@ -11,12 +11,12 @@

namespace Sensio\Bundle\FrameworkExtraBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* HttpCacheListener handles HTTP cache headers.
Expand All @@ -40,7 +40,7 @@ public function __construct()
/**
* Handles HTTP validation headers.
*/
public function onKernelController(FilterControllerEvent $event)
public function onKernelController(ControllerEvent $event)
{
$request = $event->getRequest();
if (!$configuration = $request->attributes->get('_cache')) {
Expand Down Expand Up @@ -79,7 +79,7 @@ public function onKernelController(FilterControllerEvent $event)
/**
* Modifies the response to apply HTTP cache headers when needed.
*/
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(ResponseEvent $event)
{
$request = $event->getRequest();

Expand Down
4 changes: 2 additions & 2 deletions EventListener/IsGrantedListener.php
Expand Up @@ -14,7 +14,7 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Request\ArgumentNameConverter;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
Expand All @@ -36,7 +36,7 @@ public function __construct(ArgumentNameConverter $argumentNameConverter, Author
$this->authChecker = $authChecker;
}

public function onKernelControllerArguments(FilterControllerArgumentsEvent $event)
public function onKernelControllerArguments(ControllerArgumentsEvent $event)
{
$request = $event->getRequest();
/** @var $configurations IsGranted[] */
Expand Down
6 changes: 3 additions & 3 deletions EventListener/ParamConverterListener.php
Expand Up @@ -13,10 +13,10 @@

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* The ParamConverterListener handles the ParamConverter annotation.
Expand Down Expand Up @@ -50,7 +50,7 @@ public function __construct(ParamConverterManager $manager, $autoConvert = true)
/**
* Modifies the ParamConverterManager instance.
*/
public function onKernelController(FilterControllerEvent $event)
public function onKernelController(ControllerEvent $event)
{
$controller = $event->getController();
$request = $event->getRequest();
Expand Down
4 changes: 2 additions & 2 deletions EventListener/PsrResponseListener.php
Expand Up @@ -14,7 +14,7 @@
use Psr\Http\Message\ResponseInterface;
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand All @@ -37,7 +37,7 @@ public function __construct(HttpFoundationFactoryInterface $httpFoundationFactor
/**
* Do the conversion if applicable and update the response of the event.
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
public function onKernelView(ViewEvent $event)
{
$controllerResult = $event->getControllerResult();

Expand Down
16 changes: 7 additions & 9 deletions EventListener/SecurityListener.php
Expand Up @@ -14,10 +14,10 @@
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Request\ArgumentNameConverter;
use Sensio\Bundle\FrameworkExtraBundle\Security\ExpressionLanguage;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function __construct(ArgumentNameConverter $argumentNameConverter, Expres
$this->logger = $logger;
}

public function onKernelControllerArguments(FilterControllerArgumentsEvent $event)
public function onKernelControllerArguments(ControllerArgumentsEvent $event)
{
$request = $event->getRequest();
if (!$configurations = $request->attributes->get('_security')) {
Expand Down Expand Up @@ -81,15 +81,15 @@ public function onKernelControllerArguments(FilterControllerArgumentsEvent $even
}

// code should be sync with Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter
private function getVariables(FilterControllerArgumentsEvent $event)
private function getVariables(ControllerArgumentsEvent $event)
{
$request = $event->getRequest();
$token = $this->tokenStorage->getToken();

if (null !== $this->roleHierarchy) {
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
$roles = $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
} else {
$roles = $token->getRoles();
$roles = $token->getRoleNames();
}

$variables = [
Expand All @@ -98,9 +98,7 @@ private function getVariables(FilterControllerArgumentsEvent $event)
'object' => $request,
'subject' => $request,
'request' => $request,
'roles' => array_map(function ($role) {
return $role->getRole();
}, $roles),
'roles' => $roles,
'trust_resolver' => $this->trustResolver,
// needed for the is_granted expression function
'auth_checker' => $this->authChecker,
Expand Down
16 changes: 8 additions & 8 deletions EventListener/TemplateListener.php
Expand Up @@ -11,15 +11,15 @@

namespace Sensio\Bundle\FrameworkExtraBundle\EventListener;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Templating\TemplateGuesser;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Templating\TemplateGuesser;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* Handles the Template annotation for actions.
Expand All @@ -43,7 +43,7 @@ public function __construct(TemplateGuesser $templateGuesser, \Twig_Environment
* Guesses the template name to render and its variables and adds them to
* the request object.
*/
public function onKernelController(FilterControllerEvent $event)
public function onKernelController(ControllerEvent $event)
{
$request = $event->getRequest();
$template = $request->attributes->get('_template');
Expand All @@ -68,7 +68,7 @@ public function onKernelController(FilterControllerEvent $event)
* Renders the template and initializes a new response object with the
* rendered template content.
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
public function onKernelView(ViewEvent $event)
{
/* @var Template $template */
$request = $event->getRequest();
Expand Down
6 changes: 3 additions & 3 deletions Tests/EventListener/ControllerListenerTest.php
Expand Up @@ -11,6 +11,7 @@

namespace Sensio\Bundle\FrameworkExtraBundle\Tests\EventListener;

use Doctrine\Common\Annotations\AnnotationReader;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener;
use Sensio\Bundle\FrameworkExtraBundle\Tests\EventListener\Fixture\FooControllerCacheAtClass;
Expand All @@ -19,9 +20,8 @@
use Sensio\Bundle\FrameworkExtraBundle\Tests\EventListener\Fixture\FooControllerMultipleCacheAtClass;
use Sensio\Bundle\FrameworkExtraBundle\Tests\EventListener\Fixture\FooControllerMultipleCacheAtMethod;
use Sensio\Bundle\FrameworkExtraBundle\Tests\EventListener\Fixture\FooControllerParamConverterAtClassAndMethod;
use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class ControllerListenerTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -131,7 +131,7 @@ private function getFilterControllerEvent($controller, Request $request)
{
$mockKernel = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\Kernel', ['', '']);

return new FilterControllerEvent($mockKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST);
return new ControllerEvent($mockKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST);
}

private function getReadedCache()
Expand Down
28 changes: 14 additions & 14 deletions Tests/EventListener/HttpCacheListenerTest.php
Expand Up @@ -11,12 +11,12 @@

namespace Sensio\Bundle\FrameworkExtraBundle\Tests\EventListener;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class HttpCacheListenerTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -155,7 +155,7 @@ public function testLastModifiedNotModifiedResponse()
$request->headers->add(['If-Modified-Since' => 'Fri, 23 Aug 2013 00:00:00 GMT']);

$listener = new HttpCacheListener();
$controllerEvent = new FilterControllerEvent($this->getKernel(), function () {
$controllerEvent = new ControllerEvent($this->getKernel(), function () {
return new Response(500);
}, $request, null);

Expand All @@ -172,12 +172,12 @@ public function testLastModifiedHeader()
$response = new Response();

$listener = new HttpCacheListener();
$controllerEvent = new FilterControllerEvent($this->getKernel(), function () {
$controllerEvent = new ControllerEvent($this->getKernel(), function () {
return new Response();
}, $request, null);
$listener->onKernelController($controllerEvent);

$responseEvent = new FilterResponseEvent($this->getKernel(), $request, HttpKernelInterface::MASTER_REQUEST, \call_user_func($controllerEvent->getController()));
$responseEvent = new ResponseEvent($this->getKernel(), $request, HttpKernelInterface::MASTER_REQUEST, \call_user_func($controllerEvent->getController()));
$listener->onKernelResponse($responseEvent);

$response = $responseEvent->getResponse();
Expand All @@ -194,7 +194,7 @@ public function testEtagNotModifiedResponse()
$request->headers->add(['If-None-Match' => sprintf('"%s"', hash('sha256', $entity->getId()))]);

$listener = new HttpCacheListener();
$controllerEvent = new FilterControllerEvent($this->getKernel(), function () {
$controllerEvent = new ControllerEvent($this->getKernel(), function () {
return new Response(500);
}, $request, null);

Expand All @@ -211,12 +211,12 @@ public function testEtagHeader()
$response = new Response();

$listener = new HttpCacheListener();
$controllerEvent = new FilterControllerEvent($this->getKernel(), function () {
$controllerEvent = new ControllerEvent($this->getKernel(), function () {
return new Response();
}, $request, null);
$listener->onKernelController($controllerEvent);

$responseEvent = new FilterResponseEvent($this->getKernel(), $request, HttpKernelInterface::MASTER_REQUEST, \call_user_func($controllerEvent->getController()));
$responseEvent = new ResponseEvent($this->getKernel(), $request, HttpKernelInterface::MASTER_REQUEST, \call_user_func($controllerEvent->getController()));
$listener->onKernelResponse($responseEvent);

$response = $responseEvent->getResponse();
Expand Down Expand Up @@ -246,7 +246,7 @@ public function testConfigurationDoesNotOverrideAlreadySetResponseHeaders()
$response->setVary(['foobaz']);

$listener = new HttpCacheListener();
$responseEvent = new FilterResponseEvent($this->getKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $response);
$responseEvent = new ResponseEvent($this->getKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $response);
$listener->onKernelResponse($responseEvent);

$this->assertEquals('"54321"', $response->getEtag());
Expand All @@ -267,19 +267,19 @@ private function createRequest(Cache $cache = null)
private function createEventMock(Request $request, Response $response)
{
$event = $this
->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
->getMockBuilder('Symfony\Component\HttpKernel\Event\ResponseEvent')
->disableOriginalConstructor()
->getMock();
$event
->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;

$event
->expects($this->any())
->method('getResponse')
->will($this->returnValue($response))
->willReturn($response)
;

return $event;
Expand Down
14 changes: 7 additions & 7 deletions Tests/EventListener/IsGrantedListenerTest.php
Expand Up @@ -16,7 +16,7 @@
use Sensio\Bundle\FrameworkExtraBundle\Request\ArgumentNameConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
Expand Down Expand Up @@ -51,7 +51,7 @@ public function testIsGrantedCalledCorrectly()
$authChecker->expects($this->exactly(2))
->method('isGranted')
->with('ROLE_ADMIN')
->will($this->returnValue(true));
->willReturn(true);

$listener = new IsGrantedListener($this->createArgumentNameConverter([]), $authChecker);
$isGranted = new IsGranted(['attributes' => 'ROLE_ADMIN']);
Expand All @@ -67,7 +67,7 @@ public function testIsGrantedSubjectFromArguments()
->method('isGranted')
// the subject => arg2name will eventually resolve to the 2nd argument, which has this value
->with('ROLE_ADMIN', 'arg2Value')
->will($this->returnValue(true));
->willReturn(true);

// create metadata for 2 named args for the controller
$listener = new IsGrantedListener($this->createArgumentNameConverter(['arg1Name' => 'arg1Value', 'arg2Name' => 'arg2Value']), $authChecker);
Expand Down Expand Up @@ -98,7 +98,7 @@ public function testAccessDeniedMessages(array $attributes, $subject, $expectedM
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
$authChecker->expects($this->any())
->method('isGranted')
->will($this->returnValue(false));
->willReturn(false);

// avoid the error of the subject not being found in the request attributes
$arguments = [];
Expand Down Expand Up @@ -138,7 +138,7 @@ public function testNotFoundHttpException()
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
$authChecker->expects($this->any())
->method('isGranted')
->will($this->returnValue(false));
->willReturn(false);

$listener = new IsGrantedListener($this->createArgumentNameConverter([]), $authChecker);
$listener->onKernelControllerArguments($event);
Expand All @@ -156,7 +156,7 @@ private function createRequest(IsGranted $isGranted = null)

private function createFilterControllerEvent(Request $request)
{
return new FilterControllerArgumentsEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), function () {
return new ControllerArgumentsEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), function () {
return new Response();
}, [], $request, null);
}
Expand All @@ -167,7 +167,7 @@ private function createArgumentNameConverter(array $arguments)

$nameConverter->expects($this->any())
->method('getControllerArguments')
->will($this->returnValue($arguments));
->willReturn($arguments);

return $nameConverter;
}
Expand Down