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

Skip to content

Commit c278d09

Browse files
committed
[TwigBundle] Deprecate the public "twig" service to private
1 parent fb123e4 commit c278d09

File tree

12 files changed

+113
-15
lines changed

12 files changed

+113
-15
lines changed

UPGRADE-5.2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Mime
1111

1212
* Deprecated `Address::fromString()`, use `Address::create()` instead
1313

14+
TwigBundle
15+
----------
16+
17+
* Deprecated the public `twig` service to private.
18+
1419
Validator
1520
---------
1621

UPGRADE-6.0.md

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

124+
TwigBundle
125+
----------
126+
127+
* The `twig` service is now private.
128+
124129
Validator
125130
---------
126131

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
@@ -1,6 +1,11 @@
11
imports:
22
- { resource: ./base_config.yml }
33

4+
Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Controller\LoginController:
5+
public: true
6+
tags:
7+
- { name: container.service_subscriber }
8+
49
security:
510
firewalls:
611
default:

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.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
->tag('container.preload', ['class' => ExtensionSet::class])
6464
->tag('container.preload', ['class' => Template::class])
6565
->tag('container.preload', ['class' => TemplateWrapper::class])
66+
->tag('container.private', ['package' => 'symfony/twig-bundle', 'version' => '5.2'])
6667

6768
->alias('Twig_Environment', 'twig')
6869
->alias(Environment::class, '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