From 78415a1bd6c0974b6a8555e555c17460300a91a9 Mon Sep 17 00:00:00 2001 From: Kevin Verschaeve Date: Tue, 9 Nov 2021 21:03:59 +0100 Subject: [PATCH 1/4] create depreacted interfaces file and move DataTransformer interfaces --- .../ApiPlatformExtension.php | 4 ++-- .../Symfony/Messenger/DataTransformer.php | 2 +- src/Core/Serializer/AbstractItemNormalizer.php | 4 ++-- .../DataTransformerInitializerInterface.php | 2 +- .../DataTransformerInterface.php | 2 +- src/deprecated_interfaces.php | 17 +++++++++++++++++ src/deprecation.php | 9 +++++++++ .../ApiPlatformExtensionTest.php | 4 ++-- .../Serializer/AbstractItemNormalizerTest.php | 4 ++-- tests/Core/Serializer/ItemNormalizerTest.php | 2 +- .../CustomInputDtoDataTransformer.php | 2 +- .../CustomOutputDtoDataTransformer.php | 2 +- ...ummyDtoNoInputToOutputDtoDataTransformer.php | 2 +- .../InitializeInputDataTransformer.php | 2 +- .../DataTransformer/InputDtoDataTransformer.php | 2 +- .../OutputDtoDataTransformer.php | 2 +- .../OutputDtoSameClassTransformer.php | 2 +- .../RPCOutputDataTransformer.php | 2 +- .../RecoverPasswordInputDataTransformer.php | 2 +- .../RecoverPasswordOutputDataTransformer.php | 2 +- 20 files changed, 48 insertions(+), 22 deletions(-) rename src/{Core => }/DataTransformer/DataTransformerInitializerInterface.php (93%) rename src/{Core => }/DataTransformer/DataTransformerInterface.php (95%) create mode 100644 src/deprecated_interfaces.php diff --git a/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 743d9d96fcd..0f7d4d22c5b 100644 --- a/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -31,8 +31,8 @@ use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInitializerInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInitializerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Metadata\Extractor\XmlExtractor; use ApiPlatform\Core\Metadata\Extractor\YamlExtractor; use ApiPlatform\GraphQl\Error\ErrorHandlerInterface; diff --git a/src/Core/Bridge/Symfony/Messenger/DataTransformer.php b/src/Core/Bridge/Symfony/Messenger/DataTransformer.php index 5a63870d328..7cb75124648 100644 --- a/src/Core/Bridge/Symfony/Messenger/DataTransformer.php +++ b/src/Core/Bridge/Symfony/Messenger/DataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Core\Bridge\Symfony\Messenger; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use ApiPlatform\Core\Util\ClassInfoTrait; use ApiPlatform\Exception\OperationNotFoundException; diff --git a/src/Core/Serializer/AbstractItemNormalizer.php b/src/Core/Serializer/AbstractItemNormalizer.php index af2a6d54f03..ef598513e08 100644 --- a/src/Core/Serializer/AbstractItemNormalizer.php +++ b/src/Core/Serializer/AbstractItemNormalizer.php @@ -17,8 +17,8 @@ use ApiPlatform\Api\UrlGeneratorInterface; use ApiPlatform\Core\Api\IriConverterInterface as LegacyIriConverterInterface; use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInitializerInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInitializerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface as LegacyPropertyMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface as LegacyPropertyNameCollectionFactoryInterface; use ApiPlatform\Core\Metadata\Property\PropertyMetadata; diff --git a/src/Core/DataTransformer/DataTransformerInitializerInterface.php b/src/DataTransformer/DataTransformerInitializerInterface.php similarity index 93% rename from src/Core/DataTransformer/DataTransformerInitializerInterface.php rename to src/DataTransformer/DataTransformerInitializerInterface.php index 85007c818e1..dde47366ce5 100644 --- a/src/Core/DataTransformer/DataTransformerInitializerInterface.php +++ b/src/DataTransformer/DataTransformerInitializerInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Core\DataTransformer; +namespace ApiPlatform\DataTransformer; interface DataTransformerInitializerInterface extends DataTransformerInterface { diff --git a/src/Core/DataTransformer/DataTransformerInterface.php b/src/DataTransformer/DataTransformerInterface.php similarity index 95% rename from src/Core/DataTransformer/DataTransformerInterface.php rename to src/DataTransformer/DataTransformerInterface.php index 156c0ffe437..56abe3fb5c5 100644 --- a/src/Core/DataTransformer/DataTransformerInterface.php +++ b/src/DataTransformer/DataTransformerInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Core\DataTransformer; +namespace ApiPlatform\DataTransformer; /** * Transforms a DTO or an Anonymous class to a Resource object. diff --git a/src/deprecated_interfaces.php b/src/deprecated_interfaces.php new file mode 100644 index 00000000000..a97d5c264e8 --- /dev/null +++ b/src/deprecated_interfaces.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +return [ + ApiPlatform\Core\DataTransformer\DataTransformerInitializerInterface::class => ApiPlatform\DataTransformer\DataTransformerInitializerInterface::class, + ApiPlatform\Core\DataTransformer\DataTransformerInterface::class => ApiPlatform\DataTransformer\DataTransformerInterface::class, +]; diff --git a/src/deprecation.php b/src/deprecation.php index a83c374a739..5ea3491f0d4 100644 --- a/src/deprecation.php +++ b/src/deprecation.php @@ -108,6 +108,8 @@ ApiPlatform\Core\GraphQl\Type\TypesContainer::class => ApiPlatform\GraphQl\Type\TypesContainer::class, ]; + $deprecatedInterfaces = include 'deprecated_interfaces.php'; + if (ApiPlatform\Core\Metadata\Property\PropertyMetadata::class === $className) { trigger_deprecation('api-platform/core', '2.7', sprintf('The class %s is deprecated, use %s instead.', $className, ApiPlatform\Metadata\ApiProperty::class)); } @@ -126,4 +128,11 @@ class_alias($deprecatedClasses[$className], $className); return; } + + if (isset($deprecatedInterfaces[$className])) { + class_alias($deprecatedInterfaces[$className], $className); + trigger_deprecation('api-platform/core', '2.7', sprintf('The interface %s is deprecated, use %s instead.', $className, $deprecatedClasses[$className])); + + return; + } }); diff --git a/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index bd5cf4ac1e7..b9aa7825ca3 100644 --- a/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -65,8 +65,8 @@ use ApiPlatform\Core\DataProvider\Pagination; use ApiPlatform\Core\DataProvider\PaginationOptions; use ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInitializerInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInitializerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\JsonSchema\SchemaFactoryInterface; use ApiPlatform\Core\JsonSchema\TypeFactoryInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface as LegacyPropertyMetadataFactoryInterface; diff --git a/tests/Core/Serializer/AbstractItemNormalizerTest.php b/tests/Core/Serializer/AbstractItemNormalizerTest.php index 2db10e51cc0..0a7c5c00095 100644 --- a/tests/Core/Serializer/AbstractItemNormalizerTest.php +++ b/tests/Core/Serializer/AbstractItemNormalizerTest.php @@ -16,8 +16,8 @@ use ApiPlatform\Core\Api\IriConverterInterface; use ApiPlatform\Core\Api\ResourceClassResolverInterface; use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInitializerInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInitializerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Core\Metadata\Property\PropertyMetadata; diff --git a/tests/Core/Serializer/ItemNormalizerTest.php b/tests/Core/Serializer/ItemNormalizerTest.php index ede88e6cb16..8235a8da104 100644 --- a/tests/Core/Serializer/ItemNormalizerTest.php +++ b/tests/Core/Serializer/ItemNormalizerTest.php @@ -15,7 +15,7 @@ use ApiPlatform\Core\Api\IriConverterInterface; use ApiPlatform\Core\Api\ResourceClassResolverInterface; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; use ApiPlatform\Core\Metadata\Property\PropertyNameCollection; diff --git a/tests/Fixtures/TestBundle/DataTransformer/CustomInputDtoDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/CustomInputDtoDataTransformer.php index a7a5db0212a..8b4c5b0da5b 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/CustomInputDtoDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/CustomInputDtoDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Serializer\AbstractItemNormalizer; use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyDtoCustom as DummyDtoCustomDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\CustomInputDto; diff --git a/tests/Fixtures/TestBundle/DataTransformer/CustomOutputDtoDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/CustomOutputDtoDataTransformer.php index 0e3586e10bf..a7b5e5847aa 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/CustomOutputDtoDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/CustomOutputDtoDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyDtoCustom as DummyDtoCustomDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\CustomOutputDto; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyDtoCustom; diff --git a/tests/Fixtures/TestBundle/DataTransformer/DummyDtoNoInputToOutputDtoDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/DummyDtoNoInputToOutputDtoDataTransformer.php index e9eb4cb7d2e..73a7b67114f 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/DummyDtoNoInputToOutputDtoDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/DummyDtoNoInputToOutputDtoDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyDtoNoInput as DummyDtoNoInputDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\Document\OutputDto as OutputDtoDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto; diff --git a/tests/Fixtures/TestBundle/DataTransformer/InitializeInputDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/InitializeInputDataTransformer.php index 95e2c2d19a7..71cdd2d54cc 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/InitializeInputDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/InitializeInputDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInitializerInterface; +use ApiPlatform\DataTransformer\DataTransformerInitializerInterface; use ApiPlatform\Core\Serializer\AbstractItemNormalizer; use ApiPlatform\Tests\Fixtures\TestBundle\Document\InitializeInput as InitializeInputDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\InitializeInputDto; diff --git a/tests/Fixtures/TestBundle/DataTransformer/InputDtoDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/InputDtoDataTransformer.php index 282e9199a8e..060a27b6a1b 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/InputDtoDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/InputDtoDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Serializer\AbstractItemNormalizer; use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyDtoInputOutput as DummyDtoInputOutputDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\Document\InputDto as InputDtoDocument; diff --git a/tests/Fixtures/TestBundle/DataTransformer/OutputDtoDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/OutputDtoDataTransformer.php index 7c297434024..7630c211bb6 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/OutputDtoDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/OutputDtoDataTransformer.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; use ApiPlatform\Core\DataProvider\ArrayPaginator; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyDtoInputOutput as DummyDtoInputOutputDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\Document\OutputDto as OutputDtoDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto; diff --git a/tests/Fixtures/TestBundle/DataTransformer/OutputDtoSameClassTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/OutputDtoSameClassTransformer.php index f8a776016c1..0a3e11596d1 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/OutputDtoSameClassTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/OutputDtoSameClassTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyDtoOutputFallbackToSameClass as DummyDtoOutputFallbackToSameClassDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Document\DummyDtoOutputSameClass as DummyDtoOutputSameClassDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDtoDummy; diff --git a/tests/Fixtures/TestBundle/DataTransformer/RPCOutputDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/RPCOutputDataTransformer.php index 24d6bc442c0..e5f5a80808c 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/RPCOutputDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/RPCOutputDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Document\RPC as RPCDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\RPCOutput; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RPC; diff --git a/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordInputDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordInputDataTransformer.php index d9c0581d18f..c53c99c4234 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordInputDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordInputDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Core\Serializer\AbstractItemNormalizer; use ApiPlatform\Tests\Fixtures\TestBundle\Document\User as UserDocument; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\RecoverPasswordInput; diff --git a/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordOutputDataTransformer.php b/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordOutputDataTransformer.php index 5a19c76b525..e62154d8f3f 100644 --- a/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordOutputDataTransformer.php +++ b/tests/Fixtures/TestBundle/DataTransformer/RecoverPasswordOutputDataTransformer.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\DataTransformer; -use ApiPlatform\Core\DataTransformer\DataTransformerInterface; +use ApiPlatform\DataTransformer\DataTransformerInterface; use ApiPlatform\Tests\Fixtures\TestBundle\Dto\RecoverPasswordOutput; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; use ApiPlatform\Tests\Fixtures\TestBundle\Entity\User; From cf22027d03a5404e90a6292819b5818125d5be39 Mon Sep 17 00:00:00 2001 From: Kevin Verschaeve Date: Tue, 9 Nov 2021 21:46:10 +0100 Subject: [PATCH 2/4] move Action directory --- src/{Core => }/Action/EntrypointAction.php | 2 +- src/{Core => }/Action/ExceptionAction.php | 2 +- src/{Core => }/Action/NotFoundAction.php | 2 +- src/{Core => }/Action/PlaceholderAction.php | 2 +- tests/{Core => }/Action/EntrypointActionTest.php | 4 ++-- tests/{Core => }/Action/ExceptionActionTest.php | 4 ++-- tests/{Core => }/Action/PlaceholderActionTest.php | 4 ++-- .../Fixture/disable_item_operation.php.inc | 4 ++-- .../Fixture/disable_item_operation.php.inc | 4 ++-- .../Bundle/DependencyInjection/ApiPlatformExtensionTest.php | 2 +- tests/Fixtures/TestBundle/Document/DisableItemOperation.php | 2 +- tests/Fixtures/TestBundle/Entity/DisableItemOperation.php | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) rename src/{Core => }/Action/EntrypointAction.php (96%) rename src/{Core => }/Action/ExceptionAction.php (99%) rename src/{Core => }/Action/NotFoundAction.php (93%) rename src/{Core => }/Action/PlaceholderAction.php (94%) rename tests/{Core => }/Action/EntrypointActionTest.php (92%) rename tests/{Core => }/Action/ExceptionActionTest.php (99%) rename tests/{Core => }/Action/PlaceholderActionTest.php (87%) diff --git a/src/Core/Action/EntrypointAction.php b/src/Action/EntrypointAction.php similarity index 96% rename from src/Core/Action/EntrypointAction.php rename to src/Action/EntrypointAction.php index c1d72aad76c..b4ed13f451c 100644 --- a/src/Core/Action/EntrypointAction.php +++ b/src/Action/EntrypointAction.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Action; +namespace ApiPlatform\Action; use ApiPlatform\Core\Api\Entrypoint; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; diff --git a/src/Core/Action/ExceptionAction.php b/src/Action/ExceptionAction.php similarity index 99% rename from src/Core/Action/ExceptionAction.php rename to src/Action/ExceptionAction.php index 1c029a92bd5..477c96bbaef 100644 --- a/src/Core/Action/ExceptionAction.php +++ b/src/Action/ExceptionAction.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Action; +namespace ApiPlatform\Action; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use ApiPlatform\Core\Util\ErrorFormatGuesser; diff --git a/src/Core/Action/NotFoundAction.php b/src/Action/NotFoundAction.php similarity index 93% rename from src/Core/Action/NotFoundAction.php rename to src/Action/NotFoundAction.php index 8dd73fb7090..546811fee66 100644 --- a/src/Core/Action/NotFoundAction.php +++ b/src/Action/NotFoundAction.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Action; +namespace ApiPlatform\Action; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; diff --git a/src/Core/Action/PlaceholderAction.php b/src/Action/PlaceholderAction.php similarity index 94% rename from src/Core/Action/PlaceholderAction.php rename to src/Action/PlaceholderAction.php index 5ccc9a33616..79cc83f8371 100644 --- a/src/Core/Action/PlaceholderAction.php +++ b/src/Action/PlaceholderAction.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Action; +namespace ApiPlatform\Action; /** * Placeholder returning the data passed in parameter. diff --git a/tests/Core/Action/EntrypointActionTest.php b/tests/Action/EntrypointActionTest.php similarity index 92% rename from tests/Core/Action/EntrypointActionTest.php rename to tests/Action/EntrypointActionTest.php index 194778b62e3..8793ef17698 100644 --- a/tests/Core/Action/EntrypointActionTest.php +++ b/tests/Action/EntrypointActionTest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Tests\Action; +namespace ApiPlatform\Tests\Action; -use ApiPlatform\Core\Action\EntrypointAction; +use ApiPlatform\Action\EntrypointAction; use ApiPlatform\Core\Api\Entrypoint; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection; diff --git a/tests/Core/Action/ExceptionActionTest.php b/tests/Action/ExceptionActionTest.php similarity index 99% rename from tests/Core/Action/ExceptionActionTest.php rename to tests/Action/ExceptionActionTest.php index 13038d8a36d..57d3c0734eb 100644 --- a/tests/Core/Action/ExceptionActionTest.php +++ b/tests/Action/ExceptionActionTest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Tests\Action; +namespace ApiPlatform\Tests\Action; -use ApiPlatform\Core\Action\ExceptionAction; +use ApiPlatform\Action\ExceptionAction; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Resource\ResourceMetadata; use ApiPlatform\Core\Tests\ProphecyTrait; diff --git a/tests/Core/Action/PlaceholderActionTest.php b/tests/Action/PlaceholderActionTest.php similarity index 87% rename from tests/Core/Action/PlaceholderActionTest.php rename to tests/Action/PlaceholderActionTest.php index c3682239436..2068d721b84 100644 --- a/tests/Core/Action/PlaceholderActionTest.php +++ b/tests/Action/PlaceholderActionTest.php @@ -11,9 +11,9 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Tests\Action; +namespace ApiPlatform\Tests\Action; -use ApiPlatform\Core\Action\PlaceholderAction; +use ApiPlatform\Action\PlaceholderAction; use PHPUnit\Framework\TestCase; /** diff --git a/tests/Core/Bridge/Rector/Rules/ApiResourceAnnotationToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc b/tests/Core/Bridge/Rector/Rules/ApiResourceAnnotationToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc index aa39f81e82d..3bbcf876259 100644 --- a/tests/Core/Bridge/Rector/Rules/ApiResourceAnnotationToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc +++ b/tests/Core/Bridge/Rector/Rules/ApiResourceAnnotationToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc @@ -2,7 +2,7 @@ namespace ApiPlatform\Tests\Bridge\Rector\Rules\ApiResourceAnnotationToApiResourceAttributeRector\Fixture; -use ApiPlatform\Core\Action\NotFoundAction; +use ApiPlatform\Action\NotFoundAction; use ApiPlatform\Core\Annotation\ApiResource; /** @@ -31,7 +31,7 @@ namespace ApiPlatform\Tests\Bridge\Rector\Rules\ApiResourceAnnotationToApiResour use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; -use ApiPlatform\Core\Action\NotFoundAction; +use ApiPlatform\Action\NotFoundAction; use ApiPlatform\Metadata\ApiResource; #[ApiResource] diff --git a/tests/Core/Bridge/Rector/Rules/LegacyApiResourceAttributeToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc b/tests/Core/Bridge/Rector/Rules/LegacyApiResourceAttributeToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc index 9bd344def45..804582ab322 100644 --- a/tests/Core/Bridge/Rector/Rules/LegacyApiResourceAttributeToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc +++ b/tests/Core/Bridge/Rector/Rules/LegacyApiResourceAttributeToApiResourceAttributeRector/Fixture/disable_item_operation.php.inc @@ -2,7 +2,7 @@ namespace ApiPlatform\Tests\Bridge\Rector\Rules\LegacyApiResourceAttributeToApiResourceAttributeRector\Fixture; -use ApiPlatform\Core\Action\NotFoundAction; +use ApiPlatform\Action\NotFoundAction; use ApiPlatform\Core\Annotation\ApiResource; #[ApiResource(collectionOperations: ['get'], itemOperations: ['get' => ['controller' => NotFoundAction::class, 'read' => false, 'output' => false]])] @@ -18,7 +18,7 @@ namespace ApiPlatform\Tests\Bridge\Rector\Rules\LegacyApiResourceAttributeToApiR use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; -use ApiPlatform\Core\Action\NotFoundAction; +use ApiPlatform\Action\NotFoundAction; use ApiPlatform\Metadata\ApiResource; #[ApiResource] diff --git a/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index b9aa7825ca3..13335d0d4ca 100644 --- a/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -16,7 +16,7 @@ use ApiPlatform\Api\IdentifiersExtractorInterface; use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Api\UrlGeneratorInterface; -use ApiPlatform\Core\Action\NotFoundAction; +use ApiPlatform\Action\NotFoundAction; use ApiPlatform\Core\Api\FilterInterface; use ApiPlatform\Core\Api\IdentifiersExtractorInterface as LegacyIdentifiersExtractorInterface; use ApiPlatform\Core\Api\IriConverterInterface as LegacyIriConverterInterface; diff --git a/tests/Fixtures/TestBundle/Document/DisableItemOperation.php b/tests/Fixtures/TestBundle/Document/DisableItemOperation.php index 2ba1c744b05..aa083412728 100644 --- a/tests/Fixtures/TestBundle/Document/DisableItemOperation.php +++ b/tests/Fixtures/TestBundle/Document/DisableItemOperation.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\Document; -use ApiPlatform\Core\Action\NotFoundAction; +use ApiPlatform\Action\NotFoundAction; use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; diff --git a/tests/Fixtures/TestBundle/Entity/DisableItemOperation.php b/tests/Fixtures/TestBundle/Entity/DisableItemOperation.php index e659557faa9..d294b450ef9 100644 --- a/tests/Fixtures/TestBundle/Entity/DisableItemOperation.php +++ b/tests/Fixtures/TestBundle/Entity/DisableItemOperation.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; -use ApiPlatform\Core\Action\NotFoundAction; +use ApiPlatform\Action\NotFoundAction; use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; From ed4ba6b8d41392e3c5ff545784bded11ae2afc8c Mon Sep 17 00:00:00 2001 From: Jade Bellereau Date: Tue, 9 Nov 2021 22:25:09 +0100 Subject: [PATCH 3/4] move validator --- .../Bundle/Resources/config/validator.xml | 2 +- .../EventListener/ValidateListener.php | 2 +- .../EventListener/ValidatorInterface.php | 33 +++++++++++++++++++ src/deprecated_interfaces.php | 1 + .../EventListener/ValidateListenerTest.php | 2 +- 5 files changed, 37 insertions(+), 3 deletions(-) rename src/{Core/Validator => Symfony}/EventListener/ValidateListener.php (98%) create mode 100644 src/Symfony/EventListener/ValidatorInterface.php diff --git a/src/Core/Bridge/Symfony/Bundle/Resources/config/validator.xml b/src/Core/Bridge/Symfony/Bundle/Resources/config/validator.xml index 2ea59e8eea8..33574b671ee 100644 --- a/src/Core/Bridge/Symfony/Bundle/Resources/config/validator.xml +++ b/src/Core/Bridge/Symfony/Bundle/Resources/config/validator.xml @@ -9,7 +9,7 @@ - + diff --git a/src/Core/Validator/EventListener/ValidateListener.php b/src/Symfony/EventListener/ValidateListener.php similarity index 98% rename from src/Core/Validator/EventListener/ValidateListener.php rename to src/Symfony/EventListener/ValidateListener.php index 494edef2188..d168f635b4b 100644 --- a/src/Core/Validator/EventListener/ValidateListener.php +++ b/src/Symfony/EventListener/ValidateListener.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace ApiPlatform\Core\Validator\EventListener; +namespace ApiPlatform\Symfony\EventListener; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Resource\ToggleableOperationAttributeTrait; diff --git a/src/Symfony/EventListener/ValidatorInterface.php b/src/Symfony/EventListener/ValidatorInterface.php new file mode 100644 index 00000000000..ac2c9a00830 --- /dev/null +++ b/src/Symfony/EventListener/ValidatorInterface.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Symfony\EventListener; + +use ApiPlatform\Core\Validator\Exception\ValidationException; + +/** + * Validates an item. + * + * @author Kévin Dunglas + */ +interface ValidatorInterface +{ + /** + * Validates an item. + * + * @param object $data + * + * @throws ValidationException + */ + public function validate($data, array $context = []); +} diff --git a/src/deprecated_interfaces.php b/src/deprecated_interfaces.php index a97d5c264e8..b12a6793b3b 100644 --- a/src/deprecated_interfaces.php +++ b/src/deprecated_interfaces.php @@ -14,4 +14,5 @@ return [ ApiPlatform\Core\DataTransformer\DataTransformerInitializerInterface::class => ApiPlatform\DataTransformer\DataTransformerInitializerInterface::class, ApiPlatform\Core\DataTransformer\DataTransformerInterface::class => ApiPlatform\DataTransformer\DataTransformerInterface::class, + ApiPlatform\Core\Validator\ValidatorInterface::class => ApiPlatform\Symfony\EventListener\ValidatorInterface::class, ]; diff --git a/tests/Core/Validator/EventListener/ValidateListenerTest.php b/tests/Core/Validator/EventListener/ValidateListenerTest.php index 7add8bf9190..9198e4ebd51 100644 --- a/tests/Core/Validator/EventListener/ValidateListenerTest.php +++ b/tests/Core/Validator/EventListener/ValidateListenerTest.php @@ -18,7 +18,7 @@ use ApiPlatform\Core\Tests\ProphecyTrait; use ApiPlatform\Core\Validator\EventListener\ValidateListener; use ApiPlatform\Core\Validator\Exception\ValidationException; -use ApiPlatform\Core\Validator\ValidatorInterface; +use ApiPlatform\Validator\ValidatorInterface; use ApiPlatform\Tests\Fixtures\DummyEntity; use PHPUnit\Framework\TestCase; use Prophecy\Argument; From f21878b0bc3f7e12273e1d75ab8986d9d9880a27 Mon Sep 17 00:00:00 2001 From: Kevin Verschaeve Date: Tue, 9 Nov 2021 22:50:46 +0100 Subject: [PATCH 4/4] fix interfaces and action alias --- .../DependencyInjection/ApiPlatformExtension.php | 15 +++++++++++++++ src/deprecation.php | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 0f7d4d22c5b..734c8b0857c 100644 --- a/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Core/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -96,6 +96,21 @@ public function load(array $configs, ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $deprecatedInterfaces = include __DIR__.'/../../../../../deprecated_interfaces.php'; + foreach ($deprecatedInterfaces as $oldInterface => $newInterface) { + if ($container->hasAlias($oldInterface)) { + throw new \LogicException(sprintf('Alias already exist for interface %s. Update xml first to use the new interface.', $oldInterface)); + } + + if ($container->hasAlias($newInterface)) { + $container->setAlias($oldInterface, $newInterface); + $container + ->getDefinition($oldInterface) + ->setDeprecated('api-platform/core', '2.7', sprintf('The interface %s is deprecated, use %s instead.', $oldInterface, $newInterface)) + ; + } + } + $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/src/deprecation.php b/src/deprecation.php index 5ea3491f0d4..436dc142ac2 100644 --- a/src/deprecation.php +++ b/src/deprecation.php @@ -106,6 +106,12 @@ ApiPlatform\Core\GraphQl\Type\Definition\UploadType::class => ApiPlatform\GraphQl\Type\Definition\UploadType::class, ApiPlatform\Core\GraphQl\Type\Definition\IterableType::class => ApiPlatform\GraphQl\Type\Definition\IterableType::class, ApiPlatform\Core\GraphQl\Type\TypesContainer::class => ApiPlatform\GraphQl\Type\TypesContainer::class, + + // Action + ApiPlatform\Core\Action\EntrypointAction::class => ApiPlatform\Action\EntrypointAction::class, + ApiPlatform\Core\Action\ExceptionAction::class => ApiPlatform\Action\ExceptionAction::class, + ApiPlatform\Core\Action\NotfoundAction::class => ApiPlatform\Action\NotfoundAction::class, + ApiPlatform\Core\Action\PlaceholderAction::class => ApiPlatform\Action\PlaceholderAction::class, ]; $deprecatedInterfaces = include 'deprecated_interfaces.php';