vendor/api-platform/core/src/Metadata/Property/DeprecationMetadataTrait.php line 38

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\Property;
  12. use ApiPlatform\Core\Annotation\ApiProperty;
  13. use ApiPlatform\Metadata\ApiProperty as ApiPropertyMetadata;
  14. use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
  15. /**
  16.  * @internal
  17.  */
  18. trait DeprecationMetadataTrait
  19. {
  20.     private $camelCaseToSnakeCaseNameConverter;
  21.     private function withDeprecatedAttributes(ApiPropertyMetadata $propertyMetadata, array $attributes): ApiPropertyMetadata
  22.     {
  23.         $extraProperties = [];
  24.         if (!$this->camelCaseToSnakeCaseNameConverter) {
  25.             $this->camelCaseToSnakeCaseNameConverter = new CamelCaseToSnakeCaseNameConverter();
  26.         }
  27.         foreach ($attributes as $key => $value) {
  28.             $propertyName $this->camelCaseToSnakeCaseNameConverter->denormalize($key);
  29.             if (method_exists($propertyMetadata$methodName 'with'.ucfirst($propertyName))) {
  30.                 trigger_deprecation('api-platform''2.7'sprintf('Using "%s" inside attributes on the "%s" annotation is deprecated, use "%s" on the attribute "%s" instead'$keyApiProperty::class, $propertyNameApiPropertyMetadata::class));
  31.                 $propertyMetadata $propertyMetadata->{$methodName}($value);
  32.                 continue;
  33.             }
  34.             $extraProperties[$key] = $value;
  35.         }
  36.         return $propertyMetadata->withExtraProperties($propertyMetadata->getExtraProperties() + $extraProperties);
  37.     }
  38. }