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

  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\Put;
  14. use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
  15. class DeprecationResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
  16. {
  17.     // Hashmap to avoid triggering too many deprecations
  18.     private array $deprecated;
  19.     public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $decorated)
  20.     {
  21.     }
  22.     public function create(string $resourceClass): ResourceMetadataCollection
  23.     {
  24.         $resourceMetadataCollection $this->decorated->create($resourceClass);
  25.         foreach ($resourceMetadataCollection as $resourceMetadata) {
  26.             foreach ($resourceMetadata->getOperations() as $operation) {
  27.                 if ($operation instanceof Put && null === ($operation->getExtraProperties()['standard_put'] ?? null)) {
  28.                     $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.');
  29.                 }
  30.             }
  31.         }
  32.         return $resourceMetadataCollection;
  33.     }
  34.     private function triggerDeprecationOnce(Operation $operationstring $deprecationNamestring $deprecationReason): void
  35.     {
  36.         if (isset($this->deprecated[$operation->getClass().$deprecationName])) {
  37.             return;
  38.         }
  39.         $this->deprecated[$operation->getClass().$deprecationName] = true;
  40.         trigger_deprecation('api-platform/core''3.1'$deprecationReason);
  41.     }
  42. }