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

IBX-1694: Rebranded dependency injection container service tags #12

Merged
merged 3 commits into from
Jan 17, 2022
Merged
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
16 changes: 5 additions & 11 deletions src/bundle/DependencyInjection/Compiler/FieldTypeProcessorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
namespace Ibexa\Bundle\Rest\DependencyInjection\Compiler;

use Ibexa\Core\Base\Container\Compiler\TaggedServiceIdsIterator\BackwardCompatibleIterator;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -15,7 +14,6 @@
class FieldTypeProcessorPass implements CompilerPassInterface
{
private const FIELD_TYPE_PROCESSOR_SERVICE_TAG = 'ibexa.rest.field_type.processor';
private const DEPRECATED_FIELD_TYPE_PROCESSOR_SERVICE_TAG = 'ezpublish_rest.field_type_processor';

public function process(ContainerBuilder $container)
{
Expand All @@ -25,21 +23,17 @@ public function process(ContainerBuilder $container)

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

$iterator = new BackwardCompatibleIterator(
$container,
self::FIELD_TYPE_PROCESSOR_SERVICE_TAG,
self::DEPRECATED_FIELD_TYPE_PROCESSOR_SERVICE_TAG
$taggedServiceIds = $container->findTaggedServiceIds(
self::FIELD_TYPE_PROCESSOR_SERVICE_TAG
);

foreach ($iterator as $serviceId => $attributes) {
foreach ($taggedServiceIds as $serviceId => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['alias'])) {
throw new LogicException(
sprintf(
'Service "%s" tagged with "%s" or "%s" needs an "alias" attribute to identify the Field Type',
'Service "%s" tagged with "%s" needs an "alias" attribute to identify the Field Type',
$serviceId,
self::FIELD_TYPE_PROCESSOR_SERVICE_TAG,
self::DEPRECATED_FIELD_TYPE_PROCESSOR_SERVICE_TAG
self::FIELD_TYPE_PROCESSOR_SERVICE_TAG
)
);
}
Expand Down
15 changes: 11 additions & 4 deletions src/bundle/DependencyInjection/Compiler/InputHandlerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Container processor for the ezpublish_rest.input.handler service tag.
* Container processor for the ibexa.rest.input.handler service tag.
* Maps input formats (json, xml) to handlers.
*
* Tag attributes: format. Ex: json
*/
class InputHandlerPass implements CompilerPassInterface
{
public const INPUT_HANDLER_SERVICE_TAG = 'ibexa.rest.input.handler';

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ezpublish_rest.input.dispatcher')) {
Expand All @@ -26,11 +28,16 @@ public function process(ContainerBuilder $container)

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

// @todo rethink the relationships between registries. Rename if required.
foreach ($container->findTaggedServiceIds('ezpublish_rest.input.handler') as $id => $attributes) {
$taggedServiceIds = $container->findTaggedServiceIds(self::INPUT_HANDLER_SERVICE_TAG);
foreach ($taggedServiceIds as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['format'])) {
throw new \LogicException('The ezpublish_rest.input.handler service tag needs a "format" attribute to identify the input handler.');
throw new \LogicException(
sprintf(
'The "%s" service tag needs a "format" attribute to identify the input handler.',
self::INPUT_HANDLER_SERVICE_TAG
)
);
}

$definition->addMethodCall(
Expand Down
14 changes: 11 additions & 3 deletions src/bundle/DependencyInjection/Compiler/InputParserPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Container compiler processor for the ezpublish_rest.input.parser service tag.
* Container compiler processor for the ibexa.rest.input.parser service tag.
* Maps input parsers to media types.
*
* Tag attributes: mediaType. Ex: application/vnd.ez.api.Content
*/
class InputParserPass implements CompilerPassInterface
{
public const INPUT_PARSER_SERVICE_TAG = 'ibexa.rest.input.parser';

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ezpublish_rest.input.parsing_dispatcher')) {
Expand All @@ -26,10 +28,16 @@ public function process(ContainerBuilder $container)

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

foreach ($container->findTaggedServiceIds('ezpublish_rest.input.parser') as $id => $attributes) {
$taggedServiceIds = $container->findTaggedServiceIds(self::INPUT_PARSER_SERVICE_TAG);
foreach ($taggedServiceIds as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['mediaType'])) {
throw new \LogicException('The ezpublish_rest.input.parser service tag needs a "mediaType" attribute to identify the input parser.');
throw new \LogicException(
sprintf(
'The "%s" service tag needs a "mediaType" attribute to identify the input parser.',
self::INPUT_PARSER_SERVICE_TAG
)
);
}

$definition->addMethodCall(
Expand Down
42 changes: 26 additions & 16 deletions src/bundle/DependencyInjection/Compiler/OutputVisitorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Compiler pass for the ezpublish_rest.output.visitor tag.
* Compiler pass for the ibexa.rest.output.visitor tag.
*
* Maps an output visitor (json, xml...) to an accept-header
*
* @todo The tag is much more limited in scope than the name shows. Refactor. More ways to map ?
*/
class OutputVisitorPass implements CompilerPassInterface
{
public const OUTPUT_VISITOR_SERVICE_TAG = 'ibexa.rest.output.visitor';

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ezpublish_rest.output.visitor.dispatcher')) {
Expand All @@ -30,29 +32,37 @@ public function process(ContainerBuilder $container)

$visitors = [];

foreach ($container->findTaggedServiceIds('ezpublish_rest.output.visitor') as $id => $attributes) {
$taggedServiceIds = $container->findTaggedServiceIds(self::OUTPUT_VISITOR_SERVICE_TAG);
foreach ($taggedServiceIds as $serviceId => $attributes) {
foreach ($attributes as $attribute) {
$priority = isset($attribute['priority']) ? $attribute['priority'] : 0;

if (!isset($attribute['regexps'])) {
throw new \LogicException('The ezpublish_rest.output.visitor service tag needs a "regexps" attribute to identify the Accept header.');
}

if (is_array($attribute['regexps'])) {
$regexps = $attribute['regexps'];
} elseif (is_string($attribute['regexps'])) {
$priority = $attribute['priority'] ?? 0;
$regexps = $attribute['regexps'];
if (is_string($regexps)) {
try {
$regexps = $container->getParameter($attribute['regexps']);
$regexps = $container->getParameter($regexps);
} catch (InvalidArgumentException $e) {
throw new \LogicException("The regexps attribute of the ezpublish_rest.output.visitor service tag can be a string matching a container parameter name. Could not find parameter {$attribute['regexps']}.");
throw new \LogicException(
sprintf(
'Service "%s" tagged with "%s" service tag "regexps" attribute can be a string matching a container parameter name. Could not find parameter "%s".',
$serviceId,
self::OUTPUT_VISITOR_SERVICE_TAG,
$regexps
)
);
}
} else {
throw new \LogicException('The ezpublish_rest.output.visitor service tag needs a "regexps" attribute, either as an array or a string. Invalid value.');
} elseif (!is_array($regexps)) {
throw new \LogicException(
sprintf(
'Service "%s" tagged with "%s" service tag needs a "regexps" attribute to identify the Accept header, either as an array or a string.',
$serviceId,
self::OUTPUT_VISITOR_SERVICE_TAG
)
);
}

$visitors[$priority][] = [
'regexps' => $regexps,
'reference' => new Reference($id),
'reference' => new Reference($serviceId),
];
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/bundle/DependencyInjection/Compiler/ValueObjectVisitorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Compiler pass for the ezpublish_rest.output.value_object_visitor tag.
* Compiler pass for the ibexa.rest.output.value_object.visitor tag.
* Maps an fully qualified class to a value object visitor.
*/
class ValueObjectVisitorPass implements CompilerPassInterface
{
public const OUTPUT_VALUE_OBJECT_VISITOR_SERVICE_TAG = 'ibexa.rest.output.value_object.visitor';

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ezpublish_rest.output.value_object_visitor.dispatcher')) {
Expand All @@ -24,10 +26,18 @@ public function process(ContainerBuilder $container)

$definition = $container->getDefinition('ezpublish_rest.output.value_object_visitor.dispatcher');

foreach ($container->findTaggedServiceIds('ezpublish_rest.output.value_object_visitor') as $id => $attributes) {
$taggedServiceIds = $container->findTaggedServiceIds(
self::OUTPUT_VALUE_OBJECT_VISITOR_SERVICE_TAG
);
foreach ($taggedServiceIds as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['type'])) {
throw new \LogicException('The ezpublish_rest.output.value_object_visitor service tag needs a "type" attribute to identify the field type.');
throw new \LogicException(
sprintf(
'The "%s" service tag needs a "type" attribute to identify the field type.',
self::OUTPUT_VALUE_OBJECT_VISITOR_SERVICE_TAG
)
);
}

$definition->addMethodCall(
Expand Down
Loading