vendor/api-platform/core/src/Annotation/ApiResource.php line 237

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\Core\Annotation;
  12. use ApiPlatform\Core\Exception\InvalidArgumentException;
  13. /**
  14.  * ApiResource annotation.
  15.  *
  16.  * @author Kévin Dunglas <dunglas@gmail.com>
  17.  *
  18.  * @Annotation
  19.  * @Target({"CLASS"})
  20.  * @Attributes(
  21.  *     @Attribute("accessControl", type="string"),
  22.  *     @Attribute("accessControlMessage", type="string"),
  23.  *     @Attribute("attributes", type="array"),
  24.  *     @Attribute("cacheHeaders", type="array"),
  25.  *     @Attribute("collectionOperations", type="array"),
  26.  *     @Attribute("compositeIdentifier", type="bool"),
  27.  *     @Attribute("denormalizationContext", type="array"),
  28.  *     @Attribute("deprecationReason", type="string"),
  29.  *     @Attribute("description", type="string"),
  30.  *     @Attribute("elasticsearch", type="bool"),
  31.  *     @Attribute("fetchPartial", type="bool"),
  32.  *     @Attribute("forceEager", type="bool"),
  33.  *     @Attribute("formats", type="array"),
  34.  *     @Attribute("filters", type="string[]"),
  35.  *     @Attribute("graphql", type="array"),
  36.  *     @Attribute("hydraContext", type="array"),
  37.  *     @Attribute("input", type="mixed"),
  38.  *     @Attribute("iri", type="string"),
  39.  *     @Attribute("itemOperations", type="array"),
  40.  *     @Attribute("mercure", type="mixed"),
  41.  *     @Attribute("messenger", type="mixed"),
  42.  *     @Attribute("normalizationContext", type="array"),
  43.  *     @Attribute("openapiContext", type="array"),
  44.  *     @Attribute("order", type="array"),
  45.  *     @Attribute("output", type="mixed"),
  46.  *     @Attribute("paginationClientEnabled", type="bool"),
  47.  *     @Attribute("paginationClientItemsPerPage", type="bool"),
  48.  *     @Attribute("paginationClientPartial", type="bool"),
  49.  *     @Attribute("paginationEnabled", type="bool"),
  50.  *     @Attribute("paginationFetchJoinCollection", type="bool"),
  51.  *     @Attribute("paginationItemsPerPage", type="int"),
  52.  *     @Attribute("maximumItemsPerPage", type="int"),
  53.  *     @Attribute("paginationMaximumItemsPerPage", type="int"),
  54.  *     @Attribute("paginationPartial", type="bool"),
  55.  *     @Attribute("paginationViaCursor", type="array"),
  56.  *     @Attribute("routePrefix", type="string"),
  57.  *     @Attribute("security", type="string"),
  58.  *     @Attribute("securityMessage", type="string"),
  59.  *     @Attribute("securityPostDenormalize", type="string"),
  60.  *     @Attribute("securityPostDenormalizeMessage", type="string"),
  61.  *     @Attribute("shortName", type="string"),
  62.  *     @Attribute("stateless", type="bool"),
  63.  *     @Attribute("subresourceOperations", type="array"),
  64.  *     @Attribute("sunset", type="string"),
  65.  *     @Attribute("swaggerContext", type="array"),
  66.  *     @Attribute("urlGenerationStrategy", type="int"),
  67.  *     @Attribute("validationGroups", type="mixed"),
  68.  * )
  69.  */
  70. #[\Attribute(\Attribute::TARGET_CLASS)]
  71. final class ApiResource
  72. {
  73.     use AttributesHydratorTrait;
  74.     /**
  75.      * @var array<string, array>
  76.      */
  77.     private static $deprecatedAttributes = [
  78.         'accessControl' => ['security''2.5'],
  79.         'accessControlMessage' => ['securityMessage''2.5'],
  80.         'maximumItemsPerPage' => ['paginationMaximumItemsPerPage''2.6'],
  81.     ];
  82.     /**
  83.      * @see https://api-platform.com/docs/core/operations
  84.      *
  85.      * @var array
  86.      */
  87.     public $collectionOperations;
  88.     /**
  89.      * @var string
  90.      */
  91.     public $description;
  92.     /**
  93.      * @see https://api-platform.com/docs/core/graphql
  94.      *
  95.      * @var array
  96.      */
  97.     public $graphql;
  98.     /**
  99.      * @var string
  100.      */
  101.     public $iri;
  102.     /**
  103.      * @see https://api-platform.com/docs/core/operations
  104.      *
  105.      * @var array
  106.      */
  107.     public $itemOperations;
  108.     /**
  109.      * @var string
  110.      */
  111.     public $shortName;
  112.     /**
  113.      * @see https://api-platform.com/docs/core/subresources
  114.      *
  115.      * @var array
  116.      */
  117.     public $subresourceOperations;
  118.     /**
  119.      * @param string       $description
  120.      * @param array        $collectionOperations           https://api-platform.com/docs/core/operations
  121.      * @param array        $graphql                        https://api-platform.com/docs/core/graphql
  122.      * @param array        $itemOperations                 https://api-platform.com/docs/core/operations
  123.      * @param array        $subresourceOperations          https://api-platform.com/docs/core/subresources
  124.      * @param array        $cacheHeaders                   https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers
  125.      * @param array        $denormalizationContext         https://api-platform.com/docs/core/serialization/#using-serialization-groups
  126.      * @param string       $deprecationReason              https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
  127.      * @param bool         $elasticsearch                  https://api-platform.com/docs/core/elasticsearch/
  128.      * @param bool         $fetchPartial                   https://api-platform.com/docs/core/performance/#fetch-partial
  129.      * @param bool         $forceEager                     https://api-platform.com/docs/core/performance/#force-eager
  130.      * @param array        $formats                        https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
  131.      * @param string[]     $filters                        https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters
  132.      * @param string[]     $hydraContext                   https://api-platform.com/docs/core/extending-jsonld-context/#hydra
  133.      * @param string|false $input                          https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
  134.      * @param bool|array   $mercure                        https://api-platform.com/docs/core/mercure
  135.      * @param bool         $messenger                      https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus
  136.      * @param array        $normalizationContext           https://api-platform.com/docs/core/serialization/#using-serialization-groups
  137.      * @param array        $openapiContext                 https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
  138.      * @param array        $order                          https://api-platform.com/docs/core/default-order/#overriding-default-order
  139.      * @param string|false $output                         https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
  140.      * @param bool         $paginationClientEnabled        https://api-platform.com/docs/core/pagination/#for-a-specific-resource-1
  141.      * @param bool         $paginationClientItemsPerPage   https://api-platform.com/docs/core/pagination/#for-a-specific-resource-3
  142.      * @param bool         $paginationClientPartial        https://api-platform.com/docs/core/pagination/#for-a-specific-resource-6
  143.      * @param array        $paginationViaCursor            https://api-platform.com/docs/core/pagination/#cursor-based-pagination
  144.      * @param bool         $paginationEnabled              https://api-platform.com/docs/core/pagination/#for-a-specific-resource
  145.      * @param bool         $paginationFetchJoinCollection  https://api-platform.com/docs/core/pagination/#controlling-the-behavior-of-the-doctrine-orm-paginator
  146.      * @param int          $paginationItemsPerPage         https://api-platform.com/docs/core/pagination/#changing-the-number-of-items-per-page
  147.      * @param int          $paginationMaximumItemsPerPage  https://api-platform.com/docs/core/pagination/#changing-maximum-items-per-page
  148.      * @param bool         $paginationPartial              https://api-platform.com/docs/core/performance/#partial-pagination
  149.      * @param string       $routePrefix                    https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations
  150.      * @param string       $security                       https://api-platform.com/docs/core/security
  151.      * @param string       $securityMessage                https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
  152.      * @param string       $securityPostDenormalize        https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
  153.      * @param string       $securityPostDenormalizeMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
  154.      * @param bool         $stateless
  155.      * @param string       $sunset                         https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed
  156.      * @param array        $swaggerContext                 https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
  157.      * @param array        $validationGroups               https://api-platform.com/docs/core/validation/#using-validation-groups
  158.      * @param int          $urlGenerationStrategy
  159.      *
  160.      * @throws InvalidArgumentException
  161.      */
  162.     public function __construct(
  163.         $description null,
  164.         ?array $collectionOperations null,
  165.         ?array $graphql null,
  166.         ?string $iri null,
  167.         ?array $itemOperations null,
  168.         ?string $shortName null,
  169.         ?array $subresourceOperations null,
  170.         // attributes
  171.         ?array $attributes null,
  172.         ?array $cacheHeaders null,
  173.         ?array $denormalizationContext null,
  174.         ?string $deprecationReason null,
  175.         ?bool $elasticsearch null,
  176.         ?bool $fetchPartial null,
  177.         ?bool $forceEager null,
  178.         ?array $formats null,
  179.         ?array $filters null,
  180.         ?array $hydraContext null,
  181.         $input null,
  182.         $mercure null,
  183.         $messenger null,
  184.         ?array $normalizationContext null,
  185.         ?array $openapiContext null,
  186.         ?array $order null,
  187.         $output null,
  188.         ?bool $paginationClientEnabled null,
  189.         ?bool $paginationClientItemsPerPage null,
  190.         ?bool $paginationClientPartial null,
  191.         ?array $paginationViaCursor null,
  192.         ?bool $paginationEnabled null,
  193.         ?bool $paginationFetchJoinCollection null,
  194.         ?int $paginationItemsPerPage null,
  195.         ?int $paginationMaximumItemsPerPage null,
  196.         ?bool $paginationPartial null,
  197.         ?string $routePrefix null,
  198.         ?string $security null,
  199.         ?string $securityMessage null,
  200.         ?string $securityPostDenormalize null,
  201.         ?string $securityPostDenormalizeMessage null,
  202.         ?bool $stateless null,
  203.         ?string $sunset null,
  204.         ?array $swaggerContext null,
  205.         ?array $validationGroups null,
  206.         ?int $urlGenerationStrategy null,
  207.         ?bool $compositeIdentifier null
  208.     ) {
  209.         if (!\is_array($description)) { // @phpstan-ignore-line Doctrine annotations support
  210.             [$publicProperties$configurableAttributes] = self::getConfigMetadata();
  211.             foreach ($publicProperties as $prop => $_) {
  212.                 $this->{$prop} = ${$prop};
  213.             }
  214.             $description = [];
  215.             foreach ($configurableAttributes as $attribute => $_) {
  216.                 $description[$attribute] = ${$attribute};
  217.             }
  218.         }
  219.         $this->hydrateAttributes($description ?? []); // @phpstan-ignore-line
  220.     }
  221. }