feature #36739 [TwigBundle] Deprecate the public "twig" service to private (fancyweb)
This PR was merged into the 5.2-dev branch.
Discussion
----------
[TwigBundle] Deprecate the public "twig" service to private
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| Deprecations? | yes
| Tickets | -
| License | MIT
| Doc PR | -
I think the `twig` service don't need to be public anymore - we never need to access it directly in Symfony's code.
Commits
-------
f64cbada89
[TwigBundle] Deprecate the public "twig" service to private
This commit is contained in:
commit
ce7e39b7bd
@ -11,6 +11,11 @@ Mime
|
||||
|
||||
* Deprecated `Address::fromString()`, use `Address::create()` instead
|
||||
|
||||
TwigBundle
|
||||
----------
|
||||
|
||||
* Deprecated the public `twig` service to private.
|
||||
|
||||
Validator
|
||||
---------
|
||||
|
||||
|
@ -121,6 +121,11 @@ Security
|
||||
* Removed `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
|
||||
* Added a `logout(Request $request, Response $response, TokenInterface $token)` method to the `RememberMeServicesInterface`.
|
||||
|
||||
TwigBundle
|
||||
----------
|
||||
|
||||
* The `twig` service is now private.
|
||||
|
||||
Validator
|
||||
---------
|
||||
|
||||
|
@ -40,7 +40,7 @@ class BundlePathsTest extends AbstractWebTestCase
|
||||
public function testBundleTwigTemplatesDir()
|
||||
{
|
||||
static::bootKernel(['test_case' => 'BundlePaths']);
|
||||
$twig = static::$container->get('twig');
|
||||
$twig = static::$container->get('twig.alias');
|
||||
$bundlesMetadata = static::$container->getParameter('kernel.bundles_metadata');
|
||||
|
||||
$this->assertSame([$bundlesMetadata['LegacyBundle']['path'].'/Resources/views'], $twig->getLoader()->getPaths('Legacy'));
|
||||
|
@ -8,3 +8,8 @@ framework:
|
||||
|
||||
twig:
|
||||
strict_variables: '%kernel.debug%'
|
||||
|
||||
services:
|
||||
twig.alias:
|
||||
alias: twig
|
||||
public: true
|
||||
|
@ -11,14 +11,21 @@
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
class LoginController implements ContainerAwareInterface
|
||||
class LoginController implements ServiceSubscriberInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function loginAction()
|
||||
{
|
||||
@ -43,4 +50,15 @@ class LoginController implements ContainerAwareInterface
|
||||
{
|
||||
throw new \Exception('Wrapper', 0, new \Exception('Another Wrapper', 0, new AccessDeniedException()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return [
|
||||
'form.factory' => FormFactoryInterface::class,
|
||||
'twig' => Environment::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -11,15 +11,21 @@
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
class LocalizedController implements ContainerAwareInterface
|
||||
class LocalizedController implements ServiceSubscriberInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function loginAction(Request $request)
|
||||
{
|
||||
@ -61,4 +67,14 @@ class LocalizedController implements ContainerAwareInterface
|
||||
{
|
||||
return (new Response('<html><body>Homepage</body></html>'))->setPublic();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return [
|
||||
'twig' => Environment::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,23 @@
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
class LoginController implements ContainerAwareInterface
|
||||
class LoginController implements ServiceSubscriberInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function loginAction(Request $request, UserInterface $user = null)
|
||||
{
|
||||
@ -53,4 +59,14 @@ class LoginController implements ContainerAwareInterface
|
||||
{
|
||||
throw new \Exception('Wrapper', 0, new \Exception('Another Wrapper', 0, new AccessDeniedException()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return [
|
||||
'twig' => Environment::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,28 @@
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller\LocalizedController;
|
||||
use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller\LoginController;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class FormLoginBundle extends Bundle
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
parent::build($container);
|
||||
|
||||
$container
|
||||
->register(LoginController::class)
|
||||
->setPublic(true)
|
||||
->addTag('container.service_subscriber');
|
||||
|
||||
$container
|
||||
->register(LocalizedController::class)
|
||||
->setPublic(true)
|
||||
->addTag('container.service_subscriber');
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,11 @@ services:
|
||||
tags:
|
||||
- { name: form.type }
|
||||
|
||||
Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Controller\LoginController:
|
||||
public: true
|
||||
tags:
|
||||
- { name: container.service_subscriber }
|
||||
|
||||
security:
|
||||
encoders:
|
||||
Symfony\Component\Security\Core\User\User: plaintext
|
||||
|
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
5.2.0
|
||||
-----
|
||||
|
||||
* deprecated the public `twig` service to private
|
||||
|
||||
5.0.0
|
||||
-----
|
||||
|
||||
|
@ -63,6 +63,7 @@ return static function (ContainerConfigurator $container) {
|
||||
->tag('container.preload', ['class' => ExtensionSet::class])
|
||||
->tag('container.preload', ['class' => Template::class])
|
||||
->tag('container.preload', ['class' => TemplateWrapper::class])
|
||||
->tag('container.private', ['package' => 'symfony/twig-bundle', 'version' => '5.2'])
|
||||
|
||||
->alias('Twig_Environment', 'twig')
|
||||
->alias(Environment::class, 'twig')
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
||||
use Symfony\Bundle\TwigBundle\TwigBundle;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
@ -26,7 +27,7 @@ class NoTemplatingEntryTest extends TestCase
|
||||
$kernel->boot();
|
||||
|
||||
$container = $kernel->getContainer();
|
||||
$content = $container->get('twig')->render('index.html.twig');
|
||||
$content = $container->get('twig.alias')->render('index.html.twig');
|
||||
$this->assertStringContainsString('{ a: b }', $content);
|
||||
}
|
||||
|
||||
@ -60,7 +61,7 @@ class NoTemplatingEntryKernel extends Kernel
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
$loader->load(function ($container) {
|
||||
$loader->load(function (ContainerBuilder $container) {
|
||||
$container
|
||||
->loadFromExtension('framework', [
|
||||
'secret' => '$ecret',
|
||||
@ -69,6 +70,7 @@ class NoTemplatingEntryKernel extends Kernel
|
||||
->loadFromExtension('twig', [
|
||||
'default_path' => __DIR__.'/templates',
|
||||
])
|
||||
->setAlias('twig.alias', 'twig')->setPublic(true)
|
||||
;
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user