Skip to content
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
89 changes: 56 additions & 33 deletions src/bundle/Core/Resources/config/routing/serializers.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,82 @@
services:
ibexa.core.mvc.serializer:
class: Symfony\Component\Serializer\Serializer
arguments:
$normalizers:
- '@ibexa.core.mvc.serializer.normalizer.array_denormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\SiteAccessNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\MatcherDenormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\CompoundMatcherNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\MapNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\RegexNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\URIElementNormalizer'
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\SimplifiedRequestNormalizer'
- '@ibexa.core.mvc.serializer.normalizer.json_serializable_normalizer'
- '@ibexa.core.mvc.serializer.normalizer.property_normalizer'
$encoders:
- '@ibexa.core.mvc.serializer.json_encoder'
Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface:
alias: Ibexa\Bundle\Core\Fragment\SiteAccessSerializer


Ibexa\Bundle\Core\Fragment\SiteAccessSerializer:
arguments:
$serializer: '@ibexa.core.mvc.serializer'

Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface:
alias: Ibexa\Bundle\Core\Fragment\SiteAccessSerializer
ibexa.core.mvc.serializer.normalizer.array_denormalizer:
class: Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 1300 }

ibexa.core.mvc.serializer.json_encoder:
class: Symfony\Component\Serializer\Encoder\JsonEncoder
Ibexa\Core\MVC\Symfony\Component\Serializer\SiteAccessNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 1200 }

Ibexa\Core\MVC\Symfony\Component\Serializer\MatcherDenormalizer:
arguments:
$registry: '@Ibexa\Bundle\Core\SiteAccess\SiteAccessMatcherRegistryInterface'
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 1100 }

Ibexa\Core\MVC\Symfony\Component\Serializer\SiteAccessNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\CompoundMatcherNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 1000 }

Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 900 }

Ibexa\Core\MVC\Symfony\Component\Serializer\MapNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\MapNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 800 }

Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 700 }

Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 600 }

Ibexa\Core\MVC\Symfony\Component\Serializer\RegexNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\RegexNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 500 }

Ibexa\Core\MVC\Symfony\Component\Serializer\URIElementNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\URIElementNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 400 }

Ibexa\Core\MVC\Symfony\Component\Serializer\SimplifiedRequestNormalizer: ~
Ibexa\Core\MVC\Symfony\Component\Serializer\SimplifiedRequestNormalizer:
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 300 }

ibexa.core.mvc.serializer.normalizer.json_serializable_normalizer:
class: Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 200 }

ibexa.core.mvc.serializer.normalizer.property_normalizer:
class: Symfony\Component\Serializer\Normalizer\PropertyNormalizer
tags:
- { name: 'ibexa.core.serializer.normalizer', priority: 100 }

ibexa.core.mvc.serializer.normalizer.array_denormalizer:
class: Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
ibexa.core.mvc.serializer.json_encoder:
class: Symfony\Component\Serializer\Encoder\JsonEncoder
tags:
- { name: 'ibexa.core.serializer.encoder', priority: 100 }

Ibexa\Bundle\Core\Serializer\SerializerFactory:
class: Ibexa\Bundle\Core\Serializer\SerializerFactory
arguments:
- !tagged_iterator 'ibexa.core.serializer.normalizer'
- !tagged_iterator 'ibexa.core.serializer.encoder'

ibexa.core.mvc.serializer:
# Warning: Do NOT enable autoconfigure for Serializer and Normalizer services.
# They will be tagged with "serializer.normalizer" tag and injected to main app serializer service if done so.
Comment on lines +79 to +80
Copy link
Member

Choose a reason for hiding this comment

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

This should be checked via container tests. It's easy to add _defaults on top of the file and miss that comment ;)

class: Symfony\Component\Serializer\Serializer
factory: [ '@Ibexa\Bundle\Core\Serializer\SerializerFactory', 'create' ]
32 changes: 32 additions & 0 deletions src/bundle/Core/Serializer/SerializerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

namespace Ibexa\Bundle\Core\Serializer;

use Symfony\Component\Serializer\Serializer;

final readonly class SerializerFactory
{
/**
* @param iterable<\Symfony\Component\Serializer\Normalizer\NormalizerInterface|\Symfony\Component\Serializer\Normalizer\DenormalizerInterface> $normalizers
* @param iterable<\Symfony\Component\Serializer\Encoder\EncoderInterface|\Symfony\Component\Serializer\Encoder\DecoderInterface> $encoders
*/
public function __construct(
private iterable $normalizers,
private iterable $encoders
) {
}

public function create(): Serializer
{
$normalizers = iterator_to_array($this->normalizers);
$encoders = iterator_to_array($this->encoders);

return new Serializer($normalizers, $encoders);
}
}
Loading