Skip to content

Commit 7d0e148

Browse files
[Bridge\Doctrine][FrameworkBundle] Remove legacy uses of ContainerAwareInterface
1 parent bf175ee commit 7d0e148

File tree

5 files changed

+4
-156
lines changed

5 files changed

+4
-156
lines changed

Controller/ControllerResolver.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ protected function instantiateController($class)
6565
private function configureController($controller)
6666
{
6767
if ($controller instanceof ContainerAwareInterface) {
68-
// @deprecated switch, to be removed in 4.0 where these classes
69-
// won't implement ContainerAwareInterface anymore
70-
switch (\get_class($controller)) {
71-
case RedirectController::class:
72-
case TemplateController::class:
73-
return $controller;
74-
}
7568
$controller->setContainer($this->container);
7669
}
7770
if ($controller instanceof AbstractController && null !== $previousContainer = $controller->setContainer($this->container)) {

Controller/RedirectController.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Controller;
1313

14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15-
use Symfony\Component\DependencyInjection\ContainerInterface;
1614
use Symfony\Component\HttpFoundation\RedirectResponse;
1715
use Symfony\Component\HttpFoundation\Request;
1816
use Symfony\Component\HttpFoundation\Response;
@@ -26,13 +24,8 @@
2624
*
2725
* @final since version 3.4
2826
*/
29-
class RedirectController implements ContainerAwareInterface
27+
class RedirectController
3028
{
31-
/**
32-
* @deprecated since version 3.4, to be removed in 4.0
33-
*/
34-
protected $container;
35-
3629
private $router;
3730
private $httpPort;
3831
private $httpsPort;
@@ -44,17 +37,6 @@ public function __construct(UrlGeneratorInterface $router = null, $httpPort = nu
4437
$this->httpsPort = $httpsPort;
4538
}
4639

47-
/**
48-
* @deprecated since version 3.4, to be removed in 4.0 alongside with the ContainerAwareInterface type.
49-
*/
50-
public function setContainer(ContainerInterface $container = null)
51-
{
52-
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.4 and will be removed in 4.0. Inject an UrlGeneratorInterface using the constructor instead.', __METHOD__), E_USER_DEPRECATED);
53-
54-
$this->container = $container;
55-
$this->router = $container->get('router');
56-
}
57-
5840
/**
5941
* Redirects to another route with the given name.
6042
*
@@ -104,8 +86,8 @@ public function redirectAction(Request $request, $route, $permanent = false, $ig
10486
* @param string $path The absolute path or URL to redirect to
10587
* @param bool $permanent Whether the redirect is permanent or not
10688
* @param string|null $scheme The URL scheme (null to keep the current one)
107-
* @param int|null $httpPort The HTTP port (null to keep the current one for the same scheme or the configured port in the container)
108-
* @param int|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the configured port in the container)
89+
* @param int|null $httpPort The HTTP port (null to keep the current one for the same scheme or the default configured port)
90+
* @param int|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the default configured port)
10991
*
11092
* @return Response A Response instance
11193
*
@@ -142,9 +124,6 @@ public function urlRedirectAction(Request $request, $path, $permanent = false, $
142124
if (null === $httpPort) {
143125
if ('http' === $request->getScheme()) {
144126
$httpPort = $request->getPort();
145-
} elseif ($this->container && $this->container->hasParameter('request_listener.http_port')) {
146-
@trigger_error(sprintf('Passing the http port as a container parameter is deprecated since Symfony 3.4 and won\'t be possible in 4.0. Pass it to the constructor of the "%s" class instead.', __CLASS__), E_USER_DEPRECATED);
147-
$httpPort = $this->container->getParameter('request_listener.http_port');
148127
} else {
149128
$httpPort = $this->httpPort;
150129
}
@@ -157,9 +136,6 @@ public function urlRedirectAction(Request $request, $path, $permanent = false, $
157136
if (null === $httpsPort) {
158137
if ('https' === $request->getScheme()) {
159138
$httpsPort = $request->getPort();
160-
} elseif ($this->container && $this->container->hasParameter('request_listener.https_port')) {
161-
@trigger_error(sprintf('Passing the https port as a container parameter is deprecated since Symfony 3.4 and won\'t be possible in 4.0. Pass it to the constructor of the "%s" class instead.', __CLASS__), E_USER_DEPRECATED);
162-
$httpsPort = $this->container->getParameter('request_listener.https_port');
163139
} else {
164140
$httpsPort = $this->httpsPort;
165141
}

Controller/TemplateController.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Controller;
1313

14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15-
use Symfony\Component\DependencyInjection\ContainerInterface;
1614
use Symfony\Component\HttpFoundation\Response;
1715
use Symfony\Component\Templating\EngineInterface;
1816
use Twig\Environment;
@@ -24,13 +22,8 @@
2422
*
2523
* @final since version 3.4
2624
*/
27-
class TemplateController implements ContainerAwareInterface
25+
class TemplateController
2826
{
29-
/**
30-
* @deprecated since version 3.4, to be removed in 4.0
31-
*/
32-
protected $container;
33-
3427
private $twig;
3528
private $templating;
3629

@@ -40,21 +33,6 @@ public function __construct(Environment $twig = null, EngineInterface $templatin
4033
$this->templating = $templating;
4134
}
4235

43-
/**
44-
* @deprecated since version 3.4, to be removed in 4.0 alongside with the ContainerAwareInterface type.
45-
*/
46-
public function setContainer(ContainerInterface $container = null)
47-
{
48-
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.4 and will be removed in 4.0. Inject a Twig Environment or an EngineInterface using the constructor instead.', __METHOD__), E_USER_DEPRECATED);
49-
50-
if ($container->has('templating')) {
51-
$this->templating = $container->get('templating');
52-
} elseif ($container->has('twig')) {
53-
$this->twig = $container->get('twig');
54-
}
55-
$this->container = $container;
56-
}
57-
5836
/**
5937
* Renders a template.
6038
*

Tests/Controller/RedirectControllerTest.php

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,6 @@ public function testUrlRedirectDefaultPorts()
143143
$this->assertRedirectUrl($returnValue, $expectedUrl);
144144
}
145145

146-
/**
147-
* @group legacy
148-
*/
149-
public function testUrlRedirectDefaultPortParameters()
150-
{
151-
$host = 'www.example.com';
152-
$baseUrl = '/base';
153-
$path = '/redirect-path';
154-
$httpPort = 1080;
155-
$httpsPort = 1443;
156-
157-
$expectedUrl = "https://$host:$httpsPort$baseUrl$path";
158-
$request = $this->createRequestObject('http', $host, $httpPort, $baseUrl);
159-
$controller = $this->createLegacyRedirectController(null, $httpsPort);
160-
$returnValue = $controller->urlRedirectAction($request, $path, false, 'https');
161-
$this->assertRedirectUrl($returnValue, $expectedUrl);
162-
163-
$expectedUrl = "http://$host:$httpPort$baseUrl$path";
164-
$request = $this->createRequestObject('https', $host, $httpPort, $baseUrl);
165-
$controller = $this->createLegacyRedirectController($httpPort);
166-
$returnValue = $controller->urlRedirectAction($request, $path, false, 'http');
167-
$this->assertRedirectUrl($returnValue, $expectedUrl);
168-
}
169-
170146
public function urlRedirectProvider()
171147
{
172148
return array(
@@ -276,44 +252,6 @@ private function createRedirectController($httpPort = null, $httpsPort = null)
276252
return new RedirectController(null, $httpPort, $httpsPort);
277253
}
278254

279-
/**
280-
* @deprecated
281-
*/
282-
private function createLegacyRedirectController($httpPort = null, $httpsPort = null)
283-
{
284-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
285-
286-
if (null !== $httpPort) {
287-
$container
288-
->expects($this->once())
289-
->method('hasParameter')
290-
->with($this->equalTo('request_listener.http_port'))
291-
->will($this->returnValue(true));
292-
$container
293-
->expects($this->once())
294-
->method('getParameter')
295-
->with($this->equalTo('request_listener.http_port'))
296-
->will($this->returnValue($httpPort));
297-
}
298-
if (null !== $httpsPort) {
299-
$container
300-
->expects($this->once())
301-
->method('hasParameter')
302-
->with($this->equalTo('request_listener.https_port'))
303-
->will($this->returnValue(true));
304-
$container
305-
->expects($this->once())
306-
->method('getParameter')
307-
->with($this->equalTo('request_listener.https_port'))
308-
->will($this->returnValue($httpsPort));
309-
}
310-
311-
$controller = new RedirectController();
312-
$controller->setContainer($container);
313-
314-
return $controller;
315-
}
316-
317255
public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
318256
{
319257
$this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));

Tests/Controller/TemplateControllerTest.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,6 @@ public function testTemplating()
4040
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
4141
}
4242

43-
/**
44-
* @group legacy
45-
*/
46-
public function testLegacyTwig()
47-
{
48-
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
49-
$twig->expects($this->once())->method('render')->willReturn('bar');
50-
51-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
52-
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
53-
$container->expects($this->at(1))->method('has')->will($this->returnValue(true));
54-
$container->expects($this->at(2))->method('get')->will($this->returnValue($twig));
55-
56-
$controller = new TemplateController();
57-
$controller->setContainer($container);
58-
59-
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
60-
}
61-
62-
/**
63-
* @group legacy
64-
*/
65-
public function testLegacyTemplating()
66-
{
67-
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
68-
$templating->expects($this->once())->method('render')->willReturn('bar');
69-
70-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
71-
$container->expects($this->at(0))->method('has')->willReturn(true);
72-
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
73-
74-
$controller = new TemplateController();
75-
$controller->setContainer($container);
76-
77-
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
78-
}
79-
8043
/**
8144
* @expectedException \LogicException
8245
* @expectedExceptionMessage You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.

0 commit comments

Comments
 (0)