10000 [TwigBundle] Deprecate the public "twig" service to private · symfony/symfony@1490baa · GitHub
[go: up one dir, main page]

Skip to content

Commit 1490baa

Browse files
committed
[TwigBundle] Deprecate the public "twig" service to private
1 parent 4d477ec commit 1490baa

File tree

12 files changed

+114
-15
lines changed

12 files changed

+114
-15
lines changed

UPGRADE-5.2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
UPGRADE FROM 5.1 to 5.2
22
=======================
33

4+
5+
TwigBundle
6+
----------
7+
8+
* Deprecated the public `twig` service to private.
9+
410
Validator
511
---------
612

UPGRADE-6.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Security
115115
* Removed `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
116116
* Added a `logout(Request $request, Response $response, TokenInterface $token)` method to the `RememberMeServicesInterface`.
117117

118+
TwigBundle
119+
----------
120+
121+
* The `twig` service is now private.
122+
118123
Validator
119124
---------
120125

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testBundlePublicDir()
4040
public function testBundleTwigTemplatesDir()
4141
{
4242
static::bootKernel(['test_case' => 'BundlePaths']);
43-
$twig = static::$container->get('twig');
43+
$twig = static::$container->get('twig.alias');
4444
$bundlesMetadata = static::$container->getParameter('kernel.bundles_metadata');
4545

4646
$this->assertSame([$bundlesMetadata['LegacyBundle']['path'].'/Resources/views'], $twig->getLoader()->getPaths('Legacy'));

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/BundlePaths/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ framework:
88

99
twig:
1010
strict_variables: '%kernel.debug%'
11+
12+
services:
13+
twig.alias:
14+
alias: twig
15+
public: true

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Controller/LoginController.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Controller;
1313

14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
14+
use Psr\Container\ContainerInterface;
15+
use Symfony\Component\Form\FormFactoryInterface;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
18+
use Symfony\Contracts\Service\ServiceSubscriberInterface;
19+
use Twig\Environment;
1820

19-
class LoginController implements ContainerAwareInterface
21+
class LoginController implements ServiceSubscriberInterface
2022
{
21-
use ContainerAwareTrait;
23+
private $container;
24+
25+
public function __construct(ContainerInterface $container)
26+
{
27+
$this->container = $container;
28+
}
2229

2330
public function loginAction()
2431
{
@@ -43,4 +50,15 @@ public function secureAction()
4350
{
4451
throw new \Exception('Wrapper', 0, new \Exception('Another Wrapper', 0, new AccessDeniedException()));
4552
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public static function getSubscribedServices()
58+
{
59+
return [
60+
'form.factory' => FormFactoryInterface::class,
61+
'twig' => Environment::class,
62+
];
63+
}
4664
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LocalizedController.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
1313

14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
14+
use Psr\Container\ContainerInterface;
1615
use Symfony\Component\HttpFoundation\Request;
1716
use Symfony\Component\HttpFoundation\Response;
1817
use Symfony\Component\Security\Core\Security;
18+
use Symfony\Contracts\Service\ServiceSubscriberInterface;
19+
use Twig\Environment;
1920

20-
class LocalizedController implements ContainerAwareInterface
21+
class LocalizedController implements ServiceSubscriberInterface
2122
{
22-
use ContainerAwareTrait;
23+
private $container;
24+
25+
public function __construct(ContainerInterface $container)
26+
{
27+
$this->container = $container;
28+
}
2329

2430
public function loginAction(Request $request)
2531
{
@@ -61,4 +67,14 @@ public function homepageAction()
6167
{
6268
return (new Response('<html><body>Homepage</body></html>'))->setPublic();
6369
}
70+
71+
/**
72+
* {@inheritdoc}
73+
*/
74+
public static function getSubscribedServices()
75+
{
76+
return [
77+
'twig' => Environment::class,
78+
];
79+
}
6480
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LoginController.php

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

1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
1313

14-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
14+
use Psr\Container\ContainerInterface;
1615
use Symfony\Component\HttpFoundation\Request;
1716
use Symfony\Component\HttpFoundation\Response;
1817
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1918
use Symfony\Component\Security\Core\Security;
2019
use Symfony\Component\Security\Core\User\UserInterface;
20+
use Symfony\Contracts\Service\ServiceSubscriberInterface;
21+
use Twig\Environment;
2122

22-
class LoginController implements ContainerAwareInterface
23+
class LoginController implements ServiceSubscriberInterface
2324
{
24-
use ContainerAwareTrait;
25+
private $container;
26+
27+
public function __construct(ContainerInterface $container)
28+
{
29+
$this->container = $container;
30+
}
2531

2632
public function loginAction(Request $request, UserInterface $user = null)
2733
{
@@ -53,4 +59,14 @@ public function secureAction()
5359
{
5460
throw new \Exception('Wrapper', 0, new \Exception('Another Wrapper', 0, new AccessDeniedException()));
5561
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public static function getSubscribedServices()
67+
{
68+
return [
69+
'twig' => Environment::class,
70+
];
71+
}
5672
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/FormLoginBundle.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,28 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle;
1313

14+
use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller\LocalizedController;
15+
use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller\LoginController;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1417
use Symfony\Component\HttpKernel\Bundle\Bundle;
1518

1619
class FormLoginBundle extends Bundle
1720
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function build(ContainerBuilder $container)
25+
{
26+
parent::build($container);
27+
28+
$container
29+
->register(LoginController::class)
30+
->setPublic(true)
31+
->addTag('container.service_subscriber');
32+
33+
$container
34+
->register(LocalizedController::class)
35+
->setPublic(true)
36+
->addTag('container.service_subscriber');
37+
}
1838
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ services:
99
tags:
1010
- { name: form.type }
1111

12+
Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Controller\LoginController:
13+
public: true
14+
tags:
15+
- { name: container.service_subscriber }
16+
1217
security:
1318
encoders:
1419
Symfony\Component\Security\Core\User\User: plaintext

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+
5.2.0
5+
-----
6+
7+
* deprecated the public `twig` service to private
8+
49
5.0.0
510
-----
611

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<tag name="container.preload" class="Twig\ExtensionSet" />
2727
<tag name="container.preload" class="Twig\Template" />
2828
<tag name="container.preload" class="Twig\TemplateWrapper" />
29+
<tag name="container.private" package="symfony/twig-bundle" version="5.2" />
2930
</service>
3031
<service id="Twig_Environment" alias="twig" />
3132
<service id="Twig\Environment" alias="twig" />

src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\TwigBundle\Tests\TestCase;
1616
use Symfony\Bundle\TwigBundle\TwigBundle;
1717
use Symfony\Component\Config\Loader\LoaderInterface;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\Filesystem\Filesystem;
1920
use Symfony\Component\HttpKernel\Kernel;
2021

@@ -26,7 +27,7 @@ public function test()
2627
$kernel->boot();
2728

2829
$container = $kernel->getContainer();
29-
$content = $container->get('twig')->render('index.html.twig');
30+
$content = $container->get('twig.alias')->render('index.html.twig');
3031
$this->assertStringContainsString('{ a: b }', $content);
3132
}
3233

@@ -60,7 +61,7 @@ public function registerBundles(): iterable
6061

6162
public function registerContainerConfiguration(LoaderInterface $loader)
6263
{
63-
$loader->load(function ($container) {
64+
$loader->load(function (ContainerBuilder $container) {
6465
$container
6566
->loadFromExtension('framework', [
6667
'secret' => '$ecret',
@@ -69,6 +70,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
6970
->loadFromExtension('twig', [
7071
'default_path' => __DIR__.'/templates',
7172
])
73+
->setAlias('twig.alias', 'twig')->setPublic(true)
7274
;
7375
});
7476
}

0 commit comments

Comments
 (0)
0