Skip to content

Commit fe30e9e

Browse files
committed
fix: remove deprecations when bc flag is false
1 parent 21ba5d5 commit fe30e9e

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

src/Core/Api/IdentifiersExtractor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ final class IdentifiersExtractor implements IdentifiersExtractorInterface
3434
private $propertyMetadataFactory;
3535
private $propertyAccessor;
3636

37-
public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, PropertyAccessorInterface $propertyAccessor = null, ResourceClassResolverInterface $resourceClassResolver = null)
37+
public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, PropertyAccessorInterface $propertyAccessor = null, ResourceClassResolverInterface $resourceClassResolver = null, bool $metadataBackwardCompatibilityLayer = null)
3838
{
39-
trigger_deprecation('api-platform/core', '2.7', sprintf('The service "%s" is deprecated, use %s instead.', self::class, NewIdentifiersExtractor::class));
4039
$this->propertyNameCollectionFactory = $propertyNameCollectionFactory;
4140
$this->propertyMetadataFactory = $propertyMetadataFactory;
4241
$this->propertyAccessor = $propertyAccessor ?? PropertyAccess::createPropertyAccessor();
@@ -45,6 +44,10 @@ public function __construct(PropertyNameCollectionFactoryInterface $propertyName
4544
if (null === $this->resourceClassResolver) {
4645
@trigger_error(sprintf('Not injecting %s in the IdentifiersExtractor might introduce cache issues with object identifiers.', ResourceClassResolverInterface::class), \E_USER_DEPRECATED);
4746
}
47+
48+
if ($metadataBackwardCompatibilityLayer) {
49+
trigger_deprecation('api-platform/core', '2.7', sprintf('The service "%s" is deprecated, use %s instead.', self::class, NewIdentifiersExtractor::class));
50+
}
4851
}
4952

5053
/**

src/Core/EventListener/ReadListener.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ final class ReadListener
4949
public const OPERATION_ATTRIBUTE_KEY = 'read';
5050

5151
private $serializerContextBuilder;
52+
private $metadataBackwardCompatibilityLayer;
5253

53-
public function __construct(CollectionDataProviderInterface $collectionDataProvider, ItemDataProviderInterface $itemDataProvider, SubresourceDataProviderInterface $subresourceDataProvider = null, SerializerContextBuilderInterface $serializerContextBuilder = null, IdentifierConverterInterface $identifierConverter = null, ResourceMetadataFactoryInterface $resourceMetadataFactory = null, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
54+
public function __construct(CollectionDataProviderInterface $collectionDataProvider, ItemDataProviderInterface $itemDataProvider, SubresourceDataProviderInterface $subresourceDataProvider = null, SerializerContextBuilderInterface $serializerContextBuilder = null, IdentifierConverterInterface $identifierConverter = null, ResourceMetadataFactoryInterface $resourceMetadataFactory = null, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, bool $metadataBackwardCompatibilityLayer = null)
5455
{
5556
$this->collectionDataProvider = $collectionDataProvider;
5657
$this->itemDataProvider = $itemDataProvider;
@@ -59,7 +60,11 @@ public function __construct(CollectionDataProviderInterface $collectionDataProvi
5960
$this->identifierConverter = $identifierConverter;
6061
$this->resourceMetadataFactory = $resourceMetadataFactory;
6162
$this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
62-
trigger_deprecation('api-platform/core', '2.7', sprintf('The listener "%s" is deprecated and will be replaced by "%s" in 3.0.', __CLASS__, SymfonyReadListener::class));
63+
$this->metadataBackwardCompatibilityLayer = $metadataBackwardCompatibilityLayer;
64+
65+
if ($metadataBackwardCompatibilityLayer || null === $metadataBackwardCompatibilityLayer) {
66+
trigger_deprecation('api-platform/core', '2.7', sprintf('The listener "%s" is deprecated and will be replaced by "%s" in 3.0.', __CLASS__, SymfonyReadListener::class));
67+
}
6368
}
6469

6570
/**
@@ -82,6 +87,10 @@ public function onKernelRequest(RequestEvent $event): void
8287
return;
8388
}
8489

90+
if (false === $this->metadataBackwardCompatibilityLayer) {
91+
trigger_deprecation('api-platform/core', '2.7', 'The operation you requested uses legacy metadata, switch to #[ApiPlatform\Metadata\ApiResource].');
92+
}
93+
8594
if (null === $filters = $request->attributes->get('_api_filters')) {
8695
$queryString = RequestParser::getQueryString($request);
8796
$filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;

src/Core/EventListener/WriteListener.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,20 @@ final class WriteListener
4545
private $dataPersister;
4646
/** @var IriConverterLegacyInterface|IriConverterInterface|null */
4747
private $iriConverter;
48+
private $metadataBackwardCompatibilityLayer;
4849

49-
public function __construct(DataPersisterInterface $dataPersister, $iriConverter = null, ResourceMetadataFactoryInterface $resourceMetadataFactory = null, ResourceClassResolverInterface $resourceClassResolver = null, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
50+
public function __construct(DataPersisterInterface $dataPersister, $iriConverter = null, ResourceMetadataFactoryInterface $resourceMetadataFactory = null, ResourceClassResolverInterface $resourceClassResolver = null, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, bool $metadataBackwardCompatibilityLayer = null)
5051
{
5152
$this->dataPersister = $dataPersister;
5253
$this->iriConverter = $iriConverter;
5354
$this->resourceMetadataFactory = $resourceMetadataFactory;
5455
$this->resourceClassResolver = $resourceClassResolver;
5556
$this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
57+
$this->metadataBackwardCompatibilityLayer = $metadataBackwardCompatibilityLayer;
5658

57-
trigger_deprecation('api-platform/core', '2.7', sprintf('The listener "%s" is deprecated and will be removed in 3.0, use "%s" instead', __CLASS__, \ApiPlatform\Symfony\EventListener\WriteListener::class));
59+
if ($metadataBackwardCompatibilityLayer || null === $metadataBackwardCompatibilityLayer) {
60+
trigger_deprecation('api-platform/core', '2.7', sprintf('The listener "%s" is deprecated and will be removed in 3.0, use "%s" instead', __CLASS__, \ApiPlatform\Symfony\EventListener\WriteListener::class));
61+
}
5862
}
5963

6064
/**
@@ -77,6 +81,10 @@ public function onKernelView(ViewEvent $event): void
7781
return;
7882
}
7983

84+
if (false === $this->metadataBackwardCompatibilityLayer) {
85+
trigger_deprecation('api-platform/core', '2.7', 'The operation you requested uses legacy metadata, switch to #[ApiPlatform\Metadata\ApiResource].');
86+
}
87+
8088
if (!$this->dataPersister->supports($controllerResult, $attributes)) {
8189
return;
8290
}

src/Core/Operation/Factory/SubresourceOperationFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ final class SubresourceOperationFactory implements SubresourceOperationFactoryIn
3838

3939
public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, PathSegmentNameGeneratorInterface $pathSegmentNameGenerator, IdentifiersExtractorInterface $identifiersExtractor = null)
4040
{
41-
trigger_deprecation('api-platform/core', '2.7', 'Subresources are deprecated, use alternate URLs instead.');
4241
$this->resourceMetadataFactory = $resourceMetadataFactory;
4342
$this->propertyNameCollectionFactory = $propertyNameCollectionFactory;
4443
$this->propertyMetadataFactory = $propertyMetadataFactory;
@@ -51,7 +50,10 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa
5150
*/
5251
public function create(string $resourceClass): array
5352
{
53+
trigger_deprecation('api-platform/core', '2.7', 'Subresources are deprecated, use alternate URLs instead.');
54+
5455
$tree = [];
56+
5557
try {
5658
$this->computeSubresourceOperations($resourceClass, $tree);
5759
} catch (ResourceClassNotFoundException $e) {

src/Symfony/Bundle/Resources/config/legacy/identifiers.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<argument type="service" id="api_platform.metadata.property.metadata_factory.legacy" />
1010
<argument type="service" id="api_platform.property_accessor" />
1111
<argument type="service" id="api_platform.resource_class_resolver" />
12+
<argument>%api_platform.metadata_backward_compatibility_layer%</argument>
1213
</service>
1314

1415
<service id="api_platform.identifiers_extractor.cached" class="ApiPlatform\Core\Api\CachedIdentifiersExtractor" decorates="api_platform.identifiers_extractor.legacy" public="false">

src/Symfony/Bundle/Resources/config/v3/backward_compatibility.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
<argument type="service" id="api_platform.serializer.context_builder" />
5050
<argument type="service" id="api_platform.identifier.converter" />
5151
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
52+
<argument>null</argument>
53+
<argument>%api_platform.metadata_backward_compatibility_layer%</argument>
5254

5355
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="4" />
5456
</service>

0 commit comments

Comments
 (0)