Move Extra Bundle config from XML to PHP

This commit is contained in:
Fabien Potencier
2021-01-01 14:24:19 +01:00
parent 7fab4be1bb
commit b9712ce137
18 changed files with 206 additions and 116 deletions
+1
View File
@@ -86,6 +86,7 @@ jobs:
- 'extra/intl-extra'
- 'extra/markdown-extra'
- 'extra/string-extra'
- 'extra/twig-extra-bundle'
steps:
- name: "Checkout code"
+7 -9
View File
@@ -21,21 +21,19 @@
"twig/twig": "^2.4|^3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.4.9|^5.0.9",
"twig/cssinliner-extra": "^2.12|^3.0",
"twig/html-extra": "^2.12|^3.0",
"twig/inky-extra": "^2.12|^3.0",
"twig/intl-extra": "^2.12|^3.0",
"twig/markdown-extra": "^2.12|^3.0"
"twig/markdown-extra": "^2.12|^3.0",
"twig/string-extra": "^2.12|^3.0"
},
"autoload": {
"psr-4" : {
"Twig\\Extra\\TwigExtraBundle\\" : "src/"
}
},
"autoload-dev": {
"psr-4" : {
"Twig\\Extra\\TwigExtraBundle\\Tests\\" : "tests/"
}
"psr-4" : { "Twig\\Extra\\TwigExtraBundle\\" : "src/" },
"exclude-from-classmap": [
"/Tests/"
]
},
"extra": {
"branch-alias": {
@@ -13,7 +13,7 @@ namespace Twig\Extra\TwigExtraBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Twig\Extra\TwigExtraBundle\Extensions;
@@ -24,17 +24,17 @@ class TwigExtraExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
if ($container->getParameter('kernel.debug')) {
$loader->load('suggestor.xml');
$loader->load('suggestor.php');
}
foreach (array_keys(Extensions::getClasses()) as $extension) {
if ($this->isConfigEnabled($container, $config[$extension])) {
$loader->load($extension.'.xml');
$loader->load($extension.'.php');
}
}
}
@@ -0,0 +1,21 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Twig\Extra\CssInliner\CssInlinerExtension;
return static function (ContainerConfigurator $container) {
$container->services()
->set('twig.extension.cssinliner', CssInlinerExtension::class)
->tag('twig.extension')
;
};
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="twig.extension.cssinliner" class="Twig\Extra\CssInliner\CssInlinerExtension">
<tag name="twig.extension" />
</service>
</services>
</container>
@@ -0,0 +1,21 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Twig\Extra\Html\HtmlExtension;
return static function (ContainerConfigurator $container) {
$container->services()
->set('twig.extension.html', HtmlExtension::class)
->tag('twig.extension')
;
};
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="twig.extension.html" class="Twig\Extra\Html\HtmlExtension">
<tag name="twig.extension" />
</service>
</services>
</container>
@@ -0,0 +1,21 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Twig\Extra\Inky\InkyExtension;
return static function (ContainerConfigurator $container) {
$container->services()
->set('twig.extension.inky', InkyExtension::class)
->tag('twig.extension')
;
};
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="twig.extension.inky" class="Twig\Extra\Inky\InkyExtension">
<tag name="twig.extension" />
</service>
</services>
</container>
@@ -0,0 +1,21 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Twig\Extra\Intl\IntlExtension;
return static function (ContainerConfigurator $container) {
$container->services()
->set('twig.extension.intl', IntlExtension::class)
->tag('twig.extension')
;
};
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="twig.extension.intl" class="Twig\Extra\Intl\IntlExtension">
<tag name="twig.extension" />
</service>
</services>
</container>
@@ -0,0 +1,31 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Twig\Extra\Markdown\DefaultMarkdown;
use Twig\Extra\Markdown\MarkdownExtension;
use Twig\Extra\Markdown\MarkdownRuntime;
return static function (ContainerConfigurator $container) {
$container->services()
->set('twig.extension.markdown', MarkdownExtension::class)
->tag('twig.extension')
->set('twig.runtime.markdown', MarkdownRuntime::class)
->args([
service('twig.markdown.default'),
])
->tag('twig.runtime')
->set('twig.markdown.default', DefaultMarkdown::class)
;
};
@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="twig.extension.markdown" class="Twig\Extra\Markdown\MarkdownExtension">
<tag name="twig.extension" />
</service>
<service id="twig.runtime.markdown" class="Twig\Extra\Markdown\MarkdownRuntime">
<argument type="service" id="twig.markdown.default" />
<tag name="twig.runtime" />
</service>
<service id="twig.markdown.default" class="Twig\Extra\Markdown\DefaultMarkdown" />
</services>
</container>
@@ -0,0 +1,21 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Twig\Extra\String\StringExtension;
return static function (ContainerConfigurator $container) {
$container->services()
->set('twig.extension.string', StringExtension::class)
->tag('twig.extension')
;
};
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="twig.extension.string" class="Twig\Extra\String\StringExtension">
<tag name="twig.extension" />
</service>
</services>
</container>
@@ -0,0 +1,20 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Twig\Extra\TwigExtraBundle\MissingExtensionSuggestor;
return static function (ContainerConfigurator $container) {
$container->services()
->set('twig.missing_extension_suggestor', MissingExtensionSuggestor::class)
;
};
@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="twig.missing_extension_suggestor" class="Twig\Extra\TwigExtraBundle\MissingExtensionSuggestor" />
</services>
</container>
@@ -0,0 +1,38 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Extra\TwigExtraBundle\Tests\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Twig\Extra\TwigExtraBundle\DependencyInjection\TwigExtraExtension;
use Twig\Extra\TwigExtraBundle\Extensions;
class TwigExtraExtensionTest extends TestCase
{
public function testDefaultConfiguration()
{
$container = new ContainerBuilder(new ParameterBag([
'kernel.debug' => false,
]));
$container->registerExtension(new TwigExtraExtension());
$container->loadFromExtension('twig_extra');
$container->getCompilerPassConfig()->setOptimizationPasses([]);
$container->getCompilerPassConfig()->setRemovingPasses([]);
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
$container->compile();
foreach (Extensions::getClasses() as $name => $class) {
$this->assertEquals($class, $container->getDefinition('twig.extension.'.$name)->getClass());
}
}
}