Skip to content

Commit 94704d3

Browse files
authored
Switch from XML-based to PHP-based service configuration (#42)
XML-based service configuration has been deprecated since symfony/symfony#60568 and will no longer be supported in Symfony 8.0. See also https://symfony.com/blog/new-in-symfony-7-4-deprecated-xml-configuration. In order for ComposerRequireChecker to recognise where the functions come from, we have to import them explicitly. At the same time, PHP-CS-Fixer must not remove the import, which is actually superfluous. X-Ref GromNaN/symfony-config-xml-to-php#29, maglnet/ComposerRequireChecker#193 (comment)
1 parent 4e782da commit 94704d3

File tree

6 files changed

+105
-99
lines changed

6 files changed

+105
-99
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
->notPath('var/cache')
2626
->notPath('vendor/')
2727
->notPath('tests/Fixtures/cache')
28+
->notPath('src/Resources/config')
2829
)
2930
;

src/DependencyInjection/WebfactoryShortcodeExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Symfony\Component\DependencyInjection\ChildDefinition;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
88
use Symfony\Component\DependencyInjection\Extension\Extension;
9-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
9+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1010

1111
/**
1212
* Loads the bundle configuration.
@@ -15,9 +15,9 @@ final class WebfactoryShortcodeExtension extends Extension
1515
{
1616
public function load(array $configs, ContainerBuilder $container): void
1717
{
18-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
19-
$loader->load('shortcodes.xml');
20-
$loader->load('guide.xml');
18+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
19+
$loader->load('shortcodes.php');
20+
$loader->load('guide.php');
2121

2222
$configuration = new Configuration();
2323
$config = $this->processConfiguration($configuration, $configs);

src/Resources/config/guide.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service;
6+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
7+
8+
return static function(ContainerConfigurator $container) {
9+
$services = $container->services();
10+
$parameters = $container->parameters();
11+
12+
$services->defaults()
13+
->autowire()
14+
->autoconfigure();
15+
16+
$services->set(\Webfactory\ShortcodeBundle\Controller\GuideController::class)
17+
->args([
18+
'',
19+
service('twig'),
20+
])
21+
->tag('controller.service_arguments');
22+
};

src/Resources/config/guide.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service;
6+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
7+
8+
return static function(ContainerConfigurator $container) {
9+
$services = $container->services();
10+
$parameters = $container->parameters();
11+
12+
$services->defaults()
13+
->private();
14+
15+
$services->set(\Thunder\Shortcode\HandlerContainer\HandlerContainer::class);
16+
17+
$services->set('webfactory_shortcode.regular_parser', \Thunder\Shortcode\Parser\RegularParser::class);
18+
19+
$services->set('webfactory_shortcode.regex_parser', \Thunder\Shortcode\Parser\RegexParser::class);
20+
21+
$services->set(\Webfactory\ShortcodeBundle\Factory\ProcessorFactory::class)
22+
->args([
23+
service('webfactory_shortcode.parser'),
24+
service(\Thunder\Shortcode\HandlerContainer\HandlerContainer::class),
25+
service(\Thunder\Shortcode\EventContainer\EventContainer::class),
26+
'%webfactory_shortcode.recursion_depth%',
27+
'%webfactory_shortcode.max_iterations%',
28+
]);
29+
30+
$services->set(\Thunder\Shortcode\Processor\Processor::class)
31+
->public()
32+
->factory([service(\Webfactory\ShortcodeBundle\Factory\ProcessorFactory::class), 'create']);
33+
34+
$services->set(\Thunder\Shortcode\EventContainer\EventContainer::class)
35+
->call('addListener', [
36+
\Thunder\Shortcode\Events::REPLACE_SHORTCODES,
37+
inline_service(\Webfactory\ShortcodeBundle\Handler\RemoveWrappingParagraphElementsEventHandler::class),
38+
]);
39+
40+
$services->set('Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi', \Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler::class)
41+
->abstract()
42+
->lazy()
43+
->args([
44+
service('fragment.handler'),
45+
'',
46+
'esi',
47+
service('request_stack'),
48+
service('logger')->nullOnInvalid(),
49+
])
50+
->tag('monolog.logger', ['channel' => 'shortcode']);
51+
52+
$services->alias('webfactory.shortcode.embed_esi_for_shortcode_handler', 'Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi');
53+
54+
$services->set('Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline', \Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler::class)
55+
->abstract()
56+
->lazy()
57+
->args([
58+
service('fragment.handler'),
59+
'',
60+
'inline',
61+
service('request_stack'),
62+
service('logger')->nullOnInvalid(),
63+
])
64+
->tag('monolog.logger', ['channel' => 'shortcode']);
65+
66+
$services->alias('webfactory.shortcode.embed_inline_for_shortcode_handler', 'Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline');
67+
68+
$services->set(\Webfactory\ShortcodeBundle\Twig\ShortcodeExtension::class, \Webfactory\ShortcodeBundle\Twig\ShortcodeExtension::class)
69+
->args([service(\Thunder\Shortcode\Processor\Processor::class)])
70+
->tag('twig.extension');
71+
72+
$services->set(\Webfactory\ShortcodeBundle\Test\ShortcodeDefinitionTestHelper::class)
73+
->public()
74+
->args([
75+
service('controller_resolver'),
76+
service(\Thunder\Shortcode\HandlerContainer\HandlerContainer::class),
77+
]);
78+
};

src/Resources/config/shortcodes.xml

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)