Skip to content

Commit

Permalink
EZP-32340: Deprecated ezpublish_rest.field_type_processor in favour o…
Browse files Browse the repository at this point in the history
…f ezplatform.field_type.rest.processor
  • Loading branch information
adamwojs committed Feb 15, 2021
1 parent 91226e6 commit 65a4562
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/bundle/DependencyInjection/Compiler/FieldTypeProcessorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
*/
namespace EzSystems\EzPlatformRestBundle\DependencyInjection\Compiler;

use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class FieldTypeProcessorPass implements CompilerPassInterface
{
public const FIELD_TYPE_PROCESSOR_SERVICE_TAG = 'ezplatform.field_type.rest.processor';
public const DEPRECATED_FIELD_TYPE_PROCESSOR_SERVICE_TAG = 'ezpublish_rest.field_type_processor';

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ezpublish_rest.field_type_processor_registry')) {
Expand All @@ -20,15 +25,28 @@ public function process(ContainerBuilder $container)

$definition = $container->getDefinition('ezpublish_rest.field_type_processor_registry');

foreach ($container->findTaggedServiceIds('ezpublish_rest.field_type_processor') as $id => $attributes) {
$iterator = new BackwardCompatibleIterator(
$container,
self::FIELD_TYPE_PROCESSOR_SERVICE_TAG,
self::DEPRECATED_FIELD_TYPE_PROCESSOR_SERVICE_TAG
);

foreach ($iterator as $serviceId => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new \LogicException('The ezpublish_rest.field_type_processor service tag needs an "alias" attribute to identify the Field Type.');
throw new LogicException(
sprintf(
'Service "%s" tagged with "%s" or "%s" needs an "alias" attribute to identify the Field Type',
$serviceId,
self::FIELD_TYPE_PROCESSOR_SERVICE_TAG,
self::DEPRECATED_FIELD_TYPE_PROCESSOR_SERVICE_TAG
)
);
}

$definition->addMethodCall(
'registerProcessor',
[$attribute['alias'], new Reference($id)]
[$attribute['alias'], new Reference($serviceId)]
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

class FieldTypeProcessorPassTest extends TestCase
{
public function testProcess()
/**
* @dataProvider dataProviderForProcess
*/
public function testProcess(string $tag): void
{
$processorDefinition = new Definition();
$processorDefinition->addTag('ezpublish_rest.field_type_processor', ['alias' => 'test']);
$processorDefinition->addTag($tag, ['alias' => 'test']);

$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions(
Expand All @@ -36,4 +39,10 @@ public function testProcess()
self::assertInstanceOf(Reference::class, $dispatcherMethodCalls[0][1][1], 'Failed asserting that method call is to a Reference object');
self::assertEquals('ezpublish_rest.field_type_processor.test', $dispatcherMethodCalls[0][1][1]->__toString(), "Failed asserting that Referenced service is 'ezpublish_rest.output.value_object_visitor.test'");
}

public function dataProviderForProcess(): iterable
{
yield [FieldTypeProcessorPass::FIELD_TYPE_PROCESSOR_SERVICE_TAG];
yield [FieldTypeProcessorPass::DEPRECATED_FIELD_TYPE_PROCESSOR_SERVICE_TAG];
}
}

0 comments on commit 65a4562

Please sign in to comment.