Skip to content

Commit 0bb102f

Browse files
authored
IBX-10708: Introduced SerializerFactory for SiteAccess matchers (#689)
For more details see https://issues.ibexa.co/browse/IBX-10708 and #689 Key changes: * Introduced SerializerFactory and improved serializer config for SiteAccess matchers
1 parent 237c5b0 commit 0bb102f

2 files changed

Lines changed: 88 additions & 33 deletions

File tree

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,82 @@
11
services:
2-
ibexa.core.mvc.serializer:
3-
class: Symfony\Component\Serializer\Serializer
4-
arguments:
5-
$normalizers:
6-
- '@ibexa.core.mvc.serializer.normalizer.array_denormalizer'
7-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\SiteAccessNormalizer'
8-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\MatcherDenormalizer'
9-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\CompoundMatcherNormalizer'
10-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\HostElementNormalizer'
11-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\MapNormalizer'
12-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\URITextNormalizer'
13-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\HostTextNormalizer'
14-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\RegexNormalizer'
15-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\URIElementNormalizer'
16-
- '@Ibexa\Core\MVC\Symfony\Component\Serializer\SimplifiedRequestNormalizer'
17-
- '@ibexa.core.mvc.serializer.normalizer.json_serializable_normalizer'
18-
- '@ibexa.core.mvc.serializer.normalizer.property_normalizer'
19-
$encoders:
20-
- '@ibexa.core.mvc.serializer.json_encoder'
2+
Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface:
3+
alias: Ibexa\Bundle\Core\Fragment\SiteAccessSerializer
4+
215

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

26-
Ibexa\Bundle\Core\Fragment\SiteAccessSerializerInterface:
27-
alias: Ibexa\Bundle\Core\Fragment\SiteAccessSerializer
10+
ibexa.core.mvc.serializer.normalizer.array_denormalizer:
11+
class: Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
12+
tags:
13+
- { name: 'ibexa.core.serializer.normalizer', priority: 1300 }
2814

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

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

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

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

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

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

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

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

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

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

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

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

58-
ibexa.core.mvc.serializer.normalizer.array_denormalizer:
59-
class: Symfony\Component\Serializer\Normalizer\ArrayDenormalizer
67+
ibexa.core.mvc.serializer.json_encoder:
68+
class: Symfony\Component\Serializer\Encoder\JsonEncoder
69+
tags:
70+
- { name: 'ibexa.core.serializer.encoder', priority: 100 }
71+
72+
Ibexa\Bundle\Core\Serializer\SerializerFactory:
73+
class: Ibexa\Bundle\Core\Serializer\SerializerFactory
74+
arguments:
75+
- !tagged_iterator 'ibexa.core.serializer.normalizer'
76+
- !tagged_iterator 'ibexa.core.serializer.encoder'
77+
78+
ibexa.core.mvc.serializer:
79+
# Warning: Do NOT enable autoconfigure for Serializer and Normalizer services.
80+
# They will be tagged with "serializer.normalizer" tag and injected to main app serializer service if done so.
81+
class: Symfony\Component\Serializer\Serializer
82+
factory: [ '@Ibexa\Bundle\Core\Serializer\SerializerFactory', 'create' ]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Bundle\Core\Serializer;
10+
11+
use Symfony\Component\Serializer\Serializer;
12+
13+
final readonly class SerializerFactory
14+
{
15+
/**
16+
* @param iterable<\Symfony\Component\Serializer\Normalizer\NormalizerInterface|\Symfony\Component\Serializer\Normalizer\DenormalizerInterface> $normalizers
17+
* @param iterable<\Symfony\Component\Serializer\Encoder\EncoderInterface|\Symfony\Component\Serializer\Encoder\DecoderInterface> $encoders
18+
*/
19+
public function __construct(
20+
private iterable $normalizers,
21+
private iterable $encoders
22+
) {
23+
}
24+
25+
public function create(): Serializer
26+
{
27+
$normalizers = iterator_to_array($this->normalizers);
28+
$encoders = iterator_to_array($this->encoders);
29+
30+
return new Serializer($normalizers, $encoders);
31+
}
32+
}

0 commit comments

Comments
 (0)