diff --git a/composer.json b/composer.json index c6cadae..e2008e6 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "embed/embed": "^4.4", "gedmo/doctrine-extensions": "^3.22", "goteo/benzina": "^0.5", - "jolicode/automapper": "9.2.1", + "jolicode/automapper": "^9.2.1", "knpuniversity/oauth2-client-bundle": "^2.20", "league/oauth2-google": "^4.2", "league/oauth2-server-bundle": "^1.1", diff --git a/composer.lock b/composer.lock index dfb8370..67837da 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c9934f062d83166c059c878d97911455", + "content-hash": "011dd61a2a473aef06ca6b082b3ea49b", "packages": [ { "name": "api-platform/doctrine-common", @@ -3566,22 +3566,23 @@ }, { "name": "jolicode/automapper", - "version": "9.2.1", + "version": "9.5.1", "source": { "type": "git", "url": "https://github.com/jolicode/automapper.git", - "reference": "e10d695f396501eea4f0b6a4373e6cb7b2b5b9c8" + "reference": "e55b2acfe5a09295b9d3e7e69e09ebfb113f86b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jolicode/automapper/zipball/e10d695f396501eea4f0b6a4373e6cb7b2b5b9c8", - "reference": "e10d695f396501eea4f0b6a4373e6cb7b2b5b9c8", + "url": "https://api.github.com/repos/jolicode/automapper/zipball/e55b2acfe5a09295b9d3e7e69e09ebfb113f86b2", + "reference": "e55b2acfe5a09295b9d3e7e69e09ebfb113f86b2", "shasum": "" }, "require": { - "nikic/php-parser": "^4.18 || ^5.0", + "composer-runtime-api": "^2.1 || ^3.0", + "nikic/php-parser": "^5.0", "php": "^8.2", - "phpdocumentor/type-resolver": "^1.7", + "phpdocumentor/type-resolver": "^1.7 || ^2.0", "phpstan/phpdoc-parser": "^1.13 || ^2.0", "symfony/deprecation-contracts": "^3.0", "symfony/event-dispatcher": "^6.4 || ^7.0", @@ -3596,22 +3597,28 @@ "symfony/serializer": "<6.4" }, "require-dev": { - "api-platform/core": "^3.0.4", - "doctrine/annotations": "~1.0", + "api-platform/core": "^3.0.4 || ^4", + "doctrine/annotations": "^2.0", + "doctrine/collections": "^2.2", + "doctrine/doctrine-bundle": "^2.15", "doctrine/inflector": "^2.0", + "doctrine/orm": "^2.0 || ^3.0", "matthiasnoback/symfony-dependency-injection-test": "^5.1", "moneyphp/money": "^3.3.2", "phpunit/phpunit": "^9.0", "symfony/browser-kit": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", "symfony/filesystem": "^6.4 || ^7.0", + "symfony/finder": "^6.4 || ^7.2", "symfony/framework-bundle": "*", "symfony/http-client": "^6.4 || ^7.0", "symfony/http-kernel": "^6.4 || ^7.0", - "symfony/serializer": "*", + "symfony/serializer": "^6.4 || ^7.0", "symfony/stopwatch": "^6.4 || ^7.0", "symfony/twig-bundle": "^6.4 || ^7.0", "symfony/uid": "^6.4 || ^7.0", + "symfony/var-dumper": "^6.4 || ^7.2", + "symfony/var-exporter": "^6.4 || ^7.0", "symfony/web-profiler-bundle": "^6.4 || ^7.0", "symfony/yaml": "^6.4 || ^7.0", "willdurand/negotiation": "^3.0" @@ -3646,9 +3653,9 @@ "homepage": "https://github.com/jolicode/automapper", "support": { "issues": "https://github.com/jolicode/automapper/issues", - "source": "https://github.com/jolicode/automapper/tree/9.2.1" + "source": "https://github.com/jolicode/automapper/tree/9.5.1" }, - "time": "2025-01-31T09:15:50+00:00" + "time": "2026-04-27T08:29:10+00:00" }, { "name": "knpuniversity/oauth2-client-bundle", diff --git a/src/Mapping/AutoMapper.php b/src/Mapping/AutoMapper.php index d63aedd..2f33b32 100644 --- a/src/Mapping/AutoMapper.php +++ b/src/Mapping/AutoMapper.php @@ -13,6 +13,7 @@ class AutoMapper implements AutoMapperInterface public const DEFAULT_CONTEXT = [ MapperContext::DEPTH => 1, MapperContext::SKIP_NULL_VALUES => true, + MapperContext::SKIP_UNINITIALIZED_VALUES => true, ]; private AutoMapperInterface $innerMapper; @@ -31,11 +32,17 @@ class AutoMapper implements AutoMapperInterface public function map(array|object $source, string|array|object $target, array $context = []): array|object|null { - $context = [ + return $this->innerMapper->map($source, $target, [ ...self::DEFAULT_CONTEXT, ...$context, - ]; + ]); + } - return $this->innerMapper->map($source, $target, $context); + public function mapCollection(iterable $collection, string $target, array $context = []): array + { + return $this->innerMapper->mapCollection($collection, $target, [ + ...self::DEFAULT_CONTEXT, + ...$context, + ]); } } diff --git a/src/State/Accounting/AccountingStateProvider.php b/src/State/Accounting/AccountingStateProvider.php index d8260d0..6c1bfe1 100644 --- a/src/State/Accounting/AccountingStateProvider.php +++ b/src/State/Accounting/AccountingStateProvider.php @@ -26,11 +26,7 @@ class AccountingStateProvider implements ProviderInterface { if ($operation instanceof CollectionOperationInterface) { $accountings = $this->collectionProvider->provide($operation, $uriVariables, $context); - - $resources = []; - foreach ($accountings as $accounting) { - $resources[] = $this->autoMapper->map($accounting, AccountingApiResource::class); - } + $resources = $this->autoMapper->mapCollection($accountings, AccountingApiResource::class); return new TraversablePaginator( new \ArrayIterator($resources), diff --git a/src/State/ApiResourceStateProvider.php b/src/State/ApiResourceStateProvider.php index 9b41b71..bd73a7d 100644 --- a/src/State/ApiResourceStateProvider.php +++ b/src/State/ApiResourceStateProvider.php @@ -27,11 +27,7 @@ class ApiResourceStateProvider implements ProviderInterface if ($operation instanceof CollectionOperationInterface) { $collection = $this->collectionProvider->provide($operation, $uriVariables, $context); - - $resources = []; - foreach ($collection as $item) { - $resources[] = $this->autoMapper->map($item, $resourceClass); - } + $resources = $this->autoMapper->mapCollection($collection, $resourceClass); return new TraversablePaginator( new \ArrayIterator($resources),