Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:
curl https://fabbot.io/patch/symfony/symfony/24264/0a658c6eef6b74e64193b6d89bd6cde7a90f78fe/cs.diff | patch -p0
diff -ru src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
--- src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php 2020-06-01 21:10:47.944950265 +0000
+++ src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php 2020-06-01 21:10:48.519937577 +0000
@@ -16,8 +16,8 @@
use Symfony\Component\Config\Resource\FileExistenceResource;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\WebLink\HttpHeaderSerializer;
use Twig\Extension\ExtensionInterface;
@@ -34,9 +34,6 @@
{
/**
* Responds to the twig configuration parameter.
- *
- * @param array $configs
- * @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
{
@@ -76,11 +73,11 @@
foreach ($configs as $key => $config) {
if (isset($config['globals'])) {
foreach ($config['globals'] as $name => $value) {
- if (is_array($value) && isset($value['key'])) {
- $configs[$key]['globals'][$name] = array(
+ if (\is_array($value) && isset($value['key'])) {
+ $configs[$key]['globals'][$name] = [
'key' => $name,
'value' => $value,
- );
+ ];
}
}
}
@@ -107,9 +104,9 @@
// register user-configured paths
foreach ($config['paths'] as $path => $namespace) {
if (!$namespace) {
- $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path));
+ $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path]);
} else {
- $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
+ $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path, $namespace]);
}
}
@@ -123,29 +120,29 @@
foreach ($bundle['children'] as $child) {
foreach ($bundleHierarchy[$child]['paths'] as $path) {
- $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
+ $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path, $namespace]);
}
}
foreach ($bundle['paths'] as $path) {
- $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
+ $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$path, $namespace]);
}
// add exclusive namespace for root bundles only
// to override a bundle template that also extends itself
- if (count($bundle['paths']) > 0 && 0 === count($bundle['parents'])) {
+ if (\count($bundle['paths']) > 0 && 0 === \count($bundle['parents'])) {
// the last path must be the bundle views directory
- $twigFilesystemLoaderDefinition->addMethodCall('addPath', array(end($bundle['paths']), '!'.$namespace));
+ $twigFilesystemLoaderDefinition->addMethodCall('addPath', [end($bundle['paths']), '!'.$namespace]);
}
}
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {
- $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
+ $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$dir]);
}
$container->addResource(new FileExistenceResource($dir));
if (file_exists($dir = $container->getParameterBag()->resolveValue($config['default_path']))) {
- $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
+ $twigFilesystemLoaderDefinition->addMethodCall('addPath', [$dir]);
}
$container->addResource(new FileExistenceResource($dir));
@@ -153,9 +150,9 @@
$def = $container->getDefinition('twig');
foreach ($config['globals'] as $key => $global) {
if (isset($global['type']) && 'service' === $global['type']) {
- $def->addMethodCall('addGlobal', array($key, new Reference($global['id'])));
+ $def->addMethodCall('addGlobal', [$key, new Reference($global['id'])]);
} else {
- $def->addMethodCall('addGlobal', array($key, $global['value']));
+ $def->addMethodCall('addGlobal', [$key, $global['value']]);
}
}
}
@@ -167,7 +164,7 @@
);
if (isset($config['autoescape_service']) && isset($config['autoescape_service_method'])) {
- $config['autoescape'] = array(new Reference($config['autoescape_service']), $config['autoescape_service_method']);
+ $config['autoescape'] = [new Reference($config['autoescape_service']), $config['autoescape_service_method']];
}
unset($config['autoescape_service'], $config['autoescape_service_method']);
@@ -180,7 +177,7 @@
$container->registerForAutoconfiguration(RuntimeExtensionInterface::class)->addTag('twig.runtime');
if (\PHP_VERSION_ID < 70000) {
- $this->addClassesToCompile(array(
+ $this->addClassesToCompile([
'Twig_Environment',
'Twig_Extension',
'Twig_Extension_Core',
@@ -189,21 +186,21 @@
'Twig_LoaderInterface',
'Twig_Markup',
'Twig_Template',
- ));
+ ]);
}
}
private function getBundleHierarchy(ContainerBuilder $container, array $config)
{
- $bundleHierarchy = array();
+ $bundleHierarchy = [];
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
- if (!array_key_exists($name, $bundleHierarchy)) {
- $bundleHierarchy[$name] = array(
- 'paths' => array(),
- 'parents' => array(),
- 'children' => array(),
- );
+ if (!\array_key_exists($name, $bundleHierarchy)) {
+ $bundleHierarchy[$name] = [
+ 'paths' => [],
+ 'parents' => [],
+ 'children' => [],
+ ];
}
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$name.'/views')) {
@@ -227,19 +224,19 @@
$bundleHierarchy[$name]['parents'][] = $bundle['parent'];
- if (!array_key_exists($bundle['parent'], $bundleHierarchy)) {
- $bundleHierarchy[$bundle['parent']] = array(
- 'paths' => array(),
- 'parents' => array(),
- 'children' => array(),
- );
+ if (!\array_key_exists($bundle['parent'], $bundleHierarchy)) {
+ $bundleHierarchy[$bundle['parent']] = [
+ 'paths' => [],
+ 'parents' => [],
+ 'children' => [],
+ ];
}
- $bundleHierarchy[$bundle['parent']]['children'] = array_merge($bundleHierarchy[$name]['children'], array($name), $bundleHierarchy[$bundle['parent']]['children']);
+ $bundleHierarchy[$bundle['parent']]['children'] = array_merge($bundleHierarchy[$name]['children'], [$name], $bundleHierarchy[$bundle['parent']]['children']);
foreach ($bundleHierarchy[$bundle['parent']]['parents'] as $parent) {
$bundleHierarchy[$name]['parents'][] = $parent;
- $bundleHierarchy[$parent]['children'] = array_merge($bundleHierarchy[$name]['children'], array($name), $bundleHierarchy[$parent]['children']);
+ $bundleHierarchy[$parent]['children'] = array_merge($bundleHierarchy[$name]['children'], [$name], $bundleHierarchy[$parent]['children']);
}
foreach ($bundleHierarchy[$name]['children'] as $child) {
diff -ru src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
--- src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php 2020-06-01 21:10:48.134946072 +0000
+++ src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php 2020-06-01 21:10:48.740932701 +0000
@@ -17,11 +17,11 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
+use Symfony\Component\DependencyInjection\Reference;
class TwigExtensionTest extends TestCase
{
@@ -29,7 +29,7 @@
{
$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
- $container->loadFromExtension('twig', array());
+ $container->loadFromExtension('twig', []);
$this->compileContainer($container);
$this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file');
@@ -72,9 +72,9 @@
$this->assertEquals(3.14, $calls[4][1][1], '->load() registers variables as Twig globals');
// Yaml and Php specific configs
- if (in_array($format, array('yml', 'php'))) {
+ if (\in_array($format, ['yml', 'php'])) {
$this->assertEquals('bad', $calls[5][1][0], '->load() registers variables as Twig globals');
- $this->assertEquals(array('key' => 'foo'), $calls[5][1][1], '->load() registers variables as Twig globals');
+ $this->assertEquals(['key' => 'foo'], $calls[5][1][1], '->load() registers variables as Twig globals');
}
// Twig options
@@ -99,7 +99,7 @@
$this->compileContainer($container);
$options = $container->getDefinition('twig')->getArgument(1);
- $this->assertEquals(array(new Reference('my_project.some_bundle.template_escaping_guesser'), 'guess'), $options['autoescape']);
+ $this->assertEquals([new Reference('my_project.some_bundle.template_escaping_guesser'), 'guess'], $options['autoescape']);
}
/**
@@ -138,8 +138,8 @@
public function testGlobalsWithDifferentTypesAndValues()
{
- $globals = array(
- 'array' => array(),
+ $globals = [
+ 'array' => [],
'false' => false,
'float' => 2.0,
'integer' => 3,
@@ -147,15 +147,15 @@
'object' => new \stdClass(),
'string' => 'foo',
'true' => true,
- );
+ ];
$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
- $container->loadFromExtension('twig', array('globals' => $globals));
+ $container->loadFromExtension('twig', ['globals' => $globals]);
$this->compileContainer($container);
$calls = $container->getDefinition('twig')->getMethodCalls();
- foreach (array_slice($calls, 2) as $call) {
+ foreach (\array_slice($calls, 2) as $call) {
$this->assertEquals(key($globals), $call[1][0]);
$this->assertSame(current($globals), $call[1][1]);
@@ -175,49 +175,49 @@
$this->compileContainer($container);
$def = $container->getDefinition('twig.loader.native_filesystem');
- $paths = array();
+ $paths = [];
foreach ($def->getMethodCalls() as $call) {
if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) {
$paths[] = $call[1];
}
}
- $this->assertEquals(array(
- array('path1'),
- array('path2'),
- array('namespaced_path1', 'namespace1'),
- array('namespaced_path2', 'namespace2'),
- array('namespaced_path3', 'namespace3'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'Twig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'Twig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'Twig'),
- array(__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'Twig'),
- array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'),
- array(__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'),
- array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'),
- array(realpath(__DIR__.'/../..').'/Resources/views', '!Twig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'ChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
- array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildChildTwig'),
- array(__DIR__.'/Fixtures/Resources/views'),
- array(__DIR__.'/Fixtures/templates'),
- ), $paths);
+ $this->assertEquals([
+ ['path1'],
+ ['path2'],
+ ['namespaced_path1', 'namespace1'],
+ ['namespaced_path2', 'namespace2'],
+ ['namespaced_path3', 'namespace3'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'Twig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'Twig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'Twig'],
+ [__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'Twig'],
+ [__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'],
+ [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'],
+ [realpath(__DIR__.'/../..').'/Resources/views', 'Twig'],
+ [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'ChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'],
+ [__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildChildTwig'],
+ [__DIR__.'/Fixtures/Resources/views'],
+ [__DIR__.'/Fixtures/templates'],
+ ], $paths);
}
public function getFormats()
{
- return array(
- array('php'),
- array('yml'),
- array('xml'),
- );
+ return [
+ ['php'],
+ ['yml'],
+ ['xml'],
+ ];
}
/**
@@ -231,7 +231,7 @@
$container->register('debug.stopwatch', 'Symfony\Component\Stopwatch\Stopwatch');
}
$container->registerExtension(new TwigExtension());
- $container->loadFromExtension('twig', array());
+ $container->loadFromExtension('twig', []);
$this->compileContainer($container);
$tokenParsers = $container->get('twig.extension.debug.stopwatch')->getTokenParsers();
@@ -243,19 +243,19 @@
public function stopwatchExtensionAvailabilityProvider()
{
- return array(
- 'debug-and-stopwatch-enabled' => array(true, true, true),
- 'only-stopwatch-enabled' => array(false, true, false),
- 'only-debug-enabled' => array(true, false, false),
- 'debug-and-stopwatch-disabled' => array(false, false, false),
- );
+ return [
+ 'debug-and-stopwatch-enabled' => [true, true, true],
+ 'only-stopwatch-enabled' => [false, true, false],
+ 'only-debug-enabled' => [true, false, false],
+ 'debug-and-stopwatch-disabled' => [false, false, false],
+ ];
}
public function testRuntimeLoader()
{
$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
- $container->loadFromExtension('twig', array());
+ $container->loadFromExtension('twig', []);
$container->setParameter('kernel.environment', 'test');
$container->setParameter('debug.file_link_format', 'test');
$container->setParameter('foo', 'FooClass');
@@ -264,7 +264,7 @@
$container->register('templating.name_parser', 'FooClass');
$container->register('foo', '%foo%')->addTag('twig.runtime');
$container->addCompilerPass(new RuntimeLoaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
- $container->getCompilerPassConfig()->setRemovingPasses(array());
+ $container->getCompilerPassConfig()->setRemovingPasses([]);
$container->compile();
$loader = $container->getDefinition('twig.runtime_loader');
@@ -277,55 +277,55 @@
private function createContainer()
{
- $container = new ContainerBuilder(new ParameterBag(array(
+ $container = new ContainerBuilder(new ParameterBag([
'kernel.cache_dir' => __DIR__,
'kernel.root_dir' => __DIR__.'/Fixtures',
'kernel.project_dir' => __DIR__,
'kernel.charset' => 'UTF-8',
'kernel.debug' => false,
- 'kernel.bundles' => array(
+ 'kernel.bundles' => [
'TwigBundle' => 'Symfony\\Bundle\\TwigBundle\\TwigBundle',
'ChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildTwigBundle\\ChildTwigBundle',
'ChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildTwigBundle\\ChildChildTwigBundle',
'ChildChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildTwigBundle\\ChildChildChildTwigBundle',
'ChildChildChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildChildTwigBundle\\ChildChildChildChildTwigBundle',
- ),
- 'kernel.bundles_metadata' => array(
- 'ChildChildChildChildTwigBundle' => array(
+ ],
+ 'kernel.bundles_metadata' => [
+ 'ChildChildChildChildTwigBundle' => [
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildChildTwigBundle\\ChildChildChildChildTwigBundle',
'parent' => 'ChildChildChildTwigBundle',
'path' => __DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle',
- ),
- 'TwigBundle' => array(
+ ],
+ 'TwigBundle' => [
'namespace' => 'Symfony\\Bundle\\TwigBundle',
'parent' => null,
'path' => realpath(__DIR__.'/../..'),
- ),
- 'ChildTwigBundle' => array(
+ ],
+ 'ChildTwigBundle' => [
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildTwigBundle\\ChildTwigBundle',
'parent' => 'TwigBundle',
'path' => __DIR__.'/Fixtures/Bundle/ChildTwigBundle',
- ),
- 'ChildChildChildTwigBundle' => array(
+ ],
+ 'ChildChildChildTwigBundle' => [
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildTwigBundle\\ChildChildChildTwigBundle',
'parent' => 'ChildChildTwigBundle',
'path' => __DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle',
- ),
- 'ChildChildTwigBundle' => array(
+ ],
+ 'ChildChildTwigBundle' => [
'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildTwigBundle\\ChildChildTwigBundle',
'parent' => 'ChildTwigBundle',
'path' => __DIR__.'/Fixtures/Bundle/ChildChildTwigBundle',
- ),
- ),
- )));
+ ],
+ ],
+ ]));
return $container;
}
private function compileContainer(ContainerBuilder $container)
{
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
- $container->getCompilerPassConfig()->setRemovingPasses(array());
+ $container->getCompilerPassConfig()->setOptimizationPasses([]);
+ $container->getCompilerPassConfig()->setRemovingPasses([]);
$container->compile();
}
Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:
curl https://fabbot.io/patch/symfony/symfony/24264/0a658c6eef6b74e64193b6d89bd6cde7a90f78fe/exception_messages.diff | patch -p0
diff -ru src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
--- src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php 2020-06-01 21:10:48.134946072 +0000
+++ src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php 2020-06-01 21:10:49.262921183 +0000
@@ -344,7 +344,7 @@
$loader = new YamlFileLoader($container, $locator);
break;
default:
- throw new \InvalidArgumentException(sprintf('Unsupported format: %s', $format));
+ throw new \InvalidArgumentException(sprintf('Unsupported format: "%s"', $format));
}
$loader->load($file.'.'.$format);