Skip to content

fix: unwanted deprecations #4685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Core/Api/OperationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

namespace ApiPlatform\Core\Api;

use ApiPlatform\Metadata\Operation;

trigger_deprecation('api-platform', '2.7', sprintf('%s is deprecated, an operation can be a collection using the %s::collection property.', OperationType::class, Operation::class));

final class OperationType
{
public const ITEM = 'item';
Expand Down
1 change: 1 addition & 0 deletions src/Core/Bridge/Symfony/Messenger/DataPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use ApiPlatform\Exception\OperationNotFoundException;
use ApiPlatform\Exception\ResourceClassNotFoundException;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Symfony\Messenger\DispatchTrait;
use ApiPlatform\Util\ClassInfoTrait;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function __construct(Reader $reader = null, PropertyMetadataFactoryInterf
*/
public function create(string $resourceClass, string $property, array $options = []): PropertyMetadata
{
if (false === ($options['deprecate'] ?? null)) {
trigger_deprecation('api-platform/core', '2.7', sprintf('Decorating the legacy %s is deprecated, use %s instead.', PropertyMetadataFactoryInterface::class, \ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface::class));
}

$parentPropertyMetadata = null;
if ($this->decorated) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function __construct(Reader $reader, PropertyMetadataFactoryInterface $de
{
$this->reader = $reader;
$this->decorated = $decorated;

trigger_deprecation('api-platform/core', '2.7', 'Use alternate urls instead of declaring subresources on properties.');
}

/**
Expand All @@ -62,6 +60,8 @@ public function create(string $resourceClass, string $property, array $options =

$annotation = $this->reader->getPropertyAnnotation($reflectionProperty, ApiSubresource::class);
if ($annotation instanceof ApiSubresource) {
trigger_deprecation('api-platform/core', '2.7', sprintf('Declare a new resource instead of using ApiSubresource on the property "%s".', $property));

return $this->updateMetadata($annotation, $propertyMetadata, $resourceClass, $property);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Util\ResourceClassInfoTrait;
use ApiPlatform\Exception\ResourceClassNotFoundException;
use ApiPlatform\Util\ResourceClassInfoTrait;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface as SerializerClassMetadataFactoryInterface;
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Swagger/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace ApiPlatform\Core\Swagger\Serializer;

use ApiPlatform\Api\FilterLocatorTrait;
use ApiPlatform\Core\Api\FilterCollection;
use ApiPlatform\Core\Api\FilterLocatorTrait;
use ApiPlatform\Core\Api\FormatsProviderInterface;
use ApiPlatform\Core\Api\IdentifiersExtractorInterface;
use ApiPlatform\Core\Api\OperationAwareFormatsProviderInterface;
Expand All @@ -38,6 +38,7 @@
use ApiPlatform\JsonSchema\TypeFactoryInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\OpenApi\OpenApi;
use ApiPlatform\OpenApi\Serializer\ApiGatewayNormalizer;
use ApiPlatform\PathResolver\OperationPathResolverInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\PropertyInfo\Type;
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Common/State/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(ManagerRegistry $managerRegistry)
$this->managerRegistry = $managerRegistry;
}

public function supports($data, array $identifiers = [], ?string $operationName = null, array $context = []): bool
public function supports($data, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
{
return null !== $this->getManager($data);
}
Expand Down Expand Up @@ -62,7 +62,7 @@ private function remove($data, array $context = [])
$manager->flush();
}

public function process($data, array $identifiers = [], ?string $operationName = null, array $context = [])
public function process($data, array $uriVariables = [], ?string $operationName = null, array $context = [])
{
if (\array_key_exists('operation', $context) && $context['operation']->isDelete()) {
return $this->remove($data);
Expand Down
6 changes: 3 additions & 3 deletions src/Doctrine/Odm/State/CollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
$this->collectionExtensions = $collectionExtensions;
}

public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = [])
public function provide(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = [])
{
/** @var DocumentManager $manager */
$manager = $this->managerRegistry->getManagerForClass($resourceClass);
Expand All @@ -59,7 +59,7 @@ public function provide(string $resourceClass, array $identifiers = [], ?string

$aggregationBuilder = $repository->createAggregationBuilder();

$this->handleLinks($aggregationBuilder, $identifiers, $context, $resourceClass, $operationName);
$this->handleLinks($aggregationBuilder, $uriVariables, $context, $resourceClass, $operationName);

foreach ($this->collectionExtensions as $extension) {
$extension->applyToCollection($aggregationBuilder, $resourceClass, $operationName, $context);
Expand All @@ -81,7 +81,7 @@ public function provide(string $resourceClass, array $identifiers = [], ?string
return $aggregationBuilder->hydrate($resourceClass)->execute($executeOptions);
}

public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
{
if (!$this->managerRegistry->getManagerForClass($resourceClass) instanceof DocumentManager) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/Doctrine/Odm/State/ItemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
$this->itemExtensions = $itemExtensions;
}

public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = [])
public function provide(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = [])
{
/** @var DocumentManager $manager */
$manager = $this->managerRegistry->getManagerForClass($resourceClass);

$fetchData = $context['fetch_data'] ?? true;
if (!$fetchData) {
return $manager->getReference($resourceClass, reset($identifiers));
return $manager->getReference($resourceClass, reset($uriVariables));
}

/** @var ObjectRepository $repository */
Expand All @@ -66,10 +66,10 @@ public function provide(string $resourceClass, array $identifiers = [], ?string

$aggregationBuilder = $repository->createAggregationBuilder();

$this->handleLinks($aggregationBuilder, $identifiers, $context, $resourceClass, $operationName);
$this->handleLinks($aggregationBuilder, $uriVariables, $context, $resourceClass, $operationName);

foreach ($this->itemExtensions as $extension) {
$extension->applyToItem($aggregationBuilder, $resourceClass, $identifiers, $operationName, $context);
$extension->applyToItem($aggregationBuilder, $resourceClass, $uriVariables, $operationName, $context);

if ($extension instanceof AggregationResultItemExtensionInterface && $extension->supportsResult($resourceClass, $operationName, $context)) {
return $extension->getResult($aggregationBuilder, $resourceClass, $operationName, $context);
Expand All @@ -87,7 +87,7 @@ public function provide(string $resourceClass, array $identifiers = [], ?string
return $aggregationBuilder->hydrate($resourceClass)->execute($executeOptions)->current() ?: null;
}

public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
{
if (!$this->managerRegistry->getManagerForClass($resourceClass) instanceof DocumentManager) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/Doctrine/Orm/State/CollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
$this->collectionExtensions = $collectionExtensions;
}

public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = [])
public function provide(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = [])
{
/** @var EntityManagerInterface $manager */
$manager = $this->managerRegistry->getManagerForClass($resourceClass);
Expand All @@ -62,7 +62,7 @@ public function provide(string $resourceClass, array $identifiers = [], ?string
$queryBuilder = $repository->createQueryBuilder('o');
$queryNameGenerator = new QueryNameGenerator();

$this->handleLinks($queryBuilder, $identifiers, $queryNameGenerator, $context, $resourceClass, $operationName);
$this->handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, $context, $resourceClass, $operationName);

foreach ($this->collectionExtensions as $extension) {
$extension->applyToCollection($queryBuilder, $queryNameGenerator, $resourceClass, $operationName, $context);
Expand All @@ -75,7 +75,7 @@ public function provide(string $resourceClass, array $identifiers = [], ?string
return $queryBuilder->getQuery()->getResult();
}

public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
{
if (!$this->managerRegistry->getManagerForClass($resourceClass) instanceof EntityManagerInterface) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/Doctrine/Orm/State/ItemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public function __construct(ResourceMetadataCollectionFactoryInterface $resource
$this->itemExtensions = $itemExtensions;
}

public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = [])
public function provide(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = [])
{
/** @var EntityManagerInterface $manager */
$manager = $this->managerRegistry->getManagerForClass($resourceClass);

$fetchData = $context['fetch_data'] ?? true;
if (!$fetchData) {
return $manager->getReference($resourceClass, $identifiers);
return $manager->getReference($resourceClass, $uriVariables);
}

/** @var EntityRepository $repository */
Expand All @@ -66,10 +66,10 @@ public function provide(string $resourceClass, array $identifiers = [], ?string
$queryBuilder = $repository->createQueryBuilder('o');
$queryNameGenerator = new QueryNameGenerator();

$this->handleLinks($queryBuilder, $identifiers, $queryNameGenerator, $context, $resourceClass, $operationName);
$this->handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, $context, $resourceClass, $operationName);

foreach ($this->itemExtensions as $extension) {
$extension->applyToItem($queryBuilder, $queryNameGenerator, $resourceClass, $identifiers, $operationName, $context);
$extension->applyToItem($queryBuilder, $queryNameGenerator, $resourceClass, $uriVariables, $operationName, $context);

if ($extension instanceof QueryResultItemExtensionInterface && $extension->supportsResult($resourceClass, $operationName, $context)) {
return $extension->getResult($queryBuilder, $resourceClass, $operationName, $context);
Expand All @@ -79,7 +79,7 @@ public function provide(string $resourceClass, array $identifiers = [], ?string
return $queryBuilder->getQuery()->getOneOrNullResult();
}

public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
{
if (!$this->managerRegistry->getManagerForClass($resourceClass) instanceof EntityManagerInterface) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Elasticsearch/State/CollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(Client $client, DocumentMetadataFactoryInterface $do
/**
* {@inheritdoc}
*/
public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
{
try {
$resourceMetadata = $this->resourceMetadataCollectionFactory->create($resourceClass);
Expand All @@ -83,7 +83,7 @@ public function supports(string $resourceClass, array $identifiers = [], ?string
/**
* {@inheritdoc}
*/
public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = [])
public function provide(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = [])
{
$documentMetadata = $this->documentMetadataFactory->create($resourceClass);
$body = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Elasticsearch/State/ItemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(Client $client, DocumentMetadataFactoryInterface $do
/**
* {@inheritdoc}
*/
public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
{
try {
$resourceMetadata = $this->resourceMetadataCollectionFactory->create($resourceClass);
Expand All @@ -74,15 +74,15 @@ public function supports(string $resourceClass, array $identifiers = [], ?string
/**
* {@inheritdoc}
*/
public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = [])
public function provide(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = [])
{
$documentMetadata = $this->documentMetadataFactory->create($resourceClass);

try {
$document = $this->client->get([
'index' => $documentMetadata->getIndex(),
'type' => $documentMetadata->getType(),
'id' => (string) reset($identifiers),
'id' => (string) reset($uriVariables),
]);
} catch (Missing404Exception $e) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQl/Resolver/Stage/ReadStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __invoke(?string $resourceClass, ?string $rootClass, string $ope
return [];
}

$identifiers = [];
$uriVariables = [];
$normalizationContext['filters'] = $this->getNormalizedFilters($args);

if (!$operation && $resourceClass) {
Expand All @@ -106,11 +106,11 @@ public function __invoke(?string $resourceClass, ?string $rootClass, string $ope
/** @var ResolveInfo $info */
$info = $context['info'];
if (isset($source[$info->fieldName], $source[ItemNormalizer::ITEM_IDENTIFIERS_KEY], $source[ItemNormalizer::ITEM_RESOURCE_CLASS_KEY])) {
$identifiers = $source[ItemNormalizer::ITEM_IDENTIFIERS_KEY];
$uriVariables = $source[ItemNormalizer::ITEM_IDENTIFIERS_KEY];
$normalizationContext['linkClass'] = $source[ItemNormalizer::ITEM_RESOURCE_CLASS_KEY];
}

return $this->provider->provide($resourceClass, $identifiers, $operationName, $normalizationContext);
return $this->provider->provide($resourceClass, $uriVariables, $operationName, $normalizationContext);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/HttpCache/EventListener/AddTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function onKernelResponse(ResponseEvent $event): void
$resources = $request->attributes->get('_resources');
if (isset($attributes['collection_operation_name']) || ($attributes['subresource_context']['collection'] ?? false) || ($operation && $operation->isCollection())) {
// Allows to purge collections
$identifiers = $this->getOperationIdentifiers($operation, $request->attributes->all(), $attributes['resource_class']);
$iri = $this->iriConverter instanceof IriConverterInterface ? $this->iriConverter->getIriFromResourceClass($attributes['resource_class'], $attributes['operation_name'] ?? null, UrlGeneratorInterface::ABS_PATH, ['identifiers_values' => $identifiers]) : $this->iriConverter->getIriFromResourceClass($attributes['resource_class'], UrlGeneratorInterface::ABS_PATH);
$uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $attributes['resource_class']);
$iri = $this->iriConverter instanceof IriConverterInterface ? $this->iriConverter->getIriFromResourceClass($attributes['resource_class'], $attributes['operation_name'] ?? null, UrlGeneratorInterface::ABS_PATH, ['identifiers_values' => $uriVariables]) : $this->iriConverter->getIriFromResourceClass($attributes['resource_class'], UrlGeneratorInterface::ABS_PATH);
$resources[$iri] = $iri;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Hydra/Serializer/ErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace ApiPlatform\Hydra\Serializer;

use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait;
use ApiPlatform\Problem\Serializer\ErrorNormalizerTrait;
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApi/Serializer/ErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace ApiPlatform\JsonApi\Serializer;

use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait;
use ApiPlatform\Problem\Serializer\ErrorNormalizerTrait;
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace ApiPlatform\Metadata\Property\Factory;

use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface as LegacyPropertyMetadataFactoryInterface;
use ApiPlatform\Exception\PropertyNotFoundException;
use ApiPlatform\Exception\ResourceClassNotFoundException;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Property\DeprecationMetadataTrait;

Expand Down Expand Up @@ -48,7 +48,7 @@ public function create(string $resourceClass, string $property, array $options =
}

try {
$legacyPropertyMetadata = $this->legacyPropertyMetadataFactory->create($resourceClass, $property, $options);
$legacyPropertyMetadata = $this->legacyPropertyMetadataFactory->create($resourceClass, $property, ['deprecate' => false] + $options);
} catch (PropertyNotFoundException|ResourceClassNotFoundException $propertyNotFoundException) {
return $propertyMetadata;
}
Expand Down
Loading