Skip to content

Commit ec68048

Browse files
authored
Merge pull request #302 from jolicode/fix/api-platform-iri-collection
fix(api-platform): fix not returning iri when no property to map
2 parents 71782cd + 4c9e0c5 commit ec68048

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+412
-136
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Changed
1717
- [BC Break] `PropertyTransformerSupportInterface` does not use a `TypesMatching` anymore, you can get the type directly from `SourcePropertyMetadata` or `TargetPropertyMetadata`.
1818

19+
### Fixed
20+
- [GH#303](https://github.com/jolicode/automapper/pull/302) Fix api platform not returning an iri when there is no property mapped.
21+
1922
## [9.5.0] - 2025-09-18
2023
### Added
2124
- [GH#260](https://github.com/jolicode/automapper/pull/260) Add support for identifiers detection and comparison of objects, this allow mappers to detect if objects are equals based on some properties, which allow better deep merge / update of collections.

castor.composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

castor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
#[AsTask('cs:check', namespace: 'qa', description: 'Check for coding standards without fixing them')]
1515
function qa_cs_check()
1616
{
17-
php_cs_fixer(['fix', '--config', __DIR__ . '/.php-cs-fixer.php', '--dry-run', '--diff'], '3.85.1', [
17+
php_cs_fixer(['fix', '--config', __DIR__ . '/.php-cs-fixer.php', '--dry-run', '--diff'], '3.92.3', [
1818
'kubawerlos/php-cs-fixer-custom-fixers' => '^3.21',
1919
]);
2020
}
2121

2222
#[AsTask('cs:fix', namespace: 'qa', description: 'Fix all coding standards', aliases: ['cs'])]
2323
function qa_cs_fix()
2424
{
25-
php_cs_fixer(['fix', '--config', __DIR__ . '/.php-cs-fixer.php', '-v'], '3.85.1', [
25+
php_cs_fixer(['fix', '--config', __DIR__ . '/.php-cs-fixer.php', '-v'], '3.92.3', [
2626
'kubawerlos/php-cs-fixer-custom-fixers' => '^3.21',
2727
]);
2828
}

phpstan-baseline.neon

Lines changed: 0 additions & 81 deletions
This file was deleted.

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
includes:
2-
- phpstan-baseline.neon
3-
41
parameters:
52
level: max
63
paths:

src/EventListener/ApiPlatform/JsonLdListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace AutoMapper\EventListener\ApiPlatform;
66

7-
use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
87
use ApiPlatform\Metadata\HttpOperation;
98
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
109
use ApiPlatform\Metadata\ResourceClassResolverInterface;
@@ -21,7 +20,7 @@
2120
final readonly class JsonLdListener
2221
{
2322
public function __construct(
24-
private ResourceClassResolverInterface|LegacyResourceClassResolverInterface $resourceClassResolver,
23+
private ResourceClassResolverInterface $resourceClassResolver,
2524
private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
2625
) {
2726
}

src/Provider/ApiPlatform/IriProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace AutoMapper\Provider\ApiPlatform;
66

7-
use ApiPlatform\Api\IriConverterInterface as LegacyIriConverterInterface;
8-
use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
97
use ApiPlatform\Metadata\IriConverterInterface;
108
use ApiPlatform\Metadata\ResourceClassResolverInterface;
119
use AutoMapper\MapperContext;
@@ -15,8 +13,8 @@
1513
final readonly class IriProvider implements ProviderInterface
1614
{
1715
public function __construct(
18-
private LegacyIriConverterInterface|IriConverterInterface $iriConverter,
19-
private LegacyResourceClassResolverInterface|ResourceClassResolverInterface $resourceClassResolver,
16+
private IriConverterInterface $iriConverter,
17+
private ResourceClassResolverInterface $resourceClassResolver,
2018
) {
2119
}
2220

src/Symfony/Bundle/Resources/config/api_platform.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use AutoMapper\Provider\ApiPlatform\IriProvider;
1010
use AutoMapper\Transformer\ApiPlatform\JsonLdContextTransformer;
1111
use AutoMapper\Transformer\ApiPlatform\JsonLdIdTransformer;
12+
use AutoMapper\Transformer\ApiPlatform\JsonLdObjectToIdTransformerFactory;
1213

1314
return static function (ContainerConfigurator $container) {
1415
$container->services()
@@ -36,5 +37,12 @@
3637
service('api_platform.resource_class_resolver'),
3738
])
3839
->tag('automapper.provider', ['priority' => 0])
40+
41+
->set(JsonLdObjectToIdTransformerFactory::class)
42+
->args([
43+
service('api_platform.resource_class_resolver'),
44+
service('serializer.mapping.class_metadata_factory'),
45+
])
46+
->tag('automapper.transformer_factory', ['priority' => -1003])
3947
;
4048
};

src/Symfony/Bundle/Resources/config/transformers.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@
5353
->tag('automapper.transformer_factory', ['priority' => -1002])
5454

5555
->set(ObjectTransformerFactory::class)
56-
->tag('automapper.transformer_factory', ['priority' => -1003])
56+
->tag('automapper.transformer_factory', ['priority' => -1004])
5757

5858
->set(EnumTransformerFactory::class)
59-
->tag('automapper.transformer_factory', ['priority' => -1004])
59+
->tag('automapper.transformer_factory', ['priority' => -1005])
6060

6161
->set(MixedTransformerFactory::class)
62-
->tag('automapper.transformer_factory', ['priority' => -1005])
62+
->tag('automapper.transformer_factory', ['priority' => -1006])
6363

6464
->set(CopyTransformerFactory::class)
65-
->tag('automapper.transformer_factory', ['priority' => -1006])
65+
->tag('automapper.transformer_factory', ['priority' => -1007])
6666

6767
->set(SymfonyUidTransformerFactory::class)
6868
;

src/Transformer/AbstractArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828

2929
abstract protected function getAssignExpr(Expr $valuesVar, Expr $outputVar, Expr $loopKeyVar, bool $assignByRef): Expr;
3030

31-
public function transform(Expr $input, Expr $target, PropertyMetadata $propertyMapping, UniqueVariableScope $uniqueVariableScope, Expr\Variable $source, ?Expr $existingValue = null): array
31+
public function transform(Expr $input, Expr $target, PropertyMetadata $propertyMapping, UniqueVariableScope $uniqueVariableScope, Expr $source, ?Expr $existingValue = null): array
3232
{
3333
/**
3434
* $values = [];.

0 commit comments

Comments
 (0)