Skip to content

Commit ce55cd6

Browse files
committed
Replace some container injections by service locators
1 parent 0be9ea8 commit ce55cd6

File tree

21 files changed

+201
-67
lines changed

21 files changed

+201
-67
lines changed

UPGRADE-3.3.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,22 @@ FrameworkBundle
7171
deprecated and will be removed in 4.0. Use the `Symfony\Component\Form\DependencyInjection\FormPass`
7272
class instead.
7373

74+
* The `Symfony\Bundle\FrameworkBundle\EventListener\SessionListener` class has been
75+
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpKernel\EventListener\RequestSessionListener`
76+
class instead.
77+
78+
* The `Symfony\Bundle\FrameworkBundle\EventListener\TestSessionListener` class has been
79+
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpKernel\EventListener\TestRequestSessionListener`
80+
class instead.
81+
7482
HttpKernel
7583
-----------
7684

7785
* The `Psr6CacheClearer::addPool()` method has been deprecated. Pass an array of pools indexed
7886
by name to the constructor instead.
87+
88+
* The `LazyLoadingFragmentHandler::addRendererService()` method has been deprecated and
89+
will be removed in 4.0.
7990

8091
Process
8192
-------
@@ -127,6 +138,12 @@ TwigBridge
127138
* The `TwigRendererEngine::setEnvironment()` method has been deprecated and will be removed
128139
in 4.0. Pass the Twig Environment as second argument of the constructor instead.
129140

141+
TwigBundle
142+
----------
143+
144+
* The `ContainerAwareRuntimeLoader` class has been deprecated and will be removed in 4.0.
145+
Use the Twig `Twig_ContainerRuntimeLoader` class instead.
146+
130147
Workflow
131148
--------
132149

UPGRADE-4.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ HttpKernel
229229

230230
* The `Psr6CacheClearer::addPool()` method has been removed. Pass an array of pools indexed
231231
by name to the constructor instead.
232+
233+
* The `LazyLoadingFragmentHandler::addRendererService()` method has been removed.
234+
232235

233236
Ldap
234237
----
@@ -285,6 +288,12 @@ Translation
285288

286289
* Removed the backup feature from the file dumper classes.
287290

291+
TwigBundle
292+
----------
293+
294+
* The `ContainerAwareRuntimeLoader` class has been removed. Use the
295+
Twig `Twig_ContainerRuntimeLoader` class instead.
296+
288297
TwigBridge
289298
----------
290299

src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,17 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\EventListener;
1313

14-
use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;
15-
use Symfony\Component\DependencyInjection\ContainerInterface;
14+
use Symfony\Component\HttpKernel\EventListener\RequestSessionListener;
15+
16+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', SessionListener::class, RequestSessionListener::class), E_USER_DEPRECATED);
1617

1718
/**
1819
* Sets the session in the request.
1920
*
2021
* @author Fabien Potencier <fabien@symfony.com>
22+
*
23+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link RequestSessionListener} instead
2124
*/
22-
class SessionListener extends BaseSessionListener
25+
class SessionListener extends RequestSessionListener
2326
{
24-
/**
25-
* @var ContainerInterface
26-
*/
27-
private $container;
28-
29-
public function __construct(ContainerInterface $container)
30-
{
31-
$this->container = $container;
32-
}
33-
34-
protected function getSession()
35-
{
36-
if (!$this->container->has('session')) {
37-
return;
38-
}
39-
40-
return $this->container->get('session');
41-
}
4227
}

src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\EventListener;
1313

14-
use Symfony\Component\HttpKernel\EventListener\TestSessionListener as BaseTestSessionListener;
14+
use Symfony\Component\HttpKernel\EventListener\TestRequestSessionListener;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616

17+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use %s instead.', TestSessionListener::class, TestRequestSessionListener::class), E_USER_DEPRECATED);
18+
1719
/**
1820
* TestSessionListener.
1921
*
2022
* @author Fabien Potencier <fabien@symfony.com>
23+
*
24+
* @deprecated since version 3.3, to be removed in 4.0.
2125
*/
22-
class TestSessionListener extends BaseTestSessionListener
26+
class TestSessionListener extends TestRequestSessionListener
2327
{
2428
protected $container;
2529

src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<services>
1313
<service id="fragment.handler" class="Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler">
14-
<argument type="service" id="service_container" />
14+
<argument /> <!-- fragment renderer locator -->
1515
<argument type="service" id="request_stack" />
1616
<argument>%kernel.debug%</argument>
1717
</service>

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747

4848
<service id="session.handler.write_check" class="Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler" public="false" />
4949

50-
<service id="session_listener" class="Symfony\Bundle\FrameworkBundle\EventListener\SessionListener">
50+
<service id="session_listener" class="Symfony\Component\HttpKernel\EventListener\RequestSessionListener">
5151
<tag name="kernel.event_subscriber" />
52-
<argument type="service" id="service_container" />
52+
<argument type="service-locator">
53+
<argument key="session" type="service" id="session" on-invalid="null" />
54+
</argument>
5355
</service>
5456

5557
<service id="session.save_listener" class="Symfony\Component\HttpKernel\EventListener\SaveSessionListener">

src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020

2121
<service id="test.client.cookiejar" class="Symfony\Component\BrowserKit\CookieJar" shared="false" />
2222

23-
<service id="test.session.listener" class="Symfony\Bundle\FrameworkBundle\EventListener\TestSessionListener">
24-
<argument type="service" id="service_container" />
23+
<service id="test.session.listener" class="Symfony\Component\HttpKernel\EventListener\TestRequestSessionListener">
2524
<tag name="kernel.event_subscriber" />
25+
<argument type="service-locator">
26+
<argument key="session" type="service" id="session" on-invalid="null" />
27+
</argument>
2628
</service>
2729
</services>
2830
</container>

src/Symfony/Bundle/TwigBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* Deprecated `ContainerAwareRuntimeLoader`
8+
49
2.7.0
510
-----
611

src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
namespace Symfony\Bundle\TwigBundle;
1313

14+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig_ContainerRuntimeLoader class instead.'), ContainerAwareRuntimeLoader::class);
15+
1416
use Psr\Log\LoggerInterface;
1517
use Symfony\Component\DependencyInjection\ContainerInterface;
1618

1719
/**
1820
* Loads Twig extension runtimes via the service container.
1921
*
2022
* @author Fabien Potencier <fabien@symfony.com>
23+
*
24+
* @deprecated since version 3.3, will be removed in 4.0. Use \Twig_ContainerRuntimeLoader instead.
2125
*/
2226
class ContainerAwareRuntimeLoader implements \Twig_RuntimeLoaderInterface
2327
{

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/RuntimeLoaderPass.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1415
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
17+
use Symfony\Component\DependencyInjection\Reference;
1718

1819
/**
1920
* Registers Twig runtime services.
@@ -29,19 +30,9 @@ public function process(ContainerBuilder $container)
2930
$definition = $container->getDefinition('twig.runtime_loader');
3031
$mapping = array();
3132
foreach ($container->findTaggedServiceIds('twig.runtime') as $id => $attributes) {
32-
$def = $container->getDefinition($id);
33-
34-
if (!$def->isPublic()) {
35-
throw new InvalidArgumentException(sprintf('The service "%s" must be public as it can be lazy-loaded.', $id));
36-
}
37-
38-
if ($def->isAbstract()) {
39-
throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as it can be lazy-loaded.', $id));
40-
}
41-
42-
$mapping[$def->getClass()] = $id;
33+
$mapping[$container->getDefinition($id)->getClass()] = new Reference($id);
4334
}
4435

45-
$definition->replaceArgument(1, $mapping);
36+
$definition->replaceArgument(0, new ServiceLocatorArgument($mapping));
4637
}
4738
}

0 commit comments

Comments
 (0)