mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-21 16:22:20 +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:
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Registers the Twig exception listener if Twig is registered as a templating engine.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ExceptionListenerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (false === $container->hasDefinition('twig')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// register the exception controller only if Twig is enabled and required dependencies do exist
|
||||
if (!class_exists('Symfony\Component\Debug\Exception\FlattenException') || !interface_exists('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
|
||||
$container->removeDefinition('twig.exception_listener');
|
||||
} elseif ($container->hasParameter('templating.engines')) {
|
||||
$engines = $container->getParameter('templating.engines');
|
||||
if (!\in_array('twig', $engines)) {
|
||||
$container->removeDefinition('twig.exception_listener');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Adds tagged twig.extension services to twig service.
|
||||
@@ -22,6 +22,8 @@ use Symfony\Component\DependencyInjection\Reference;
|
||||
*/
|
||||
class TwigEnvironmentPass implements CompilerPassInterface
|
||||
{
|
||||
use PriorityTaggedServiceTrait;
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (false === $container->hasDefinition('twig')) {
|
||||
@@ -37,11 +39,11 @@ class TwigEnvironmentPass implements CompilerPassInterface
|
||||
$currentMethodCalls = $definition->getMethodCalls();
|
||||
$twigBridgeExtensionsMethodCalls = [];
|
||||
$othersExtensionsMethodCalls = [];
|
||||
foreach ($container->findTaggedServiceIds('twig.extension', true) as $id => $attributes) {
|
||||
$methodCall = ['addExtension', [new Reference($id)]];
|
||||
$extensionClass = $container->getDefinition($id)->getClass();
|
||||
foreach ($this->findAndSortTaggedServices('twig.extension', $container) as $extension) {
|
||||
$methodCall = ['addExtension', [$extension]];
|
||||
$extensionClass = $container->getDefinition((string) $extension)->getClass();
|
||||
|
||||
if (\is_string($extensionClass) && 0 === strpos($extensionClass, 'Symfony\Bridge\Twig\Extension')) {
|
||||
if (\is_string($extensionClass) && str_starts_with($extensionClass, 'Symfony\Bridge\Twig\Extension')) {
|
||||
$twigBridgeExtensionsMethodCalls[] = $methodCall;
|
||||
} else {
|
||||
$othersExtensionsMethodCalls[] = $methodCall;
|
||||
|
||||
@@ -33,7 +33,7 @@ class TwigLoaderPass implements CompilerPassInterface
|
||||
$found = 0;
|
||||
|
||||
foreach ($container->findTaggedServiceIds('twig.loader', true) as $id => $attributes) {
|
||||
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
|
||||
$priority = $attributes[0]['priority'] ?? 0;
|
||||
$prioritizedLoaders[$priority][] = $id;
|
||||
++$found;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class TwigLoaderPass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
if (1 === $found) {
|
||||
$container->setAlias('twig.loader', $id)->setPrivate(true);
|
||||
$container->setAlias('twig.loader', $id);
|
||||
} else {
|
||||
$chainLoader = $container->getDefinition('twig.loader.chain');
|
||||
krsort($prioritizedLoaders);
|
||||
@@ -54,7 +54,7 @@ class TwigLoaderPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
$container->setAlias('twig.loader', 'twig.loader.chain')->setPrivate(true);
|
||||
$container->setAlias('twig.loader', 'twig.loader.chain');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user