vendor/api-platform/core/src/Metadata/Resource/Factory/DeprecationResourceMetadataCollectionFactory.php line 66

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Metadata\Resource\Factory;
  12. use ApiPlatform\Metadata\Operation;
  13. use ApiPlatform\Metadata\Operations;
  14. use ApiPlatform\Metadata\Put;
  15. use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
  16. /**
  17.  * Triggers resource deprecations.
  18.  *
  19.  * @final
  20.  *
  21.  * @internal
  22.  */
  23. class DeprecationResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
  24. {
  25.     // Hashmap to avoid triggering too many deprecations
  26.     private array $deprecated;
  27.     public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $decorated)
  28.     {
  29.     }
  30.     public function create(string $resourceClass): ResourceMetadataCollection
  31.     {
  32.         $resourceMetadataCollection $this->decorated->create($resourceClass);
  33.         foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
  34.             $newOperations = [];
  35.             foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
  36.                 $extraProperties $operation->getExtraProperties();
  37.                 if ($operation instanceof Put && null === ($extraProperties['standard_put'] ?? null)) {
  38.                     $this->triggerDeprecationOnce($operation'extraProperties["standard_put"]''In API Platform 4 PUT will always replace the data, use extraProperties["standard_put"] to "true" on every operation to avoid breaking PUT\'s behavior. Use PATCH to use the old behavior.');
  39.                 }
  40.                 $newOperations[$operationName] = $operation;
  41.             }
  42.             $resourceMetadataCollection[$i] = $resourceMetadata->withOperations(new Operations($newOperations));
  43.         }
  44.         return $resourceMetadataCollection;
  45.     }
  46.     private function triggerDeprecationOnce(Operation $operationstring $deprecationNamestring $deprecationReason): void
  47.     {
  48.         if (isset($this->deprecated[$operation->getClass().$deprecationName])) {
  49.             return;
  50.         }
  51.         $this->deprecated[$operation->getClass().$deprecationName] = true;
  52.         trigger_deprecation('api-platform/core''3.1'$deprecationReason);
  53.     }
  54. }