vendor/api-platform/core/src/Metadata/Resource/DeprecationMetadataTrait.php line 50

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;
  12. use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
  13. /**
  14.  * @internal
  15.  */
  16. trait DeprecationMetadataTrait
  17. {
  18.     private $camelCaseToSnakeCaseNameConverter;
  19.     public function getKeyValue(string $key, $value)
  20.     {
  21.         if (!$this->camelCaseToSnakeCaseNameConverter) {
  22.             $this->camelCaseToSnakeCaseNameConverter = new CamelCaseToSnakeCaseNameConverter();
  23.         }
  24.         if ('attributes' === $key) {
  25.             trigger_deprecation('api-platform/core', '2.7', 'The "attributes" option is deprecated and will be renamed to "extra_properties".');
  26.             $key = 'extra_properties';
  27.         } elseif ('iri' === $key) {
  28.             trigger_deprecation('api-platform/core', '2.7', 'The "iri" is deprecated and will be renamed to "types".');
  29.             $key = 'types';
  30.             $value = [$value];
  31.         } elseif ('validation_groups' === $key) {
  32.             trigger_deprecation('api-platform/core', '2.7', 'The "validation_groups" is deprecated and will be renamed to "validation_context" having an array with a "groups" key.');
  33.             $key = 'validation_context';
  34.             $value = ['groups' => $value];
  35.         } elseif ('access_control' === $key) {
  36.             $key = 'security';
  37.             trigger_deprecation('api-platform/core', '2.7', 'The "access_control" option is deprecated and will be renamed to "security".');
  38.         } elseif ('access_control_message' === $key) {
  39.             $key = 'security_message';
  40.             trigger_deprecation('api-platform/core', '2.7', 'The "access_control_message" option is deprecated and will be renamed to "security_message".');
  41.         } elseif ('path' === $key) {
  42.             $key = 'uri_template';
  43.             trigger_deprecation('api-platform/core', '2.7', 'The "path" option is deprecated and will be renamed to "uri_template".');
  44.         // Transform default value to an empty array if null
  45.         } elseif (\in_array($key, ['denormalization_context', 'normalization_context', 'hydra_context', 'openapi_context', 'order', 'pagination_via_cursor', 'exception_to_status'], true)) {
  46.             if (null === $value) {
  47.                 $value = [];
  48.             } elseif (!\is_array($value)) {
  49.                 $value = [$value];
  50.             }
  51.         } elseif ('route_prefix' === $key) {
  52.             $value = \is_string($value) ? $value : '';
  53.         } elseif ('swagger_context' === $key) {
  54.             trigger_deprecation('api-platform/core', '2.7', 'The "swagger_context" option is deprecated and will be removed, use "openapi_context".');
  55.             $key = 'openapi_context';
  56.             $value = $value ?? [];
  57.         } elseif ('query_parameter_validation_enabled' === $key) {
  58.             $value = !$value ? false : $value;
  59.         // GraphQl related keys
  60.         } elseif (\in_array($key, ['collection_query', 'item_query', 'mutation'], true)) {
  61.             trigger_deprecation('api-platform/core', '2.7', 'To specify a GraphQl resolver use "resolver" instead of "mutation", "item_query" or "collection_query".');
  62.             $key = 'resolver';
  63.         } elseif ('filters' === $key) {
  64.             $value = null === $value ? [] : $value;
  65.         } elseif ('graphql' === $key) {
  66.             trigger_deprecation('api-platform/core', '2.7', 'The "graphql" option is deprecated and will be renamed to "graphQlOperations".');
  67.             $key = 'graphQlOperations';
  68.         } elseif ('identifiers' === $key) {
  69.             $key = 'uriVariables';
  70.         } elseif ('doctrine_mongodb' === $key) {
  71.             $key = 'extra_properties';
  72.             $value = ['doctrine_mongodb' => $value];
  73.         }
  74.         return [$this->camelCaseToSnakeCaseNameConverter->denormalize($key), $value];
  75.     }
  76. }