Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using tagged_iterators for the markup listener #7403

Open
wants to merge 3 commits into
base: 2.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Upgrade

### Replacing compiler passes with `tagged_iterator`s
We have replaced the manual logic of getting a list of tagged services to the Symfony `tagged_iterator` argument. This
means that the following classes have been deprecated:
- src/Sulu/Bundle/MarkupBundle/DependencyInjection/CompilerPass/ParserCompilerPass.php

## 2.6.0

### PHP 8.2 upgrade
Expand Down
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12660,16 +12660,6 @@ parameters:
count: 1
path: src/Sulu/Bundle/MarkupBundle/Listener/MarkupListener.php

-
message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, Sulu\\\\Bundle\\\\MarkupBundle\\\\Markup\\\\MarkupParserInterface given\\.$#"
count: 1
path: src/Sulu/Bundle/MarkupBundle/Listener/MarkupListener.php

-
message: "#^Property Sulu\\\\Bundle\\\\MarkupBundle\\\\Listener\\\\MarkupListener\\:\\:\\$markupParser \\(Sulu\\\\Bundle\\\\MarkupBundle\\\\Markup\\\\MarkupParserInterface\\) does not accept array\\<Sulu\\\\Bundle\\\\MarkupBundle\\\\Markup\\\\MarkupParserInterface\\>\\.$#"
count: 1
path: src/Sulu/Bundle/MarkupBundle/Listener/MarkupListener.php

-
message: "#^Method Sulu\\\\Bundle\\\\MarkupBundle\\\\Markup\\\\HtmlTagExtractor\\:\\:count\\(\\) should return int but returns int\\<0, max\\>\\|false\\.$#"
count: 1
Expand Down Expand Up @@ -12835,11 +12825,6 @@ parameters:
count: 1
path: src/Sulu/Bundle/MarkupBundle/Tag/TagRegistry.php

-
message: "#^Class Sulu\\\\Bundle\\\\MarkupBundle\\\\Listener\\\\MarkupListener constructor invoked with 2 parameters, 1 required\\.$#"
count: 1
path: src/Sulu/Bundle/MarkupBundle/Tests/Unit/Listener/MarkupListenerTest.php

-
message: "#^Method Sulu\\\\Bundle\\\\MarkupBundle\\\\Tests\\\\Unit\\\\Markup\\\\HtmlTagExtractorTest\\:\\:provideMultipleTags\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,33 @@

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Collects all parsers for markup.
*
* @internal
*
* @deprecated
*/
class ParserCompilerPass implements CompilerPassInterface
{
/**
* @deprecated Don't use this constant anymore use tagged_iterator
*/
public const SERVICE_ID = 'sulu_markup.response_listener';

/**
* @deprecated Use the value instead
*/
public const TAG_NAME = 'sulu_markup.parser';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could move this to the ParserInterface as a constant. Could be helpful for people who use PHP to Configure their app?


/**
* @deprecated don't use this constant anymore
*/
public const TYPE_ATTRIBUTE = 'type';

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(self::SERVICE_ID)) {
return;
}

$references = [];
foreach ($container->findTaggedServiceIds(self::TAG_NAME) as $id => $tags) {
foreach ($tags as $attributes) {
$references[$attributes[self::TYPE_ATTRIBUTE]] = new Reference($id);
}
}

if (0 === \count($references)) {
return;
}

$container->getDefinition(self::SERVICE_ID)->replaceArgument(0, $references);
trigger_deprecation('sulu/sulu', '2.5', 'Using this CompilerPass is deprecated. Use the tagged_iterator instead');
}
}
10 changes: 5 additions & 5 deletions src/Sulu/Bundle/MarkupBundle/Listener/MarkupListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
class MarkupListener implements EventSubscriberInterface
{
/**
* @var MarkupParserInterface
* @var array<string, MarkupParserInterface>
*/
private $markupParser;
private array $markupParser;

/**
* @param MarkupParserInterface[] $markupParser
* @param iterable<MarkupParserInterface> $markupParser
*/
public function __construct(array $markupParser)
public function __construct(iterable $markupParser)
{
$this->markupParser = $markupParser;
$this->markupParser = \iterator_to_array($markupParser);
}

public static function getSubscribedEvents(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Sulu/Bundle/MarkupBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</service>

<service id="sulu_markup.response_listener" class="Sulu\Bundle\MarkupBundle\Listener\MarkupListener">
<argument type="collection"/>
<argument type="tagged_iterator" tag="sulu_markup.parser" index-by="type" />

<tag name="kernel.event_subscriber"/>
</service>
Expand Down
2 changes: 0 additions & 2 deletions src/Sulu/Bundle/MarkupBundle/SuluMarkupBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Sulu\Bundle\MarkupBundle;

use Sulu\Bundle\MarkupBundle\DependencyInjection\CompilerPass\ParserCompilerPass;
use Sulu\Bundle\MarkupBundle\DependencyInjection\CompilerPass\TagCompilerPass;
use Sulu\Component\Symfony\CompilerPass\TaggedServiceCollectorCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -31,7 +30,6 @@ public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new ParserCompilerPass());
$container->addCompilerPass(new TagCompilerPass());
$container->addCompilerPass(
new TaggedServiceCollectorCompilerPass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function setUp(): void
$this->response->reveal()
);

$this->listener = new MarkupListener(['html' => $this->markupParser->reveal()], ['text/html' => 'html']);
$this->listener = new MarkupListener(['html' => $this->markupParser->reveal()]);
}

public function testReplaceMarkup(): void
Expand Down
Loading