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-8190: Add Symfony's Serializer support #121

Open
wants to merge 110 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
254ed51
Add Symfony's Serializer support
barw4 Aug 12, 2024
af71b38
Add `AdapterNormalizer`
barw4 Aug 22, 2024
10e8d14
Remove `ValueObjectVisitorDispatcher`
barw4 Aug 23, 2024
1fc9964
Rollback
barw4 Aug 23, 2024
ddc4a04
Rollback
barw4 Aug 23, 2024
cc4445c
Rollback
barw4 Aug 23, 2024
230ca38
Fixup
barw4 Aug 23, 2024
9392805
Applied review remarks
barw4 Aug 27, 2024
52da6b1
Code cleanup
barw4 Aug 27, 2024
3424a8c
Code cleanup
barw4 Aug 27, 2024
249d489
Code cleanup
barw4 Aug 27, 2024
4209e63
Fixup
barw4 Aug 27, 2024
4984b5f
Change login code to 200
barw4 Aug 27, 2024
df8eb96
Set proper encoding format
barw4 Aug 28, 2024
8154a71
Handle XML
barw4 Sep 4, 2024
7095971
Rollback
barw4 Sep 4, 2024
871bcdd
Rollback
barw4 Sep 4, 2024
4b1aae2
Use dispatched visitor instead of creating a new one
barw4 Sep 4, 2024
f741514
Reuse already initialized visitor
barw4 Sep 5, 2024
d1c1585
Fixup
barw4 Sep 5, 2024
e75bdcb
Fix PHPStan issues
barw4 Sep 5, 2024
655164e
Fixups
barw4 Sep 5, 2024
35b1d5a
Fixups
barw4 Sep 6, 2024
b4c519e
Make unit tests use the new XML generator
barw4 Oct 1, 2024
de79944
Rollback
barw4 Oct 1, 2024
8340f2c
Stan
barw4 Oct 1, 2024
d0da344
Made `transformData` method private
Steveb-p Oct 2, 2024
a08ec36
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
28ace81
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
94fb737
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
bbf6730
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
a44e132
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
d890381
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
cc1ef85
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
ea3ffa5
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
8975898
Add Symfony's Serializer support
barw4 Aug 12, 2024
67da09a
Add `AdapterNormalizer`
barw4 Aug 22, 2024
6c37b33
Remove `ValueObjectVisitorDispatcher`
barw4 Aug 23, 2024
b45a1a7
Rollback
barw4 Aug 23, 2024
ab65a12
Rollback
barw4 Aug 23, 2024
03ae7b4
Rollback
barw4 Aug 23, 2024
2c8a0b9
Fixup
barw4 Aug 23, 2024
bf65ee5
Applied review remarks
barw4 Aug 27, 2024
f7d9969
Code cleanup
barw4 Aug 27, 2024
e9cce3e
Code cleanup
barw4 Aug 27, 2024
b5c4d9a
Code cleanup
barw4 Aug 27, 2024
bd06a72
Fixup
barw4 Aug 27, 2024
4c4b86d
Change login code to 200
barw4 Aug 27, 2024
93612b8
Set proper encoding format
barw4 Aug 28, 2024
adda1b1
Handle XML
barw4 Sep 4, 2024
b9c5391
Rollback
barw4 Sep 4, 2024
a8b2157
Rollback
barw4 Sep 4, 2024
f0aa85f
Use dispatched visitor instead of creating a new one
barw4 Sep 4, 2024
6342b45
Reuse already initialized visitor
barw4 Sep 5, 2024
6372caf
Fixup
barw4 Sep 5, 2024
9a5a349
Fix PHPStan issues
barw4 Sep 5, 2024
d1dc2f5
Fixups
barw4 Sep 5, 2024
bba7bee
Fixups
barw4 Sep 6, 2024
49a5636
Make unit tests use the new XML generator
barw4 Oct 1, 2024
eaeaa1b
Rollback
barw4 Oct 1, 2024
04aee52
Made `transformData` method private
Steveb-p Oct 2, 2024
3b26a12
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
cc786e6
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
2339c0a
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
7a2b8b0
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
ea3905c
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
c569ae9
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
7637fd2
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
a69b955
Introduced normalizers for Generator state
Steveb-p Oct 8, 2024
ffb1072
Update Generator normalizers
barw4 Oct 10, 2024
7ec9272
Generate baseline
barw4 Oct 10, 2024
8d80d19
Refactor encoder context
barw4 Oct 10, 2024
726b5ea
Handle empty `ArrayList` object
barw4 Oct 10, 2024
5c58b4b
`outer_element` context item
barw4 Oct 10, 2024
ff10aa9
Remove dependencies to old Xml generator
barw4 Oct 15, 2024
0662f93
Remove old Xml generator
barw4 Oct 15, 2024
76ee06c
CS
barw4 Oct 15, 2024
fdff4b4
Update services.yml
barw4 Oct 16, 2024
bdbab45
Rollback
barw4 Oct 16, 2024
8e4e6aa
Implement integration tests
barw4 Oct 18, 2024
e7fd050
Fixup
barw4 Oct 18, 2024
5406419
CS
barw4 Oct 18, 2024
19842a4
Fixup
barw4 Oct 18, 2024
0e2349b
Fix tests
barw4 Oct 21, 2024
aeede99
Fixup
barw4 Oct 21, 2024
e26c28c
Cleanup generators
barw4 Oct 23, 2024
a188b1c
PHPStan
barw4 Oct 23, 2024
44edd9e
CS
barw4 Oct 23, 2024
793d2c6
Remove comment
barw4 Oct 23, 2024
004a4dd
Clean up field generators
barw4 Oct 24, 2024
6ee5023
PHPStan
barw4 Oct 24, 2024
0f81414
Applied review remarks
barw4 Nov 4, 2024
a337960
Applied review remark
barw4 Nov 4, 2024
1345c33
Applied review remarks
barw4 Nov 4, 2024
b720b5e
Response code as const
barw4 Nov 18, 2024
e1e8b59
PHPStan
barw4 Nov 18, 2024
0758b0b
PHPDoc
barw4 Nov 26, 2024
bf372bd
PHPStan
barw4 Nov 26, 2024
7e710c6
Applied review remarks
barw4 Nov 26, 2024
fb81943
IBX-8190: Added `Symfony\Component\Serializer\Normalizer\ObjectNormal…
barw4 Jan 8, 2025
5c58750
IBX-8190: Fixup
barw4 Jan 8, 2025
5219ed2
IBX-8190: Handle unexpected exceptions
barw4 Jan 8, 2025
bc4cc96
IBX-8190: Allow integers as object names
barw4 Jan 8, 2025
070ea44
IBX-8190: Regenerate baseline
barw4 Jan 8, 2025
e6f2b87
IBX-8190: Force XML generator to not lose information about value's name
barw4 Jan 9, 2025
9bf9cc3
IBX-8190: Added the `ArrayListNormalizerTest` unit test
barw4 Jan 9, 2025
34f7c5b
Add required normalizers
barw4 Jan 17, 2025
301542f
Remove `NativeArrayObjectNormalizer`
barw4 Jan 17, 2025
846eedf
Convert `false` to `null` in Xml Generator
barw4 Jan 17, 2025
9322522
Lower priority of the `JsonSerializableNormalizer`
barw4 Jan 22, 2025
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
789 changes: 17 additions & 772 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@
* @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\Rest\DependencyInjection\Compiler;

use Ibexa\Contracts\Rest\Output\ValueObjectVisitorDispatcher;
use Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

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

public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition(ValueObjectVisitorDispatcher::class)) {
if (!$container->hasDefinition(ValueObjectVisitorResolver::class)) {
return;
}

$definition = $container->getDefinition(ValueObjectVisitorDispatcher::class);
$definition = $container->getDefinition(ValueObjectVisitorResolver::class);

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

foreach ($taggedServiceIds as $id => $attributes) {
foreach ($attributes as $attribute) {
if (!isset($attribute['type'])) {
Expand Down
1 change: 1 addition & 0 deletions src/bundle/DependencyInjection/IbexaRestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
$loader->load('input_parsers.yml');
$loader->load('security.yml');
$loader->load('default_settings.yml');
$loader->load('serializer.yaml');

$processor = new ConfigurationProcessor($container, 'ibexa.site_access.config');
$processor->mapConfigArray('rest_root_resources', $mergedConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/IbexaRestBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new Compiler\InputHandlerPass());
$container->addCompilerPass(new Compiler\InputParserPass());
$container->addCompilerPass(new Compiler\OutputVisitorPass());
$container->addCompilerPass(new Compiler\ValueObjectVisitorPass());
$container->addCompilerPass(new Compiler\ValueObjectVisitorResolverPass());

if ($container->hasExtension('lexik_jwt_authentication')) {
$container->addCompilerPass(new Compiler\LexikAuthorizationHeaderBridgePass());
Expand Down
39 changes: 39 additions & 0 deletions src/bundle/Resources/config/serializer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
services:
ibexa.rest.serializer.encoder.json:
class: Symfony\Component\Serializer\Encoder\JsonEncoder
tags:
- ibexa.rest.serializer.encoder

ibexa.rest.serializer.encoder.xml:
class: Symfony\Component\Serializer\Encoder\XmlEncoder
tags:
- ibexa.rest.serializer.encoder

Ibexa\Contracts\Rest\Output\VisitorAdapterNormalizer:
arguments:
$jsonEncoder: '@ibexa.rest.serializer.encoder.json'
$xmlEncoder: '@ibexa.rest.serializer.encoder.xml'
$valueObjectVisitorResolver: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver'
tags:
- { name: ibexa.rest.serializer.normalizer, priority: -1000 }

Ibexa\Rest\Output\Normalizer\JsonObjectNormalizer:
tags:
- { name: ibexa.rest.serializer.normalizer, priority: -500 }

Ibexa\Rest\Output\Normalizer\ArrayListNormalizer:
tags:
- { name: ibexa.rest.serializer.normalizer, priority: -400 }

Ibexa\Rest\Output\Normalizer\ArrayObjectNormalizer:
tags:
- { name: ibexa.rest.serializer.normalizer, priority: -400 }

Ibexa\Rest\Output\Normalizer\JsonSerializableNormalizer:
tags:
- { name: ibexa.rest.serializer.normalizer, priority: -500 }

ibexa.rest.serializer.object_normalizer:
class: Symfony\Component\Serializer\Normalizer\ObjectNormalizer
tags:
- { name: ibexa.rest.serializer.normalizer, priority: -1000 }
25 changes: 15 additions & 10 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ services:
- '@ibexa.api.service.section'
- '@ibexa.api.repository'
- '@Ibexa\Contracts\Core\Repository\PermissionResolver'
- '@Ibexa\Contracts\Core\Repository\ContentService\RelationListFacadeInterface'
tags: [controller.service_arguments]

Ibexa\Rest\Server\Controller\URLWildcard:
Expand Down Expand Up @@ -316,25 +315,29 @@ services:
ibexa.rest.output.visitor.json:
class: Ibexa\Contracts\Rest\Output\Visitor
arguments:
- '@Ibexa\Rest\Output\Generator\Json'
- '@Ibexa\Contracts\Rest\Output\ValueObjectVisitorDispatcher'
$generator: '@Ibexa\Rest\Output\Generator\Json'
$normalizer: '@ibexa.rest.serializer'
$encoder: '@ibexa.rest.serializer.encoder.json'
$valueObjectVisitorResolver: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver'
$format: 'json'
tags:
- { name: ibexa.rest.output.visitor, regexps: ibexa.rest.output.visitor.json.regexps }

ibexa.rest.output.visitor.xml:
class: Ibexa\Contracts\Rest\Output\Visitor
arguments:
- '@Ibexa\Rest\Output\Generator\Xml'
- '@Ibexa\Contracts\Rest\Output\ValueObjectVisitorDispatcher'
$generator: '@Ibexa\Rest\Output\Generator\Xml'
$normalizer: '@ibexa.rest.serializer'
$encoder: '@ibexa.rest.serializer.encoder.xml'
$valueObjectVisitorResolver: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver'
$format: 'xml'
tags:
- { name: ibexa.rest.output.visitor, regexps: ibexa.rest.output.visitor.xml.regexps }

# format output generators
Ibexa\Rest\Output\Generator\Xml:
arguments:
- '@Ibexa\Rest\Output\Generator\Xml\FieldTypeHashGenerator'
calls:
- [ setFormatOutput, [ "%kernel.debug%" ] ]
$fieldTypeHashGenerator: '@Ibexa\Rest\Output\Generator\Xml\FieldTypeHashGenerator'

Ibexa\Rest\Output\Generator\Xml\FieldTypeHashGenerator:
arguments:
Expand All @@ -359,8 +362,6 @@ services:
- { name: monolog.logger, channel: ibexa.rest }

# value objects visitors
Ibexa\Contracts\Rest\Output\ValueObjectVisitorDispatcher: ~

ibexa.rest.output.value_object_visitor.Exception.InvalidArgumentException:
class: Ibexa\Rest\Server\Output\ValueObjectVisitor\InvalidArgumentException
tags:
Expand Down Expand Up @@ -404,6 +405,10 @@ services:
arguments:
$parsingDispatcher: '@Ibexa\Contracts\Rest\Input\ParsingDispatcher'

Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolverInterface: '@Ibexa\Contracts\Rest\Output\ValueObjectVisitor'

Ibexa\Contracts\Rest\Output\ValueObjectVisitorResolver: ~

Ibexa\Contracts\Rest\Input\Parser\Query\SortClause\BaseSortClauseProcessor:
abstract: true
arguments:
Expand Down
Loading
Loading