Skip to content

Commit

Permalink
EZP-31588: Introduced eZ\Bundle\EzPublishCoreBundle\DependencyInjecti…
Browse files Browse the repository at this point in the history
…on\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator
  • Loading branch information
adamwojs committed Jul 2, 2020
1 parent ff87f69 commit ef9bfab
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;

use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -31,20 +32,13 @@ public function process(ContainerBuilder $container)

$parameterProviderRegistryDef = $container->getDefinition('ezpublish.fieldType.parameterProviderRegistry');

$deprecatedFieldTypeParameterProviderTags = $container->findTaggedServiceIds(self::DEPRECATED_FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG);
foreach ($deprecatedFieldTypeParameterProviderTags as $deprecatedFieldTypeParameterProviderTag) {
@trigger_error(
sprintf(
'Service tag `%s` is deprecated and will be removed in eZ Platform 4.0. Use `%s` instead.',
self::DEPRECATED_FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG,
self::FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG
),
E_USER_DEPRECATED
);
}
$fieldTypeParameterProviderTags = $container->findTaggedServiceIds(self::FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG);
$parameterProviderFieldTypesTags = array_merge($deprecatedFieldTypeParameterProviderTags, $fieldTypeParameterProviderTags);
foreach ($parameterProviderFieldTypesTags as $id => $attributes) {
$iterator = new BackwardCompatibleIterator(
$container,
self::FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG,
self::DEPRECATED_FIELD_TYPE_PARAMETER_PROVIDER_SERVICE_TAG
);

foreach ($iterator as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new \LogicException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;

use AppendIterator;
use ArrayIterator;
use Iterator;
use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -31,7 +29,12 @@ public function process(ContainerBuilder $container): void

$queryTypes = [];

$iterator = $this->getTaggedServiceIdsIterator($container);
$iterator = new BackwardCompatibleIterator(
$container,
self::QUERY_TYPE_SERVICE_TAG,
self::DEPRECATED_QUERY_TYPE_SERVICE_TAG
);

foreach ($iterator as $taggedServiceId => $tags) {
$queryTypeDefinition = $container->getDefinition($taggedServiceId);
$queryTypeClass = $container->getParameterBag()->resolveValue($queryTypeDefinition->getClass());
Expand All @@ -45,31 +48,4 @@ public function process(ContainerBuilder $container): void
$aggregatorDefinition = $container->getDefinition('ezpublish.query_type.registry');
$aggregatorDefinition->addMethodCall('addQueryTypes', [$queryTypes]);
}

private function getTaggedServiceIdsIterator(ContainerBuilder $container): Iterator
{
$serviceIdsWithDeprecatedTags = $container->findTaggedServiceIds(
self::DEPRECATED_QUERY_TYPE_SERVICE_TAG
);

foreach ($serviceIdsWithDeprecatedTags as $serviceId => $tags) {
@trigger_error(
sprintf(
'Service tag `%s` is deprecated and will be removed in eZ Platform 4.0. Tag %s with `%s` instead.',
self::DEPRECATED_QUERY_TYPE_SERVICE_TAG,
$serviceId,
self::QUERY_TYPE_SERVICE_TAG
),
E_USER_DEPRECATED
);
}

$taggedServiceIds = $container->findTaggedServiceIds(self::QUERY_TYPE_SERVICE_TAG);

$iterator = new AppendIterator();
$iterator->append(new ArrayIterator($serviceIdsWithDeprecatedTags));
$iterator->append(new ArrayIterator($taggedServiceIds));

return $iterator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace eZ\Publish\Core\Base\Container\Compiler;

use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -27,24 +28,15 @@ abstract class AbstractFieldTypeBasedPass implements CompilerPassInterface
*
* @throws \LogicException
*/
public function getFieldTypeServiceIds(ContainerBuilder $container): array
public function getFieldTypeServiceIds(ContainerBuilder $container): iterable
{
// Field types.
// Alias attribute is the field type string.
$deprecatedFieldTypeTags = $container->findTaggedServiceIds(self::DEPRECATED_FIELD_TYPE_SERVICE_TAG);
foreach ($deprecatedFieldTypeTags as $deprecatedFieldTypeTag) {
@trigger_error(
sprintf(
'`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s`. instead.',
self::DEPRECATED_FIELD_TYPE_SERVICE_TAG,
self::FIELD_TYPE_SERVICE_TAG
),
E_USER_DEPRECATED
);
}
$fieldTypeTags = $container->findTaggedServiceIds(self::FIELD_TYPE_SERVICE_TAG);
$fieldTypesTags = array_merge($deprecatedFieldTypeTags, $fieldTypeTags);
foreach ($fieldTypesTags as $id => $attributes) {
$fieldTypesIterator = new BackwardCompatibleIterator(
$container,
self::FIELD_TYPE_SERVICE_TAG,
self::DEPRECATED_FIELD_TYPE_SERVICE_TAG
);

foreach ($fieldTypesIterator as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new LogicException(
Expand All @@ -58,7 +50,7 @@ public function getFieldTypeServiceIds(ContainerBuilder $container): array
}
}

return $fieldTypesTags;
return $fieldTypesIterator;
}

abstract public function process(ContainerBuilder $container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace eZ\Publish\Core\Base\Container\Compiler\Search;

use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -32,20 +33,13 @@ public function process(ContainerBuilder $container)

$fieldRegistryDefinition = $container->getDefinition('ezpublish.search.common.field_registry');

$deprecatedIndexableFieldTypeTags = $container->findTaggedServiceIds(self::DEPRECATED_FIELD_TYPE_INDEXABLE_SERVICE_TAG);
foreach ($deprecatedIndexableFieldTypeTags as $deprecatedIndexableFieldTypeTag) {
@trigger_error(
sprintf(
'`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s`. instead.',
self::DEPRECATED_FIELD_TYPE_INDEXABLE_SERVICE_TAG,
self::FIELD_TYPE_INDEXABLE_SERVICE_TAG
),
E_USER_DEPRECATED
);
}
$indexableFieldTypeTags = $container->findTaggedServiceIds(self::FIELD_TYPE_INDEXABLE_SERVICE_TAG);
$fieldTypesTags = array_merge($deprecatedIndexableFieldTypeTags, $indexableFieldTypeTags);
foreach ($fieldTypesTags as $id => $attributes) {
$fieldTypesIterator = new BackwardCompatibleIterator(
$container,
self::FIELD_TYPE_INDEXABLE_SERVICE_TAG,
self::DEPRECATED_FIELD_TYPE_INDEXABLE_SERVICE_TAG
);

foreach ($fieldTypesIterator as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new LogicException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace eZ\Publish\Core\Base\Container\Compiler\Storage;

use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -41,30 +42,14 @@ public function process(ContainerBuilder $container)
// Alias attribute is the corresponding field type string.
$externalStorageGateways = [];

$deprecatedExternalStorageHandlerGatewayTags = $container->findTaggedServiceIds(
self::DEPRECATED_EXTERNAL_STORAGE_HANDLER_GATEWAY_SERVICE_TAG
);

foreach ($deprecatedExternalStorageHandlerGatewayTags as $deprecatedExternalStorageHandlerGatewayTag) {
@trigger_error(
sprintf(
'`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s` instead.',
self::DEPRECATED_EXTERNAL_STORAGE_HANDLER_GATEWAY_SERVICE_TAG,
self::EXTERNAL_STORAGE_HANDLER_GATEWAY_SERVICE_TAG
),
E_USER_DEPRECATED
);
}

$externalStorageHandlerGatewayTags = array_merge(
$deprecatedExternalStorageHandlerGatewayTags,
$container->findTaggedServiceIds(
self::EXTERNAL_STORAGE_HANDLER_GATEWAY_SERVICE_TAG
)
$externalStorageHandlerGatewayIterator = new BackwardCompatibleIterator(
$container,
self::EXTERNAL_STORAGE_HANDLER_GATEWAY_SERVICE_TAG,
self::DEPRECATED_EXTERNAL_STORAGE_HANDLER_GATEWAY_SERVICE_TAG,
);

// Referencing the services by alias (field type string)
foreach ($externalStorageHandlerGatewayTags as $id => $attributes) {
foreach ($externalStorageHandlerGatewayIterator as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new LogicException(
Expand Down Expand Up @@ -93,31 +78,15 @@ public function process(ContainerBuilder $container)
}
}

$deprecatedExternalStorageHandlerTags = $container->findTaggedServiceIds(
$externalStorageHandlerIterator = new BackwardCompatibleIterator(
$container,
self::EXTERNAL_STORAGE_HANDLER_SERVICE_TAG,
self::DEPRECATED_EXTERNAL_STORAGE_HANDLER_SERVICE_TAG
);

foreach ($deprecatedExternalStorageHandlerTags as $deprecatedExternalStorageHandlerTag) {
@trigger_error(
sprintf(
'`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s` instead.',
self::DEPRECATED_EXTERNAL_STORAGE_HANDLER_SERVICE_TAG,
self::EXTERNAL_STORAGE_HANDLER_SERVICE_TAG
),
E_USER_DEPRECATED
);
}

$externalStorageHandlerTags = array_merge(
$deprecatedExternalStorageHandlerTags,
$container->findTaggedServiceIds(
self::EXTERNAL_STORAGE_HANDLER_SERVICE_TAG
)
);

// External storage handlers for field types that need them.
// Alias attribute is the field type string.
foreach ($externalStorageHandlerTags as $id => $attributes) {
foreach ($externalStorageHandlerIterator as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new LogicException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace eZ\Publish\Core\Base\Container\Compiler\Storage\Legacy;

use eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;
Expand Down Expand Up @@ -37,22 +38,13 @@ public function process(ContainerBuilder $container): void

$registry = $container->getDefinition(self::CONVERTER_REGISTRY_SERVICE_ID);

$deprecatedFieldTypeStorageConverterTags = $container->findTaggedServiceIds(
$iterator = new BackwardCompatibleIterator(
$container,
self::CONVERTER_SERVICE_TAG,
self::DEPRECATED_CONVERTER_SERVICE_TAG
);
foreach ($deprecatedFieldTypeStorageConverterTags as $deprecatedFieldTypeStorageConverterTag) {
@trigger_error(
sprintf(
'`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s` instead.',
self::DEPRECATED_CONVERTER_SERVICE_TAG,
self::CONVERTER_SERVICE_TAG
),
E_USER_DEPRECATED
);
}
$fieldTypeStorageConverterTags = $container->findTaggedServiceIds(self::CONVERTER_SERVICE_TAG);
$storageConverterFieldTypesTags = array_merge($deprecatedFieldTypeStorageConverterTags, $fieldTypeStorageConverterTags);
foreach ($storageConverterFieldTypesTags as $id => $attributes) {

foreach ($iterator as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new LogicException(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace eZ\Publish\Core\Base\Container\Compiler\TaggedServiceIdsIterator;

use Iterator;
use IteratorAggregate;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;

/**
* @internal
*/
final class BackwardCompatibleIterator implements IteratorAggregate
{
/** @var \Symfony\Component\DependencyInjection\TaggedContainerInterface */
private $container;

/** @var string */
private $serviceTag;

/** @var string */
private $deprecatedServiceTag;

public function __construct(TaggedContainerInterface $container, string $serviceTag, string $deprecatedServiceTag)
{
$this->container = $container;
$this->serviceTag = $serviceTag;
$this->deprecatedServiceTag = $deprecatedServiceTag;
}

public function getIterator(): Iterator
{
$serviceIdsWithDeprecatedTags = $this->container->findTaggedServiceIds($this->deprecatedServiceTag);
foreach ($serviceIdsWithDeprecatedTags as $serviceId => $tags) {
@trigger_error(
sprintf(
'Service tag `%s` is deprecated and will be removed in eZ Platform 4.0. Tag %s with `%s` instead.',
$this->deprecatedServiceTag,
$serviceId,
$this->serviceTag
),
E_USER_DEPRECATED
);

yield $serviceId => $tags;
}

$taggedServiceIds = $this->container->findTaggedServiceIds($this->serviceTag);
foreach ($taggedServiceIds as $serviceId => $tags) {
yield $serviceId => $tags;
}

yield from [];
}
}
Loading

0 comments on commit ef9bfab

Please sign in to comment.