From f6e3815d5f67f1eb6b5a2d93817f949ace248383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Skowro=C5=84ski?= Date: Mon, 15 Jan 2024 15:16:59 +0100 Subject: [PATCH 1/2] Update Api Platform to 3.2 --- composer.json | 2 +- composer.lock | 142 +++++++++++++++--------------- config/bundles.php | 2 +- config/packages/api_platform.yaml | 41 +++------ symfony.lock | 8 +- 5 files changed, 89 insertions(+), 106 deletions(-) diff --git a/composer.json b/composer.json index 32c25ce6..66fb61ac 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "ext-ctype": "*", "ext-dom": "*", "ext-iconv": "*", - "api-platform/core": "^2.7", + "api-platform/core": "^3.2", "discord-php/http": "^10.3", "doctrine/doctrine-bundle": "^2.11", "doctrine/doctrine-fixtures-bundle": "^3.4", diff --git a/composer.lock b/composer.lock index 86fd84c3..1e4868b5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,111 +4,116 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1e90f5c74d11f73dd09192325ccba7e4", + "content-hash": "3b63d54c8360bc5a5ba524bd63522bf8", "packages": [ { "name": "api-platform/core", - "version": "v2.7.15", + "version": "v3.2.11", "source": { "type": "git", "url": "https://github.com/api-platform/core.git", - "reference": "dd433f76da60819cd01278b54e4fb70283302aa8" + "reference": "227c85871b00613f427ea985b54f4af24ce56a29" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/api-platform/core/zipball/dd433f76da60819cd01278b54e4fb70283302aa8", - "reference": "dd433f76da60819cd01278b54e4fb70283302aa8", + "url": "https://api.github.com/repos/api-platform/core/zipball/227c85871b00613f427ea985b54f4af24ce56a29", + "reference": "227c85871b00613f427ea985b54f4af24ce56a29", "shasum": "" }, "require": { "doctrine/inflector": "^1.0 || ^2.0", - "php": ">=7.1", + "php": ">=8.1", "psr/cache": "^1.0 || ^2.0 || ^3.0", "psr/container": "^1.0 || ^2.0", - "symfony/deprecation-contracts": "^2.1 || ^3.0", - "symfony/http-foundation": "^4.4 || ^5.1 || ^6.0", - "symfony/http-kernel": "^4.4 || ^5.1 || ^6.0", - "symfony/property-access": "^3.4.19 || ^4.4 || ^5.1 || ^6.0", - "symfony/property-info": "^3.4 || ^4.4 || ^5.2.1 || ^6.0", - "symfony/serializer": "^4.4 || ^5.1 || ^6.0", - "symfony/web-link": "^4.4 || ^5.1 || ^6.0", - "willdurand/negotiation": "^2.0.3 || ^3.0" + "symfony/deprecation-contracts": "^3.1", + "symfony/http-foundation": "^6.1 || ^7.0", + "symfony/http-kernel": "^6.1 || ^7.0", + "symfony/property-access": "^6.1 || ^7.0", + "symfony/property-info": "^6.1 || ^7.0", + "symfony/serializer": "^6.1 || ^7.0", + "symfony/translation-contracts": "^3.3", + "symfony/web-link": "^6.1 || ^7.0", + "willdurand/negotiation": "^3.0" }, "conflict": { - "doctrine/common": "<2.7", + "doctrine/common": "<3.2.2", "doctrine/dbal": "<2.10", - "doctrine/mongodb-odm": "<2.2", + "doctrine/mongodb-odm": "<2.4", + "doctrine/orm": "<2.14.0", "doctrine/persistence": "<1.3", - "elasticsearch/elasticsearch": ">=8.0" + "elasticsearch/elasticsearch": ">=8.0,<8.4", + "phpspec/prophecy": "<1.15", + "phpunit/phpunit": "<9.5", + "symfony/var-exporter": "<6.1.1" }, "require-dev": { - "behat/behat": "^3.1", - "behat/mink": "^1.9@dev", - "doctrine/annotations": "^1.7", + "behat/behat": "^3.11", + "behat/mink": "^1.9", "doctrine/cache": "^1.11 || ^2.1", - "doctrine/common": "^2.11 || ^3.0", - "doctrine/data-fixtures": "^1.2.2", - "doctrine/dbal": "^2.6 || ^3.0", + "doctrine/common": "^3.2.2", + "doctrine/dbal": "^3.4.0", "doctrine/doctrine-bundle": "^1.12 || ^2.0", "doctrine/mongodb-odm": "^2.2", - "doctrine/mongodb-odm-bundle": "^4.0", - "doctrine/orm": "^2.6.4", - "elasticsearch/elasticsearch": "^7.11.0", + "doctrine/orm": "^2.14", + "elasticsearch/elasticsearch": "^7.11 || ^8.4", "friends-of-behat/mink-browserkit-driver": "^1.3.1", "friends-of-behat/mink-extension": "^2.2", "friends-of-behat/symfony-extension": "^2.1", "guzzlehttp/guzzle": "^6.0 || ^7.0", "jangregor/phpstan-prophecy": "^1.0", "justinrainbow/json-schema": "^5.2.1", - "phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.1", - "phpdocumentor/type-resolver": "^0.3 || ^0.4 || ^1.4", - "phpspec/prophecy": "^1.10", + "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.1", + "phpstan/phpdoc-parser": "^1.13", "phpstan/phpstan": "^1.1", "phpstan/phpstan-doctrine": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-symfony": "^1.0", + "phpunit/phpunit": "^9.5", "psr/log": "^1.0 || ^2.0 || ^3.0", - "ramsey/uuid": "^3.7 || ^4.0", - "ramsey/uuid-doctrine": "^1.4", - "soyuka/contexts": "^3.3.6", + "ramsey/uuid": "^3.9.7 || ^4.0", + "ramsey/uuid-doctrine": "^1.4 || ^2.0", + "sebastian/comparator": "<5.0", + "soyuka/contexts": "v3.3.9", "soyuka/stubs-mongodb": "^1.0", - "symfony/asset": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/browser-kit": "^4.4 || ^5.1 || ^6.0", - "symfony/cache": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/config": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/console": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/css-selector": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/debug": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/dependency-injection": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/doctrine-bridge": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/dom-crawler": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/expression-language": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/finder": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/form": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/framework-bundle": "^4.4 || ^5.1 || ^6.0", - "symfony/http-client": "^4.4 || ^5.1 || ^6.0", - "symfony/intl": "^4.4 || ^5.3 || ^6.0", + "symfony/asset": "^6.1 || ^7.0", + "symfony/browser-kit": "^6.1 || ^7.0", + "symfony/cache": "^6.1 || ^7.0", + "symfony/config": "^6.1 || ^7.0", + "symfony/console": "^6.1 || ^7.0", + "symfony/css-selector": "^6.1 || ^7.0", + "symfony/dependency-injection": "^6.1 || ^7.0.12", + "symfony/doctrine-bridge": "^6.1 || ^7.0", + "symfony/dom-crawler": "^6.1 || ^7.0", + "symfony/error-handler": "^6.1 || ^7.0", + "symfony/event-dispatcher": "^6.1 || ^7.0", + "symfony/expression-language": "^6.1 || ^7.0", + "symfony/finder": "^6.1 || ^7.0", + "symfony/form": "^6.1 || ^7.0", + "symfony/framework-bundle": "^6.1 || ^7.0", + "symfony/http-client": "^6.1 || ^7.0", + "symfony/intl": "^6.1 || ^7.0", "symfony/maker-bundle": "^1.24", "symfony/mercure-bundle": "*", - "symfony/messenger": "^4.4 || ^5.1 || ^6.0", - "symfony/phpunit-bridge": "^5.4 || ^6.0", - "symfony/routing": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/security-bundle": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/security-core": "^4.4 || ^5.1 || ^6.0", - "symfony/twig-bundle": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/validator": "^3.4 || ^4.4 || ^5.1 || ^6.0", - "symfony/web-profiler-bundle": "^4.4 || ^5.1 || ^6.0", - "symfony/yaml": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/messenger": "^6.1 || ^7.0", + "symfony/phpunit-bridge": "^6.1 || ^7.0", + "symfony/routing": "^6.1 || ^7.0", + "symfony/security-bundle": "^6.1 || ^7.0", + "symfony/security-core": "^6.1 || ^7.0", + "symfony/stopwatch": "^6.1 || ^7.0", + "symfony/twig-bundle": "^6.1 || ^7.0", + "symfony/uid": "^6.1 || ^7.0", + "symfony/validator": "^6.1 || ^7.0", + "symfony/web-profiler-bundle": "^6.1 || ^7.0", + "symfony/yaml": "^6.1 || ^7.0", "twig/twig": "^1.42.3 || ^2.12 || ^3.0", - "webonyx/graphql-php": "^14.0" + "webonyx/graphql-php": "^14.0 || ^15.0" }, "suggest": { "doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.", "elasticsearch/elasticsearch": "To support Elasticsearch.", "ocramius/package-versions": "To display the API Platform's version in the debug bar.", - "phpdocumentor/reflection-docblock": "To support extracting metadata from PHPDoc.", + "phpstan/phpdoc-parser": "To support extracting metadata from PHPDoc.", "psr/cache-implementation": "To use metadata caching.", "ramsey/uuid": "To support Ramsey's UUID identifiers.", "symfony/cache": "To have metadata caching when using Symfony integration.", @@ -125,16 +130,13 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.7.x-dev" + "dev-main": "3.3.x-dev" }, "symfony": { - "require": "^3.4 || ^4.4 || ^5.1 || ^6.0" + "require": "^6.1 || ^7.0" } }, "autoload": { - "files": [ - "src/deprecation.php" - ], "psr-4": { "ApiPlatform\\": "src/" } @@ -165,15 +167,9 @@ ], "support": { "issues": "https://github.com/api-platform/core/issues", - "source": "https://github.com/api-platform/core/tree/v2.7.15" + "source": "https://github.com/api-platform/core/tree/v3.2.11" }, - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/api-platform/core", - "type": "tidelift" - } - ], - "time": "2023-08-11T14:04:22+00:00" + "time": "2024-01-12T13:17:28+00:00" }, { "name": "brick/math", diff --git a/config/bundles.php b/config/bundles.php index 8fe03843..044fd770 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -15,6 +15,6 @@ KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle::class => ['all' => true], FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true], Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], - ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], + ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], ]; diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index 69eb5300..4d0c3f7f 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -1,31 +1,18 @@ -imports: - - { resource: ../api_platform/filters/ } - api_platform: - title: "%app.api.name%" - version: "%app.api.version%" - show_webby: false - swagger: - versions: [3] - api_keys: - apiKey: - name: '%env(APP_SECURITY_API_KEY_HEADER_NAME)%' - type: header - - path_segment_name_generator: api_platform.path_segment_name_generator.dash - mapping: - paths: ['%kernel.project_dir%/config/api_platform/resources'] - patch_formats: - json: ['application/merge-patch+json'] + title: Hello API Platform + version: 1.0.0 formats: - json: ['application/json'] + jsonld: ['application/ld+json'] + docs_formats: + jsonld: ['application/ld+json'] + jsonopenapi: ['application/vnd.openapi+json'] html: ['text/html'] - defaults: - pagination_enabled: true - pagination_maximum_items_per_page: 50 - pagination_client_items_per_page: true - collection: - pagination: - items_per_page_parameter_name: limit - page_parameter_name: page + stateless: true + cache_headers: + vary: ['Content-Type', 'Authorization', 'Origin'] + extra_properties: + standard_put: true + rfc_7807_compliant_errors: true + event_listeners_backward_compatibility_layer: false + keep_legacy_inflector: false diff --git a/symfony.lock b/symfony.lock index 534b4d4f..5d3ef257 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,16 +1,16 @@ { "api-platform/core": { - "version": "2.7", + "version": "3.2", "recipe": { "repo": "github.com/symfony/recipes", "branch": "main", - "version": "2.5", - "ref": "05b57782a78c21a664a42055dc11cf1954ca36bb" + "version": "3.2", + "ref": "696d44adc3c0d4f5d25a2f1c4f3700dd8a5c6db9" }, "files": [ "config/packages/api_platform.yaml", "config/routes/api_platform.yaml", - "src/Entity/.gitignore" + "src/ApiResource/.gitignore" ] }, "codeception/codeception": { From 337e6e9ae80b7d7421524eec05a8a2788b350742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Skowro=C5=84ski?= Date: Fri, 19 Jan 2024 21:19:23 +0100 Subject: [PATCH 2/2] Adjust config and existing code --- config/api_platform/resources/Attendance.yaml | 32 ++--- config/api_platform/resources/ModList.yaml | 42 ++++--- config/packages/api_platform.yaml | 33 ++++-- config/packages/security.yaml | 2 +- config/services.yaml | 4 - src/Api/Controller/GetModListByNameAction.php | 28 ----- .../ModList/GetModListByNameOperation.php | 32 +++++ .../AttendanceInputDataTransformer.php | 23 ++-- .../AttendanceOutputDataTransformer.php | 25 ++-- .../Dlc/DlcOutputDataTransformer.php | 29 ++--- .../Mod/ModOutputDataTransformer.php | 41 +++---- .../ModListDetailsOutputDataTransformer.php | 52 +++------ .../ModList/ModListOutputDataTransformer.php | 29 ++--- src/Api/Input/Attendance/AttendanceInput.php | 24 +--- .../Output/Attendance/AttendanceOutput.php | 49 +------- src/Api/Output/Dlc/DlcOutput.php | 73 ++---------- src/Api/Output/Mod/ModOutput.php | 109 ++---------------- .../Output/ModList/ModListDetailsOutput.php | 47 +++----- src/Api/Output/ModList/ModListOutput.php | 73 ++---------- .../Attendance/AttendanceProcessor.php | 38 ++++++ .../Attendance/AttendanceDataProvider.php | 31 +++++ .../Provider/Common/AbstractDataProvider.php | 64 ++++++++++ .../Provider/ModList/ModListDataProvider.php | 31 +++++ .../ModList/ModListDetailsDataProvider.php | 31 +++++ .../Normalizer/PaginatorNormalizer.php | 12 +- .../UserLocaleRequestSubscriber.php | 3 + .../Attendance/UniqueAttendanceValidator.php | 4 +- tests/functional.suite.yml | 2 +- .../Api/ModList/GetModListsByIdCest.php | 3 +- .../Api/ModList/GetModListsByNameCest.php | 3 +- 30 files changed, 432 insertions(+), 537 deletions(-) delete mode 100644 src/Api/Controller/GetModListByNameAction.php create mode 100644 src/Api/Controller/ModList/GetModListByNameOperation.php create mode 100644 src/Api/Processor/Attendance/AttendanceProcessor.php create mode 100644 src/Api/Provider/Attendance/AttendanceDataProvider.php create mode 100644 src/Api/Provider/Common/AbstractDataProvider.php create mode 100644 src/Api/Provider/ModList/ModListDataProvider.php create mode 100644 src/Api/Provider/ModList/ModListDetailsDataProvider.php diff --git a/config/api_platform/resources/Attendance.yaml b/config/api_platform/resources/Attendance.yaml index 99b0063d..6124d00a 100644 --- a/config/api_platform/resources/Attendance.yaml +++ b/config/api_platform/resources/Attendance.yaml @@ -1,17 +1,19 @@ -App\Entity\Attendance\Attendance: - attributes: - input: 'App\Api\Input\Attendance\AttendanceInput' - output: 'App\Api\Output\Attendance\AttendanceOutput' +resources: + App\Entity\Attendance\Attendance: + operations: + ApiPlatform\Metadata\GetCollection: + provider: 'App\Api\Provider\Attendance\AttendanceDataProvider' + output: 'App\Api\Output\Attendance\AttendanceOutput' + filters: + - 'attendance.search_filter' + - 'attendance.date_filter' + - 'attendance.order_filter' - itemOperations: - get: ~ + ApiPlatform\Metadata\Get: + provider: 'App\Api\Provider\Attendance\AttendanceDataProvider' + output: 'App\Api\Output\Attendance\AttendanceOutput' - collectionOperations: - get: - filters: - - 'attendance.search_filter' - - 'attendance.date_filter' - - 'attendance.order_filter' - - post: - input: 'App\Api\Input\Attendance\AttendanceInput' + ApiPlatform\Metadata\Post: + input: 'App\Api\Input\Attendance\AttendanceInput' + processor: 'App\Api\Processor\Attendance\AttendanceProcessor' + output: 'App\Api\Output\Attendance\AttendanceOutput' diff --git a/config/api_platform/resources/ModList.yaml b/config/api_platform/resources/ModList.yaml index bef532ea..0aabeca7 100644 --- a/config/api_platform/resources/ModList.yaml +++ b/config/api_platform/resources/ModList.yaml @@ -1,21 +1,25 @@ -App\Entity\ModList\ModList: - attributes: - output: 'App\Api\Output\ModList\ModListOutput' +resources: + App\Entity\ModList\ModList: + operations: + ApiPlatform\Metadata\GetCollection: + provider: 'App\Api\Provider\ModList\ModListDataProvider' + output: 'App\Api\Output\ModList\ModListOutput' + filters: + - 'mod_list.search_filter' + - 'mod_list.date_filter' + - 'mod_list.order_filter' - itemOperations: - get: - output: 'App\Api\Output\ModList\ModListDetailsOutput' + ApiPlatform\Metadata\Get: + provider: 'App\Api\Provider\ModList\ModListDetailsDataProvider' + output: 'App\Api\Output\ModList\ModListDetailsOutput' - get_by_name: - method: 'GET' - path: '/mod-lists/by-name/{name}' - controller: 'App\Api\Controller\GetModListByNameAction' - output: 'App\Api\Output\ModList\ModListDetailsOutput' - read: false - - collectionOperations: - get: - filters: - - 'mod_list.search_filter' - - 'mod_list.date_filter' - - 'mod_list.order_filter' + get_by_name: + output: 'App\Api\Output\ModList\ModListDetailsOutput' + class: 'ApiPlatform\Metadata\Get' + uriTemplate: '/mod-lists/by-name/{name}' + uriVariables: + name: + fromClass: 'App\Entity\ModList\ModList' + fromProperty: 'name' + controller: 'App\Api\Controller\ModList\GetModListByNameOperation' + read: false diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index 4d0c3f7f..11983979 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -1,18 +1,37 @@ +imports: + - { resource: ../api_platform/filters/ } + api_platform: - title: Hello API Platform - version: 1.0.0 + title: "%app.api.name%" + version: "%app.api.version%" + show_webby: false + + swagger: + versions: [ 3 ] + api_keys: + apiKey: + name: '%env(APP_SECURITY_API_KEY_HEADER_NAME)%' + type: header + + path_segment_name_generator: api_platform.path_segment_name_generator.dash + + mapping: + paths: [ '%kernel.project_dir%/config/api_platform/resources' ] + formats: - jsonld: ['application/ld+json'] + json: [ 'application/json' ] + docs_formats: - jsonld: ['application/ld+json'] - jsonopenapi: ['application/vnd.openapi+json'] - html: ['text/html'] + html: [ 'text/html' ] + defaults: stateless: true cache_headers: - vary: ['Content-Type', 'Authorization', 'Origin'] + vary: [ 'Content-Type', 'Authorization', 'Origin' ] extra_properties: standard_put: true rfc_7807_compliant_errors: true + normalization_context: + skip_null_values: false event_listeners_backward_compatibility_layer: false keep_legacy_inflector: false diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 86292877..c95cf4c9 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -20,7 +20,7 @@ security: lazy: true stateless: true pattern: ^/api/attendances - methods: ['POST'] + methods: [ 'POST' ] custom_authenticators: - App\Security\Authenticator\ApiKeyAuthenticator diff --git a/config/services.yaml b/config/services.yaml index a863933c..9ee435da 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -39,10 +39,6 @@ services: resource: '../src/Controller/' tags: [ 'controller.service_arguments' ] - App\Api\Controller\: - resource: '../src/Api/Controller/' - tags: [ 'controller.service_arguments' ] - # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones App\Security\Authenticator\DiscordAuthenticator: diff --git a/src/Api/Controller/GetModListByNameAction.php b/src/Api/Controller/GetModListByNameAction.php deleted file mode 100644 index 63d7d8d5..00000000 --- a/src/Api/Controller/GetModListByNameAction.php +++ /dev/null @@ -1,28 +0,0 @@ -modListRepository->findOneByName($name); - - if (!$modList) { - throw new NotFoundHttpException('Not Found'); - } - - return $modList; - } -} diff --git a/src/Api/Controller/ModList/GetModListByNameOperation.php b/src/Api/Controller/ModList/GetModListByNameOperation.php new file mode 100644 index 00000000..c6bff581 --- /dev/null +++ b/src/Api/Controller/ModList/GetModListByNameOperation.php @@ -0,0 +1,32 @@ +modListRepository->findOneByName($name); + + if (!$modList) { + throw new NotFoundHttpException('Not Found'); + } + + return $this->modListDetailsOutputDataTransformer->transform($modList); + } +} diff --git a/src/Api/DataTransformer/Attendance/AttendanceInputDataTransformer.php b/src/Api/DataTransformer/Attendance/AttendanceInputDataTransformer.php index 1f027452..c1822faf 100644 --- a/src/Api/DataTransformer/Attendance/AttendanceInputDataTransformer.php +++ b/src/Api/DataTransformer/Attendance/AttendanceInputDataTransformer.php @@ -4,33 +4,26 @@ namespace App\Api\DataTransformer\Attendance; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; use ApiPlatform\Validator\ValidatorInterface; use App\Api\Input\Attendance\AttendanceInput; use App\Entity\Attendance\Attendance; use Ramsey\Uuid\Uuid; -class AttendanceInputDataTransformer implements DataTransformerInterface +class AttendanceInputDataTransformer { public function __construct( private ValidatorInterface $validator ) { } - public function transform($object, string $to, array $context = []): Attendance + public function transform(AttendanceInput $attendanceInput): Attendance { - /** @var AttendanceInput $object */ - $this->validator->validate($object); + $this->validator->validate($attendanceInput); - return new Attendance(Uuid::uuid4(), $object->getMissionId(), $object->getPlayerId()); - } - - public function supportsTransformation($data, string $to, array $context = []): bool - { - if ($data instanceof Attendance) { - return false; - } - - return Attendance::class === $to && null !== ($context['input']['class'] ?? null); + return new Attendance( + Uuid::uuid4(), + $attendanceInput->missionId, + $attendanceInput->playerId + ); } } diff --git a/src/Api/DataTransformer/Attendance/AttendanceOutputDataTransformer.php b/src/Api/DataTransformer/Attendance/AttendanceOutputDataTransformer.php index 3cd7082e..435ec16d 100644 --- a/src/Api/DataTransformer/Attendance/AttendanceOutputDataTransformer.php +++ b/src/Api/DataTransformer/Attendance/AttendanceOutputDataTransformer.php @@ -4,27 +4,18 @@ namespace App\Api\DataTransformer\Attendance; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; use App\Api\Output\Attendance\AttendanceOutput; use App\Entity\Attendance\Attendance; -class AttendanceOutputDataTransformer implements DataTransformerInterface +class AttendanceOutputDataTransformer { - public function transform($object, string $to, array $context = []): AttendanceOutput + public function transform(Attendance $attendance): AttendanceOutput { - /** @var Attendance $object */ - $output = new AttendanceOutput(); - - $output->setId($object->getId()->toString()); - $output->setCreatedAt($object->getCreatedAt()); - $output->setMissionId($object->getMissionId()); - $output->setPlayerId($object->getPlayerId()); - - return $output; - } - - public function supportsTransformation($data, string $to, array $context = []): bool - { - return AttendanceOutput::class === $to && $data instanceof Attendance; + return new AttendanceOutput( + $attendance->getId()->toString(), + $attendance->getMissionId(), + $attendance->getPlayerId(), + $attendance->getCreatedAt(), + ); } } diff --git a/src/Api/DataTransformer/Dlc/DlcOutputDataTransformer.php b/src/Api/DataTransformer/Dlc/DlcOutputDataTransformer.php index 6bf3dc5e..aca60109 100644 --- a/src/Api/DataTransformer/Dlc/DlcOutputDataTransformer.php +++ b/src/Api/DataTransformer/Dlc/DlcOutputDataTransformer.php @@ -4,29 +4,20 @@ namespace App\Api\DataTransformer\Dlc; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; use App\Api\Output\Dlc\DlcOutput; use App\Entity\Dlc\Dlc; -class DlcOutputDataTransformer implements DataTransformerInterface +class DlcOutputDataTransformer { - public function transform($object, string $to, array $context = []): DlcOutput + public function transform(Dlc $dlc): DlcOutput { - /** @var Dlc $object */ - $output = new DlcOutput(); - - $output->setId($object->getId()->toString()); - $output->setName($object->getName()); - $output->setCreatedAt($object->getCreatedAt()); - $output->setLastUpdatedAt($object->getLastUpdatedAt()); - $output->setAppId($object->getAppId()); - $output->setDirectory($object->getDirectory()); - - return $output; - } - - public function supportsTransformation($data, string $to, array $context = []): bool - { - return DlcOutput::class === $to && $data instanceof Dlc; + return new DlcOutput( + $dlc->getId()->toString(), + $dlc->getName(), + $dlc->getAppId(), + $dlc->getDirectory(), + $dlc->getCreatedAt(), + $dlc->getLastUpdatedAt() + ); } } diff --git a/src/Api/DataTransformer/Mod/ModOutputDataTransformer.php b/src/Api/DataTransformer/Mod/ModOutputDataTransformer.php index 1575e01b..009298ff 100644 --- a/src/Api/DataTransformer/Mod/ModOutputDataTransformer.php +++ b/src/Api/DataTransformer/Mod/ModOutputDataTransformer.php @@ -4,7 +4,6 @@ namespace App\Api\DataTransformer\Mod; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; use App\Api\Output\Mod\ModOutput; use App\Entity\Mod\AbstractMod; use App\Entity\Mod\DirectoryMod; @@ -12,34 +11,20 @@ use App\Entity\Mod\Enum\ModTypeEnum; use App\Entity\Mod\SteamWorkshopMod; -class ModOutputDataTransformer implements DataTransformerInterface +class ModOutputDataTransformer { - public function transform($object, string $to, array $context = []): ModOutput + public function transform(AbstractMod $mod): ModOutput { - /** @var AbstractMod $object */ - $output = new ModOutput(); - - $output->setId($object->getId()->toString()); - $output->setName($object->getName()); - $output->setStatus($object->getStatus()?->value); - $output->setCreatedAt($object->getCreatedAt()); - $output->setLastUpdatedAt($object->getLastUpdatedAt()); - - if ($object instanceof SteamWorkshopMod) { - $output->setType($object->getType()->value); - $output->setSource(ModSourceEnum::STEAM_WORKSHOP->value); - $output->setItemId($object->getItemId()); - } elseif ($object instanceof DirectoryMod) { - $output->setType(ModTypeEnum::SERVER_SIDE->value); - $output->setSource(ModSourceEnum::DIRECTORY->value); - $output->setDirectory($object->getDirectory()); - } - - return $output; - } - - public function supportsTransformation($data, string $to, array $context = []): bool - { - return ModOutput::class === $to && $data instanceof AbstractMod; + return new ModOutput( + $mod->getId()->toString(), + $mod->getName(), + $mod instanceof SteamWorkshopMod ? ModSourceEnum::STEAM_WORKSHOP->value : ModSourceEnum::DIRECTORY->value, + $mod instanceof SteamWorkshopMod ? $mod->getType()->value : ModTypeEnum::SERVER_SIDE->value, + $mod->getStatus()?->value, + $mod instanceof SteamWorkshopMod ? $mod->getItemId() : null, + $mod instanceof DirectoryMod ? $mod->getDirectory() : null, + $mod->getCreatedAt(), + $mod->getLastUpdatedAt(), + ); } } diff --git a/src/Api/DataTransformer/ModList/ModListDetailsOutputDataTransformer.php b/src/Api/DataTransformer/ModList/ModListDetailsOutputDataTransformer.php index cb47cc58..2456e119 100644 --- a/src/Api/DataTransformer/ModList/ModListDetailsOutputDataTransformer.php +++ b/src/Api/DataTransformer/ModList/ModListDetailsOutputDataTransformer.php @@ -4,55 +4,41 @@ namespace App\Api\DataTransformer\ModList; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; use App\Api\DataTransformer\Dlc\DlcOutputDataTransformer; use App\Api\DataTransformer\Mod\ModOutputDataTransformer; -use App\Api\Output\Dlc\DlcOutput; -use App\Api\Output\Mod\ModOutput; use App\Api\Output\ModList\ModListDetailsOutput; use App\Api\Output\ModList\ModListOutput; use App\Entity\Dlc\Dlc; +use App\Entity\Mod\AbstractMod; use App\Entity\ModList\ModList; use App\Repository\Mod\ModRepository; -class ModListDetailsOutputDataTransformer implements DataTransformerInterface +class ModListDetailsOutputDataTransformer { public function __construct( - private ModOutputDataTransformer $modDataTransformer, + private ModOutputDataTransformer $modOutputDataTransformer, private DlcOutputDataTransformer $dlcOutputDataTransformer, private ModRepository $modRepository ) { } - public function transform($object, string $to, array $context = []): ModListOutput + public function transform(ModList $modList): ModListOutput { - /** @var ModList $object */ - $output = new ModListDetailsOutput(); - - $output->setId($object->getId()->toString()); - $output->setName($object->getName()); - $output->setActive($object->isActive()); - $output->setApproved($object->isApproved()); - $output->setCreatedAt($object->getCreatedAt()); - $output->setLastUpdatedAt($object->getLastUpdatedAt()); - - $mods = []; - foreach ($this->modRepository->findIncludedMods($object) as $mod) { - $mods[] = $this->modDataTransformer->transform($mod, ModOutput::class, $context); - } - $output->setMods($mods); - - $dlcs = array_map( - fn (Dlc $dlc) => $this->dlcOutputDataTransformer->transform($dlc, DlcOutput::class, $context), - $object->getDlcs() + return new ModListDetailsOutput( + $modList->getId()->toString(), + $modList->getName(), + $modList->isActive(), + $modList->isApproved(), + $modList->getCreatedAt(), + $modList->getLastUpdatedAt(), + array_map( + fn (AbstractMod $mod) => $this->modOutputDataTransformer->transform($mod), + $this->modRepository->findIncludedMods($modList) + ), + array_map( + fn (Dlc $dlc) => $this->dlcOutputDataTransformer->transform($dlc), + $modList->getDlcs() + ), ); - $output->setDlcs($dlcs); - - return $output; - } - - public function supportsTransformation($data, string $to, array $context = []): bool - { - return ModListDetailsOutput::class === $to && $data instanceof ModList; } } diff --git a/src/Api/DataTransformer/ModList/ModListOutputDataTransformer.php b/src/Api/DataTransformer/ModList/ModListOutputDataTransformer.php index 0f51f897..6d8180bb 100644 --- a/src/Api/DataTransformer/ModList/ModListOutputDataTransformer.php +++ b/src/Api/DataTransformer/ModList/ModListOutputDataTransformer.php @@ -4,29 +4,20 @@ namespace App\Api\DataTransformer\ModList; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; use App\Api\Output\ModList\ModListOutput; use App\Entity\ModList\ModList; -class ModListOutputDataTransformer implements DataTransformerInterface +class ModListOutputDataTransformer { - public function transform($object, string $to, array $context = []): ModListOutput + public function transform(ModList $modList): ModListOutput { - /** @var ModList $object */ - $output = new ModListOutput(); - - $output->setId($object->getId()->toString()); - $output->setName($object->getName()); - $output->setActive($object->isActive()); - $output->setApproved($object->isApproved()); - $output->setCreatedAt($object->getCreatedAt()); - $output->setLastUpdatedAt($object->getLastUpdatedAt()); - - return $output; - } - - public function supportsTransformation($data, string $to, array $context = []): bool - { - return ModListOutput::class === $to && $data instanceof ModList; + return new ModListOutput( + $modList->getId()->toString(), + $modList->getName(), + $modList->isActive(), + $modList->isApproved(), + $modList->getCreatedAt(), + $modList->getLastUpdatedAt(), + ); } } diff --git a/src/Api/Input/Attendance/AttendanceInput.php b/src/Api/Input/Attendance/AttendanceInput.php index 090c0b2d..4132c899 100644 --- a/src/Api/Input/Attendance/AttendanceInput.php +++ b/src/Api/Input/Attendance/AttendanceInput.php @@ -13,29 +13,9 @@ class AttendanceInput { #[Assert\NotBlank] #[Assert\Length(max: 255)] - private ?string $missionId = null; + public string $missionId; #[Assert\NotBlank] #[SteamProfileId] - private ?int $playerId = null; - - public function getMissionId(): ?string - { - return $this->missionId; - } - - public function setMissionId(?string $missionId): void - { - $this->missionId = $missionId; - } - - public function getPlayerId(): ?int - { - return $this->playerId; - } - - public function setPlayerId(?int $playerId): void - { - $this->playerId = $playerId; - } + public int $playerId; } diff --git a/src/Api/Output/Attendance/AttendanceOutput.php b/src/Api/Output/Attendance/AttendanceOutput.php index 28927ad9..92fb7fae 100644 --- a/src/Api/Output/Attendance/AttendanceOutput.php +++ b/src/Api/Output/Attendance/AttendanceOutput.php @@ -6,48 +6,11 @@ class AttendanceOutput { - private ?string $id = null; - private ?\DateTimeInterface $createdAt = null; - private ?string $missionId = null; - private ?int $playerId = null; - - public function getId(): ?string - { - return $this->id; - } - - public function setId(?string $id): void - { - $this->id = $id; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt): void - { - $this->createdAt = $createdAt; - } - - public function getMissionId(): ?string - { - return $this->missionId; - } - - public function setMissionId(?string $missionId): void - { - $this->missionId = $missionId; - } - - public function getPlayerId(): ?int - { - return $this->playerId; - } - - public function setPlayerId(?int $playerId): void - { - $this->playerId = $playerId; + public function __construct( + public string $id, + public string $missionId, + public int $playerId, + public ?\DateTimeInterface $createdAt, + ) { } } diff --git a/src/Api/Output/Dlc/DlcOutput.php b/src/Api/Output/Dlc/DlcOutput.php index b3d73b4f..c7911eb1 100644 --- a/src/Api/Output/Dlc/DlcOutput.php +++ b/src/Api/Output/Dlc/DlcOutput.php @@ -6,70 +6,13 @@ class DlcOutput { - private ?string $id = null; - private ?string $name = null; - private ?\DateTimeInterface $createdAt = null; - private ?\DateTimeInterface $lastUpdatedAt = null; - private ?int $appId = null; - private ?string $directory = null; - - public function getId(): ?string - { - return $this->id; - } - - public function setId(?string $id): void - { - $this->id = $id; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(?string $name): void - { - $this->name = $name; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt): void - { - $this->createdAt = $createdAt; - } - - public function getLastUpdatedAt(): ?\DateTimeInterface - { - return $this->lastUpdatedAt; - } - - public function setLastUpdatedAt(?\DateTimeInterface $lastUpdatedAt): void - { - $this->lastUpdatedAt = $lastUpdatedAt; - } - - public function getAppId(): ?int - { - return $this->appId; - } - - public function setAppId(?int $appId): void - { - $this->appId = $appId; - } - - public function getDirectory(): ?string - { - return $this->directory; - } - - public function setDirectory(?string $directory): void - { - $this->directory = $directory; + public function __construct( + public string $id, + public string $name, + public int $appId, + public string $directory, + public \DateTimeInterface $createdAt, + public ?\DateTimeInterface $lastUpdatedAt, + ) { } } diff --git a/src/Api/Output/Mod/ModOutput.php b/src/Api/Output/Mod/ModOutput.php index 1cb7d0c5..5feb4e52 100644 --- a/src/Api/Output/Mod/ModOutput.php +++ b/src/Api/Output/Mod/ModOutput.php @@ -6,103 +6,16 @@ class ModOutput { - private ?string $id = null; - private ?string $name = null; - private ?\DateTimeInterface $createdAt = null; - private ?\DateTimeInterface $lastUpdatedAt = null; - private ?string $source = null; - private ?string $status = null; - private ?string $type = null; - private ?int $itemId = null; - private ?string $directory = null; - - public function getId(): ?string - { - return $this->id; - } - - public function setId(?string $id): void - { - $this->id = $id; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(?string $name): void - { - $this->name = $name; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt): void - { - $this->createdAt = $createdAt; - } - - public function getLastUpdatedAt(): ?\DateTimeInterface - { - return $this->lastUpdatedAt; - } - - public function setLastUpdatedAt(?\DateTimeInterface $lastUpdatedAt): void - { - $this->lastUpdatedAt = $lastUpdatedAt; - } - - public function getSource(): ?string - { - return $this->source; - } - - public function setSource(?string $source): void - { - $this->source = $source; - } - - public function getStatus(): ?string - { - return $this->status; - } - - public function setStatus(?string $status): void - { - $this->status = $status; - } - - public function getType(): ?string - { - return $this->type; - } - - public function setType(?string $type): void - { - $this->type = $type; - } - - public function getItemId(): ?int - { - return $this->itemId; - } - - public function setItemId(?int $itemId): void - { - $this->itemId = $itemId; - } - - public function getDirectory(): ?string - { - return $this->directory; - } - - public function setDirectory(?string $directory): void - { - $this->directory = $directory; + public function __construct( + public string $id, + public string $name, + public string $source, + public string $type, + public ?string $status, + public ?int $itemId, + public ?string $directory, + public ?\DateTimeInterface $createdAt, + public ?\DateTimeInterface $lastUpdatedAt, + ) { } } diff --git a/src/Api/Output/ModList/ModListDetailsOutput.php b/src/Api/Output/ModList/ModListDetailsOutput.php index 1becb13e..482e6853 100644 --- a/src/Api/Output/ModList/ModListDetailsOutput.php +++ b/src/Api/Output/ModList/ModListDetailsOutput.php @@ -9,38 +9,27 @@ class ModListDetailsOutput extends ModListOutput { - private array $mods = []; - private array $dlcs = []; - - /** - * @return ModOutput[] - */ - public function getMods(): array - { - return $this->mods; - } - /** * @param ModOutput[] $mods - */ - public function setMods(array $mods): void - { - $this->mods = $mods; - } - - /** - * @return DlcOutput[] - */ - public function getDlcs(): array - { - return $this->dlcs; - } - - /** * @param DlcOutput[] $dlcs */ - public function setDlcs(array $dlcs): void - { - $this->dlcs = $dlcs; + public function __construct( + string $id, + string $name, + bool $active, + bool $approved, + \DateTimeInterface $createdAt, + ?\DateTimeInterface $lastUpdatedAt, + public array $mods, + public array $dlcs + ) { + parent::__construct( + $id, + $name, + $active, + $approved, + $createdAt, + $lastUpdatedAt + ); } } diff --git a/src/Api/Output/ModList/ModListOutput.php b/src/Api/Output/ModList/ModListOutput.php index 4a8c4161..1be77130 100644 --- a/src/Api/Output/ModList/ModListOutput.php +++ b/src/Api/Output/ModList/ModListOutput.php @@ -6,70 +6,13 @@ class ModListOutput { - private ?string $id = null; - private ?string $name = null; - private bool $active; - private bool $approved; - private ?\DateTimeInterface $createdAt = null; - private ?\DateTimeInterface $lastUpdatedAt = null; - - public function getId(): ?string - { - return $this->id; - } - - public function setId(?string $id): void - { - $this->id = $id; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(?string $name): void - { - $this->name = $name; - } - - public function isActive(): bool - { - return $this->active; - } - - public function setActive(bool $active): void - { - $this->active = $active; - } - - public function isApproved(): bool - { - return $this->approved; - } - - public function setApproved(bool $approved): void - { - $this->approved = $approved; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt): void - { - $this->createdAt = $createdAt; - } - - public function getLastUpdatedAt(): ?\DateTimeInterface - { - return $this->lastUpdatedAt; - } - - public function setLastUpdatedAt(?\DateTimeInterface $lastUpdatedAt): void - { - $this->lastUpdatedAt = $lastUpdatedAt; + public function __construct( + public string $id, + public string $name, + public bool $active, + public bool $approved, + public \DateTimeInterface $createdAt, + public ?\DateTimeInterface $lastUpdatedAt, + ) { } } diff --git a/src/Api/Processor/Attendance/AttendanceProcessor.php b/src/Api/Processor/Attendance/AttendanceProcessor.php new file mode 100644 index 00000000..8255708c --- /dev/null +++ b/src/Api/Processor/Attendance/AttendanceProcessor.php @@ -0,0 +1,38 @@ +validator->validate($data); + + $attendance = $this->attendanceInputDataTransformer->transform($data); + + $this->persistProcessor->process($attendance, $operation, $uriVariables, $context); + + return $this->attendanceOutputDataTransformer->transform($attendance); + } +} diff --git a/src/Api/Provider/Attendance/AttendanceDataProvider.php b/src/Api/Provider/Attendance/AttendanceDataProvider.php new file mode 100644 index 00000000..2af1717d --- /dev/null +++ b/src/Api/Provider/Attendance/AttendanceDataProvider.php @@ -0,0 +1,31 @@ +attendanceOutputDataTransformer->transform($data); + } +} diff --git a/src/Api/Provider/Common/AbstractDataProvider.php b/src/Api/Provider/Common/AbstractDataProvider.php new file mode 100644 index 00000000..871290e2 --- /dev/null +++ b/src/Api/Provider/Common/AbstractDataProvider.php @@ -0,0 +1,64 @@ +collectionProvider->provide($operation, $uriVariables, $context); + + return new Pagination\TraversablePaginator( + $this->transformCollection($paginator->getIterator(), $operation, $uriVariables, $context), + $paginator->getCurrentPage(), + $paginator->getItemsPerPage(), + $paginator->getTotalItems(), + ); + } + + $item = $this->itemProvider->provide($operation, $uriVariables, $context); + if (null !== $item) { + $item = $this->provideTransformedData($item, $operation, $uriVariables, $context); + } + + return $item; + } + + public function provideTransformedData( + mixed $data, + Operation $operation, + array $uriVariables = [], + array $context = [] + ): object { + return $data; + } + + private function transformCollection( + \Traversable $collection, + Operation $operation, + array $uriVariables = [], + array $context = [] + ): \Traversable { + foreach ($collection as $item) { + yield $this->provideTransformedData($item, $operation, $uriVariables, $context); + } + } +} diff --git a/src/Api/Provider/ModList/ModListDataProvider.php b/src/Api/Provider/ModList/ModListDataProvider.php new file mode 100644 index 00000000..b4c07274 --- /dev/null +++ b/src/Api/Provider/ModList/ModListDataProvider.php @@ -0,0 +1,31 @@ +modListOutputDataTransformer->transform($data); + } +} diff --git a/src/Api/Provider/ModList/ModListDetailsDataProvider.php b/src/Api/Provider/ModList/ModListDetailsDataProvider.php new file mode 100644 index 00000000..854e91ae --- /dev/null +++ b/src/Api/Provider/ModList/ModListDetailsDataProvider.php @@ -0,0 +1,31 @@ +modListDetailsOutputDataTransformer->transform($data); + } +} diff --git a/src/Api/Serializer/Normalizer/PaginatorNormalizer.php b/src/Api/Serializer/Normalizer/PaginatorNormalizer.php index 3908f4f5..63f70c67 100644 --- a/src/Api/Serializer/Normalizer/PaginatorNormalizer.php +++ b/src/Api/Serializer/Normalizer/PaginatorNormalizer.php @@ -4,7 +4,7 @@ namespace App\Api\Serializer\Normalizer; -use ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator; +use ApiPlatform\State\Pagination\TraversablePaginator; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -13,9 +13,11 @@ class PaginatorNormalizer implements NormalizerInterface, NormalizerAwareInterfa { use NormalizerAwareTrait; - public function normalize($object, string $format = null, array $context = []): array + /** + * @param TraversablePaginator $object + */ + public function normalize(mixed $object, string $format = null, array $context = []): array { - /** @var Paginator $object */ $data = []; foreach ($object->getIterator() as $item) { $data[] = $this->normalizer->normalize($item, $format, $context); @@ -31,8 +33,8 @@ public function normalize($object, string $format = null, array $context = []): ]; } - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization(mixed $data, string $format = null): bool { - return $data instanceof Paginator && 'json' === $format; + return $data instanceof TraversablePaginator && 'json' === $format; } } diff --git a/src/EventSubscriber/UserLocaleRequestSubscriber.php b/src/EventSubscriber/UserLocaleRequestSubscriber.php index 9480ddd1..42d16255 100644 --- a/src/EventSubscriber/UserLocaleRequestSubscriber.php +++ b/src/EventSubscriber/UserLocaleRequestSubscriber.php @@ -44,6 +44,9 @@ public function onKernelRequest(RequestEvent $event): void } $request = $event->getRequest(); + if (str_starts_with($request->getRequestUri(), '/api')) { + return; + } $negotiatedLanguage = $request->getLocale(); $acceptLanguage = $request->headers->get('Accept-Language'); diff --git a/src/Validator/Attendance/UniqueAttendanceValidator.php b/src/Validator/Attendance/UniqueAttendanceValidator.php index 118da96b..065b540d 100644 --- a/src/Validator/Attendance/UniqueAttendanceValidator.php +++ b/src/Validator/Attendance/UniqueAttendanceValidator.php @@ -22,8 +22,8 @@ public function validate(mixed $value, Constraint $constraint): void throw new UnexpectedTypeException($constraint, UniqueAttendance::class); } - $missionId = $value->getMissionId(); - $playerId = $value->getPlayerId(); + $missionId = $value->missionId; + $playerId = $value->playerId; if (!$missionId || !$playerId) { return; diff --git a/tests/functional.suite.yml b/tests/functional.suite.yml index 743a6895..0f7ff15b 100644 --- a/tests/functional.suite.yml +++ b/tests/functional.suite.yml @@ -4,7 +4,7 @@ modules: - Symfony: app_path: 'src' environment: 'test' - cache_router: true + cache_router: false # Needs to be disabled in order to work correctly with Api Platform 3 routes rebootable_client: false authenticator: true - Doctrine2: diff --git a/tests/functional/Api/ModList/GetModListsByIdCest.php b/tests/functional/Api/ModList/GetModListsByIdCest.php index faa915ef..634bf601 100644 --- a/tests/functional/Api/ModList/GetModListsByIdCest.php +++ b/tests/functional/Api/ModList/GetModListsByIdCest.php @@ -52,9 +52,10 @@ public function getModListByIdUsingValidApiKeyWhenModListDoesNotExist(Functional $I->seeResponseCodeIs(HttpCode::NOT_FOUND); $I->seeResponseContainsJson([ - 'type' => 'https://tools.ietf.org/html/rfc2616#section-10', 'title' => 'An error occurred', 'detail' => 'Not Found', + 'status' => HttpCode::NOT_FOUND, + 'type' => '/errors/404', ]); } diff --git a/tests/functional/Api/ModList/GetModListsByNameCest.php b/tests/functional/Api/ModList/GetModListsByNameCest.php index 9fc29202..3fd23115 100644 --- a/tests/functional/Api/ModList/GetModListsByNameCest.php +++ b/tests/functional/Api/ModList/GetModListsByNameCest.php @@ -52,9 +52,10 @@ public function getModListByNameUsingValidApiKeyWhenModListDoesNotExist(Function $I->seeResponseCodeIs(HttpCode::NOT_FOUND); $I->seeResponseContainsJson([ - 'type' => 'https://tools.ietf.org/html/rfc2616#section-10', 'title' => 'An error occurred', 'detail' => 'Not Found', + 'status' => HttpCode::NOT_FOUND, + 'type' => '/errors/404', ]); }