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

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