Skip to content

Commit 9fb7e04

Browse files
committed
Use class names as service ids
Old service ids are aliasing the new services for backwards compatibility
1 parent 755237a commit 9fb7e04

8 files changed

Lines changed: 42 additions & 33 deletions

File tree

DependencyInjection/Compiler/ShortcodeCompilerPass.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
66
use Symfony\Component\DependencyInjection\ContainerBuilder;
77
use Symfony\Component\DependencyInjection\Reference;
8+
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
9+
use Webfactory\ShortcodeBundle\Controller\GuideController;
810

911
/**
1012
* CompilerPass that prepares the shortcode handler container and the GuideController (if configured).
@@ -16,22 +18,22 @@ public function process(ContainerBuilder $container)
1618
$shortcodeServices = $container->findTaggedServiceIds('webfactory.shortcode');
1719

1820
// add services tagged with webfactory.shortcode as handlers to the short code handler container
19-
$handlerContainer = $container->findDefinition('webfactory.shortcode.handler_container');
21+
$handlerContainer = $container->findDefinition(HandlerContainer::class);
2022
foreach ($shortcodeServices as $id => $shortcodeTags) {
2123
foreach ($shortcodeTags as $shortcodeTag) {
2224
$handlerContainer->addMethodCall('add', [$shortcodeTag['shortcode'], new Reference($id)]);
2325
}
2426
}
2527

2628
// prepare the GuideController if it's configuration is imported
27-
if ($container->has('webfactory.shortcode.guide.controller')) {
29+
if ($container->has(GuideController::class)) {
2830
$allShortcodeTags = [];
2931
foreach ($shortcodeServices as $id => $shortcodeTags) {
3032
$allShortcodeTags = array_merge($allShortcodeTags, $shortcodeTags);
3133
}
3234

3335
$container
34-
->getDefinition('webfactory.shortcode.guide.controller')
36+
->getDefinition(GuideController::class)
3537
->setArgument(0, $allShortcodeTags);
3638
}
3739
}

Handler/EmbeddedShortcodeHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public function __invoke(ShortcodeInterface $shortcode)
8787
.'attributes. This can happen e.g. when using Param Converters for your original controller '
8888
.'action, as the request (containing the conversion result) is automatically passed to the call of '
8989
.'the shortcode controller to allow context sensitive shortcodes. You could use '
90-
.'webfactory.shortcode.embed_inline_for_shortcode_handler as parent in your shortcode\'s service '
91-
.'defintion, so that the inline instead of ESI rendering strategy will be used.',
90+
.'Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline as parent in your '
91+
.'shortcode\'s service defintion, so that the inline instead of ESI rendering strategy will be '
92+
.'used.',
9293
0,
9394
$exception
9495
);

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public function registerBundles()
6767
The easiest way is to add one anonymous service for each shortcode in your services definition:
6868

6969
```xml
70-
<service parent="webfactory.shortcode.embed_esi_for_shortcode_handler">
70+
<service parent="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi">
7171
<argument index="1">reference-to-your-replacement-controller</argument>
7272
<tag name="webfactory.shortcode" shortcode="your-shortcode-name"/>
7373
</service>
7474
```
7575

76-
The parent ```webfactory.shortcode.embed_esi_for_shortcode_handler``` will use [ESI rendering](https://symfony.com/doc/current/http_cache/esi.html)
77-
(which may be nice for caching), while the parent ```webfactory.shortcode.embed_inline_for_shortcode_handler``` will use
76+
The parent ```Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi``` will use [ESI rendering](https://symfony.com/doc/current/http_cache/esi.html)
77+
(which may be nice for caching), while the parent ```Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline``` will use
7878
inline rendering.
7979

8080
The ```reference-to-your-replacement-controller``` could be a string like ```AppBundle\Controller\EmbeddedImageController::showAction```
@@ -106,7 +106,7 @@ Then, write a service definition like this:
106106

107107
<!-- ... -->
108108

109-
<service parent="webfactory.shortcode.embed_esi_for_shortcode_handler">
109+
<service parent="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi">
110110
<argument index="1">app.controller.embedded_image:showAction</argument>
111111
<tag name="webfactory.shortcode" shortcode="image"/>
112112
</service>
@@ -207,7 +207,7 @@ Finally, enrich your shortcode tags with description and example attributes for
207207
<!-- import guide.xml -->
208208

209209
<services>
210-
<service parent="webfactory.shortcode.embed_esi_for_shortcode_handler">
210+
<service parent="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi">
211211
<argument index="1">app.controller.embedded_image:showAction</argument>
212212
<tag
213213
name="webfactory.shortcode"
@@ -289,7 +289,7 @@ definition of your shortcode:
289289
<?xml version="1.0" ?>
290290
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
291291
<services>
292-
<service parent="webfactory.shortcode.embed_esi_for_shortcode_handler">
292+
<service parent="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi">
293293
<argument index="1">app.controller.embedded_image:showAction</argument>
294294
<tag name="webfactory.shortcode" ... />
295295
...

Resources/config/guide-routing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
http://symfony.com/schema/routing/routing-1.0.xsd">
66

77
<route id="webfactory.shortcode.guide-list" path="/">
8-
<default key="_controller">webfactory.shortcode.guide.controller:listAction</default>
8+
<default key="_controller">Webfactory\ShortcodeBundle\Controller\GuideController:listAction</default>
99
</route>
1010

1111
<route id="webfactory.shortcode.guide-detail" path="/{shortcode}/">
12-
<default key="_controller">webfactory.shortcode.guide.controller:detailAction</default>
12+
<default key="_controller">Webfactory\ShortcodeBundle\Controller\GuideController:detailAction</default>
1313
</route>
1414

1515
</routes>

Resources/config/guide.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66
<services>
77

8-
<service id="webfactory.shortcode.guide.controller" class="Webfactory\ShortcodeBundle\Controller\GuideController">
8+
<service id="Webfactory\ShortcodeBundle\Controller\GuideController">
99
<argument><!-- shortcode description placeholder argument --></argument>
1010
</service>
1111

Resources/config/shortcodes.xml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@
66
<services>
77

88
<!-- Definition of a Shortcode HandlerContainer instance. -->
9-
<service id="webfactory.shortcode.handler_container" class="Thunder\Shortcode\HandlerContainer\HandlerContainer">
10-
</service>
9+
<service id="Thunder\Shortcode\HandlerContainer\HandlerContainer"/>
1110

1211
<!-- Definition of a Shortcode RegularParser instance. -->
13-
<service id="webfactory.shortcode.regular_parser" class="Thunder\Shortcode\Parser\RegularParser">
14-
</service>
12+
<service id="Thunder\Shortcode\Parser\RegularParser"/>
1513

1614
<!-- Definition of a Shortcode Processor instance. -->
17-
<service id="webfactory.shortcode.processor" class="Thunder\Shortcode\Processor\Processor">
18-
<argument type="service" id="webfactory.shortcode.regular_parser" />
19-
<argument type="service" id="webfactory.shortcode.handler_container" />
15+
<service id="Thunder\Shortcode\Processor\Processor">
16+
<argument type="service" id="Thunder\Shortcode\Parser\RegularParser" />
17+
<argument type="service" id="Thunder\Shortcode\HandlerContainer\HandlerContainer" />
2018
</service>
2119

2220
<!-- Definition of a Shortcode EventContainer instance. -->
23-
<service id="webfactory.shortcode.event_container" class="Thunder\Shortcode\EventContainer\EventContainer">
21+
<service id="Thunder\Shortcode\EventContainer\EventContainer">
2422
<!-- Event handler that removes <p>...</p> tag that directly wrap shortcodes. -->
2523
<call method="addListener">
2624
<argument type="constant">\Thunder\Shortcode\Events::REPLACE_SHORTCODES</argument>
@@ -31,27 +29,33 @@
3129
</service>
3230

3331
<!-- Base definition for the EmbedForShortcodeHandler with esi renderer. -->
34-
<service abstract="true" id="webfactory.shortcode.embed_esi_for_shortcode_handler" class="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler" lazy="true">
32+
<service abstract="true" id="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi" class="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler" lazy="true">
3533
<argument type="service" id="fragment.handler"/>
3634
<argument><!-- Controller name placeholder argument --></argument>
3735
<argument>esi</argument>
3836
<argument type="service" id="request_stack" />
3937
<argument type="service" id="logger" on-invalid="null" />
4038
</service>
4139

40+
<!-- alias for BC -->
41+
<service id="webfactory.shortcode.embed_esi_for_shortcode_handler" alias="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi"/>
42+
4243
<!-- Base definition for the EmbedForShortcodeHandler with inline renderer. -->
43-
<service abstract="true" id="webfactory.shortcode.embed_inline_for_shortcode_handler" class="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler" lazy="true">
44+
<service abstract="true" id="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline" class="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler" lazy="true">
4445
<argument type="service" id="fragment.handler"/>
4546
<argument><!-- Controller name placeholder argument --></argument>
4647
<argument>inline</argument>
4748
<argument type="service" id="request_stack" />
4849
<argument type="service" id="logger" on-invalid="null" />
4950
</service>
5051

52+
<!-- alias for BC -->
53+
<service id="webfactory.shortcode.embed_inline_for_shortcode_handler" alias="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline"/>
54+
5155
<!-- Twig extension providing the |shortcodes filter. The content will be passed to the Shortcode Processor. -->
5256
<service id="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension" class="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension">
53-
<argument type="service" id="webfactory.shortcode.processor"/>
54-
<argument type="service" id="webfactory.shortcode.event_container"/>
57+
<argument type="service" id="Thunder\Shortcode\Processor\Processor"/>
58+
<argument type="service" id="Thunder\Shortcode\EventContainer\EventContainer"/>
5559
<tag name="twig.extension"/>
5660
</service>
5761

Tests/DependencyInjection/Compiler/ShortcodeCompilerPassTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Symfony\Component\DependencyInjection\ContainerBuilder;
77
use Symfony\Component\DependencyInjection\Definition;
88
use Symfony\Component\DependencyInjection\Reference;
9+
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
10+
use Webfactory\ShortcodeBundle\Controller\GuideController;
911
use Webfactory\ShortcodeBundle\DependencyInjection\Compiler\ShortcodeCompilerPass;
1012

1113
final class ShortcodeCompilerPassTest extends TestCase
@@ -58,7 +60,7 @@ public function tagged_services_are_added_as_handlers_to_handler_container()
5860

5961
$this->containerBuilder->expects($this->once())
6062
->method('findDefinition')
61-
->with('webfactory.shortcode.handler_container')
63+
->with(HandlerContainer::class)
6264
->willReturn($mockedShortcodeHandlerContainer);
6365

6466
$this->compilerPass->process($this->containerBuilder);
@@ -92,12 +94,12 @@ public function shortcode_guide_service_gets_configured_if_set()
9294

9395
$this->containerBuilder->expects($this->once())
9496
->method('findDefinition')
95-
->with('webfactory.shortcode.handler_container')
97+
->with(HandlerContainer::class)
9698
->willReturn($this->createMock(Definition::class));
9799

98100
$this->containerBuilder->expects($this->once())
99101
->method('has')
100-
->with('webfactory.shortcode.guide.controller')
102+
->with(GuideController::class)
101103
->willReturn(true);
102104

103105
$mockedShortcodeGuideServiceDefinition = $this->createMock(Definition::class);
@@ -113,7 +115,7 @@ public function shortcode_guide_service_gets_configured_if_set()
113115

114116
$this->containerBuilder->expects($this->once())
115117
->method('getDefinition')
116-
->with('webfactory.shortcode.guide.controller')
118+
->with(GuideController::class)
117119
->willReturn($mockedShortcodeGuideServiceDefinition);
118120

119121
$this->compilerPass->process($this->containerBuilder);
@@ -130,7 +132,7 @@ public function missing_shortcode_guide_service_does_no_harm()
130132

131133
$this->containerBuilder->expects($this->once())
132134
->method('has')
133-
->with('webfactory.shortcode.guide.controller')
135+
->with(GuideController::class)
134136
->willReturn(false);
135137

136138
$this->compilerPass->process($this->containerBuilder);

Tests/Fixtures/config/test_shortcodes.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
<!-- Two shortcode handlers defined for tests -->
99

10-
<service id="test_esi" parent="webfactory.shortcode.embed_esi_for_shortcode_handler">
10+
<service id="test_esi" parent="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.esi">
1111
<argument index="1">test-esi-controller</argument>
1212
<argument index="4">null</argument><!-- Logger -->
1313
<tag name="webfactory.shortcode" shortcode="test-esi"/>
1414
</service>
1515

16-
<service id="test_inline" parent="webfactory.shortcode.embed_inline_for_shortcode_handler">
16+
<service id="test_inline" parent="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline">
1717
<argument index="1">test-inline-controller</argument>
1818
<argument index="4">null</argument><!-- Logger -->
1919
<tag name="webfactory.shortcode" shortcode="test-inline"/>

0 commit comments

Comments
 (0)