Skip to content

Commit

Permalink
Move Extra Bundle config from XML to PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 1, 2021
1 parent 7fab4be commit b9712ce
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 116 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
- 'extra/intl-extra'
- 'extra/markdown-extra'
- 'extra/string-extra'
- 'extra/twig-extra-bundle'

steps:
- name: "Checkout code"
Expand Down
16 changes: 7 additions & 9 deletions extra/twig-extra-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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;

Expand All @@ -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');
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions extra/twig-extra-bundle/src/Resources/config/cssinliner.php
Original file line number Diff line number Diff line change
@@ -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')
;
};
14 changes: 0 additions & 14 deletions extra/twig-extra-bundle/src/Resources/config/cssinliner.xml

This file was deleted.

21 changes: 21 additions & 0 deletions extra/twig-extra-bundle/src/Resources/config/html.php
Original file line number Diff line number Diff line change
@@ -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')
;
};
14 changes: 0 additions & 14 deletions extra/twig-extra-bundle/src/Resources/config/html.xml

This file was deleted.

21 changes: 21 additions & 0 deletions extra/twig-extra-bundle/src/Resources/config/inky.php
Original file line number Diff line number Diff line change
@@ -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')
;
};
14 changes: 0 additions & 14 deletions extra/twig-extra-bundle/src/Resources/config/inky.xml

This file was deleted.

21 changes: 21 additions & 0 deletions extra/twig-extra-bundle/src/Resources/config/intl.php
Original file line number Diff line number Diff line change
@@ -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')
;
};
14 changes: 0 additions & 14 deletions extra/twig-extra-bundle/src/Resources/config/intl.xml

This file was deleted.

31 changes: 31 additions & 0 deletions extra/twig-extra-bundle/src/Resources/config/markdown.php
Original file line number Diff line number Diff line change
@@ -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)
;
};
21 changes: 0 additions & 21 deletions extra/twig-extra-bundle/src/Resources/config/markdown.xml

This file was deleted.

21 changes: 21 additions & 0 deletions extra/twig-extra-bundle/src/Resources/config/string.php
Original file line number Diff line number Diff line change
@@ -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')
;
};
14 changes: 0 additions & 14 deletions extra/twig-extra-bundle/src/Resources/config/string.xml

This file was deleted.

20 changes: 20 additions & 0 deletions extra/twig-extra-bundle/src/Resources/config/suggestor.php
Original file line number Diff line number Diff line change
@@ -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)
;
};
12 changes: 0 additions & 12 deletions extra/twig-extra-bundle/src/Resources/config/suggestor.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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());
}
}
}

0 comments on commit b9712ce

Please sign in to comment.