mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -11,11 +11,14 @@
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\Asset\Packages;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
||||
@@ -24,40 +27,44 @@ class ExtensionPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Asset\Packages')) {
|
||||
if (!class_exists(Packages::class)) {
|
||||
$container->removeDefinition('twig.extension.assets');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\ExpressionLanguage\Expression')) {
|
||||
if (!class_exists(Expression::class)) {
|
||||
$container->removeDefinition('twig.extension.expression');
|
||||
}
|
||||
|
||||
if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
|
||||
if (!interface_exists(UrlGeneratorInterface::class)) {
|
||||
$container->removeDefinition('twig.extension.routing');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
|
||||
if (!class_exists(Yaml::class)) {
|
||||
$container->removeDefinition('twig.extension.yaml');
|
||||
}
|
||||
|
||||
$viewDir = \dirname((new \ReflectionClass(\Symfony\Bridge\Twig\Extension\FormExtension::class))->getFileName(), 2).'/Resources/views';
|
||||
$templateIterator = $container->getDefinition('twig.template_iterator');
|
||||
$templatePaths = $templateIterator->getArgument(1);
|
||||
$loader = $container->getDefinition('twig.loader.native_filesystem');
|
||||
|
||||
if ($container->has('mailer')) {
|
||||
$emailPath = $viewDir.'/Email';
|
||||
$loader->addMethodCall('addPath', [$emailPath, 'email']);
|
||||
$loader->addMethodCall('addPath', [$emailPath, '!email']);
|
||||
$templatePaths[$emailPath] = 'email';
|
||||
}
|
||||
|
||||
if ($container->has('form.extension')) {
|
||||
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
|
||||
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
|
||||
|
||||
$coreThemePath = \dirname(\dirname($reflClass->getFileName())).'/Resources/views/Form';
|
||||
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', [$coreThemePath]);
|
||||
|
||||
$paths = $container->getDefinition('twig.template_iterator')->getArgument(2);
|
||||
$paths[$coreThemePath] = null;
|
||||
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $paths);
|
||||
|
||||
if ($container->hasDefinition('twig.cache_warmer')) {
|
||||
$paths = $container->getDefinition('twig.cache_warmer')->getArgument(2);
|
||||
$paths[$coreThemePath] = null;
|
||||
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $paths);
|
||||
}
|
||||
$coreThemePath = $viewDir.'/Form';
|
||||
$loader->addMethodCall('addPath', [$coreThemePath]);
|
||||
$templatePaths[$coreThemePath] = null;
|
||||
}
|
||||
|
||||
$templateIterator->replaceArgument(1, $templatePaths);
|
||||
|
||||
if ($container->has('router')) {
|
||||
$container->getDefinition('twig.extension.routing')->addTag('twig.extension');
|
||||
}
|
||||
@@ -66,19 +73,13 @@ class ExtensionPass implements CompilerPassInterface
|
||||
$container->getDefinition('twig.extension.httpkernel')->addTag('twig.extension');
|
||||
$container->getDefinition('twig.runtime.httpkernel')->addTag('twig.runtime');
|
||||
|
||||
// inject Twig in the hinclude service if Twig is the only registered templating engine
|
||||
if ((!$container->hasParameter('templating.engines') || ['twig'] == $container->getParameter('templating.engines')) && $container->hasDefinition('fragment.renderer.hinclude')) {
|
||||
if ($container->hasDefinition('fragment.renderer.hinclude')) {
|
||||
$container->getDefinition('fragment.renderer.hinclude')
|
||||
->addTag('kernel.fragment_renderer', ['alias' => 'hinclude'])
|
||||
->replaceArgument(0, new Reference('twig'))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$container->has('http_kernel')) {
|
||||
$container->removeDefinition('twig.controller.preview_error');
|
||||
}
|
||||
|
||||
if ($container->has('request_stack')) {
|
||||
$container->getDefinition('twig.extension.httpfoundation')->addTag('twig.extension');
|
||||
}
|
||||
@@ -96,16 +97,7 @@ class ExtensionPass implements CompilerPassInterface
|
||||
$container->getDefinition('twig.extension.weblink')->addTag('twig.extension');
|
||||
}
|
||||
|
||||
$twigLoader = $container->getDefinition('twig.loader.native_filesystem');
|
||||
if ($container->has('templating')) {
|
||||
$loader = $container->getDefinition('twig.loader.filesystem');
|
||||
$loader->setMethodCalls(array_merge($twigLoader->getMethodCalls(), $loader->getMethodCalls()));
|
||||
|
||||
$twigLoader->clearTag('twig.loader');
|
||||
} else {
|
||||
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
|
||||
$container->removeDefinition('templating.engine.twig');
|
||||
}
|
||||
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
|
||||
|
||||
if ($container->has('assets.packages')) {
|
||||
$container->getDefinition('twig.extension.assets')->addTag('twig.extension');
|
||||
@@ -115,7 +107,7 @@ class ExtensionPass implements CompilerPassInterface
|
||||
$container->getDefinition('twig.extension.yaml')->addTag('twig.extension');
|
||||
}
|
||||
|
||||
if (class_exists('Symfony\Component\Stopwatch\Stopwatch')) {
|
||||
if (class_exists(\Symfony\Component\Stopwatch\Stopwatch::class)) {
|
||||
$container->getDefinition('twig.extension.debug.stopwatch')->addTag('twig.extension');
|
||||
}
|
||||
|
||||
@@ -128,5 +120,10 @@ class ExtensionPass implements CompilerPassInterface
|
||||
} else {
|
||||
$container->getDefinition('workflow.twig_extension')->addTag('twig.extension');
|
||||
}
|
||||
|
||||
if ($container->has('serializer')) {
|
||||
$container->getDefinition('twig.runtime.serializer')->addTag('twig.runtime');
|
||||
$container->getDefinition('twig.extension.serializer')->addTag('twig.extension');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user