Skip to content

Commit 831def6

Browse files
authored
Merge pull request #3 from webfactory/89286_increase_iteration_count
89286 increase iteration count
2 parents 7744220 + 2e2e3fc commit 831def6

4 files changed

Lines changed: 41 additions & 25 deletions

File tree

DependencyInjection/Compiler/ShortcodeCompilerPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
use Symfony\Component\DependencyInjection\Reference;
88

99
/**
10-
* CompilerPass that prepares the shortcode facade and the GuideController (if configured).
10+
* CompilerPass that prepares the shortcode handler container and the GuideController (if configured).
1111
*/
1212
class ShortcodeCompilerPass implements CompilerPassInterface
1313
{
1414
public function process(ContainerBuilder $container)
1515
{
1616
$shortcodeServices = $container->findTaggedServiceIds('webfactory.shortcode');
1717

18-
// add services tagged with webfactory.shortcode.facade as handlers to the short code facade
19-
$serviceDefinition = $container->findDefinition('webfactory.shortcode.facade');
18+
// add services tagged with webfactory.shortcode as handlers to the short code handler container
19+
$handlerContainer = $container->findDefinition('webfactory.shortcode.handler_container');
2020
foreach ($shortcodeServices as $id => $shortcodeTags) {
2121
foreach ($shortcodeTags as $shortcodeTag) {
22-
$serviceDefinition->addMethodCall('addHandler', [$shortcodeTag['shortcode'], new Reference($id)]);
22+
$handlerContainer->addMethodCall('add', [$shortcodeTag['shortcode'], new Reference($id)]);
2323
}
2424
}
2525

Resources/config/shortcodes.xml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66
<services>
77

8-
<!-- Definition of a ShortcodeFacade instance. -->
9-
<service id="webfactory.shortcode.facade" class="Thunder\Shortcode\ShortcodeFacade">
8+
<!-- Definition of a Shortcode HandlerContainer instance. -->
9+
<service id="webfactory.shortcode.handler_container" class="Thunder\Shortcode\HandlerContainer\HandlerContainer">
10+
</service>
11+
12+
<!-- Definition of a Shortcode RegularParser instance. -->
13+
<service id="webfactory.shortcode.regular_parser" class="Thunder\Shortcode\Parser\RegularParser">
14+
</service>
15+
16+
<!-- 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" />
20+
</service>
21+
22+
<!-- Definition of a Shortcode EventContainer instance. -->
23+
<service id="webfactory.shortcode.event_container" class="Thunder\Shortcode\EventContainer\EventContainer">
1024
<!-- Event handler that removes <p>...</p> tag that directly wrap shortcodes. -->
11-
<call method="addEventHandler">
25+
<call method="addListener">
1226
<argument type="constant">\Thunder\Shortcode\Events::REPLACE_SHORTCODES</argument>
1327
<argument type="service">
1428
<service class="Webfactory\ShortcodeBundle\Handler\RemoveWrappingParagraphElementsEventHandler"/>
@@ -34,9 +48,10 @@
3448
<argument type="service" id="logger" on-invalid="null" />
3549
</service>
3650

37-
<!-- Twig extension providing the |shortcodes filter. The content will be passed to the ShortcodeFacade. -->
51+
<!-- Twig extension providing the |shortcodes filter. The content will be passed to the Shortcode Processor. -->
3852
<service id="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension" class="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension">
39-
<argument type="service" id="webfactory.shortcode.facade"/>
53+
<argument type="service" id="webfactory.shortcode.processor"/>
54+
<argument type="service" id="webfactory.shortcode.event_container"/>
4055
<tag name="twig.extension"/>
4156
</service>
4257

Tests/DependencyInjection/Compiler/ShortcodeCompilerPassTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp()
2929
}
3030

3131
/** @test */
32-
public function tagged_services_are_added_as_handlers_to_facade()
32+
public function tagged_services_are_added_as_handlers_to_handler_container()
3333
{
3434
$this->containerBuilder->expects($this->once())
3535
->method('findTaggedServiceIds')
@@ -42,24 +42,24 @@ public function tagged_services_are_added_as_handlers_to_facade()
4242
],
4343
]);
4444

45-
$mockedShortcodeFacade = $this->createMock(Definition::class);
46-
$mockedShortcodeFacade->expects($this->at(0))
45+
$mockedShortcodeHandlerContainer = $this->createMock(Definition::class);
46+
$mockedShortcodeHandlerContainer->expects($this->at(0))
4747
->method('addMethodCall')
48-
->with('addHandler', $this->callback(function (array $argument) {
48+
->with('add', $this->callback(function (array $argument) {
4949
return 'shortcode1' === $argument[0]
5050
&& $argument[1] instanceof Reference;
5151
}));
52-
$mockedShortcodeFacade->expects($this->at(1))
52+
$mockedShortcodeHandlerContainer->expects($this->at(1))
5353
->method('addMethodCall')
54-
->with('addHandler', $this->callback(function ($argument) {
54+
->with('add', $this->callback(function ($argument) {
5555
return 'shortcode2' === $argument[0]
5656
&& $argument[1] instanceof Reference;
5757
}));
5858

5959
$this->containerBuilder->expects($this->once())
6060
->method('findDefinition')
61-
->with('webfactory.shortcode.facade')
62-
->willReturn($mockedShortcodeFacade);
61+
->with('webfactory.shortcode.handler_container')
62+
->willReturn($mockedShortcodeHandlerContainer);
6363

6464
$this->compilerPass->process($this->containerBuilder);
6565
}
@@ -92,7 +92,7 @@ public function shortcode_guide_service_gets_configured_if_set()
9292

9393
$this->containerBuilder->expects($this->once())
9494
->method('findDefinition')
95-
->with('webfactory.shortcode.facade')
95+
->with('webfactory.shortcode.handler_container')
9696
->willReturn($this->createMock(Definition::class));
9797

9898
$this->containerBuilder->expects($this->once())

Twig/ShortcodeExtension.php

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

33
namespace Webfactory\ShortcodeBundle\Twig;
44

5-
use Thunder\Shortcode\ShortcodeFacade;
5+
use Thunder\Shortcode\EventContainer\EventContainer;
6+
use Thunder\Shortcode\Processor\Processor;
67
use Twig\Extension\AbstractExtension;
78
use Twig\TwigFilter;
89

@@ -11,15 +12,15 @@
1112
*/
1213
final class ShortcodeExtension extends AbstractExtension
1314
{
14-
/** @var ShortcodeFacade */
15-
private $facade;
15+
/** @var Processor */
16+
private $processor;
1617

1718
/**
18-
* @param ShortcodeFacade $facade
19+
* @param Processor $processor
1920
*/
20-
public function __construct(ShortcodeFacade $facade)
21+
public function __construct(Processor $processor, EventContainer $eventContainer)
2122
{
22-
$this->facade = $facade;
23+
$this->processor = $processor->withMaxIterations(null)->withEventContainer($eventContainer);
2324
}
2425

2526
public function getFilters()
@@ -36,6 +37,6 @@ public function getFilters()
3637
*/
3738
public function processShortcodes($content)
3839
{
39-
return $this->facade->process($content);
40+
return $this->processor->process($content);
4041
}
4142
}

0 commit comments

Comments
 (0)