vendor/api-platform/core/src/Core/Annotation/ApiProperty.php line 110

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. * ApiProperty annotation.
  15. *
  16. * @author Kévin Dunglas <dunglas@gmail.com>
  17. *
  18. * @Annotation
  19. *
  20. * @Target({"METHOD", "PROPERTY"})
  21. *
  22. * @Attributes(
  23. *
  24. * @Attribute("deprecationReason", type="string"),
  25. * @Attribute("fetchable", type="bool"),
  26. * @Attribute("fetchEager", type="bool"),
  27. * @Attribute("openapiContext", type="array"),
  28. * @Attribute("jsonldContext", type="array"),
  29. * @Attribute("push", type="bool"),
  30. * @Attribute("security", type="string"),
  31. * @Attribute("securityPostDenormalize", type="string"),
  32. * @Attribute("swaggerContext", type="array")
  33. * )
  34. */
  35. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER)]
  36. final class ApiProperty
  37. {
  38. use AttributesHydratorTrait;
  39. /**
  40. * @var array<string, array>
  41. */
  42. private static $deprecatedAttributes = [];
  43. /**
  44. * @var string
  45. */
  46. public $description;
  47. /**
  48. * @var bool
  49. */
  50. public $readable;
  51. /**
  52. * @var bool
  53. */
  54. public $writable;
  55. /**
  56. * @var bool
  57. */
  58. public $readableLink;
  59. /**
  60. * @var bool
  61. */
  62. public $writableLink;
  63. /**
  64. * @var bool
  65. */
  66. public $required;
  67. /**
  68. * @var string
  69. */
  70. public $iri;
  71. /**
  72. * @var bool
  73. */
  74. public $identifier;
  75. /**
  76. * @var string|int|float|bool|array|null
  77. */
  78. public $default;
  79. /**
  80. * @var string|int|float|bool|array|null
  81. */
  82. public $example;
  83. public $types;
  84. public $builtinTypes;
  85. /**
  86. * @param string $description
  87. * @param string|int|float|bool|array $default
  88. * @param string|int|float|bool|array|null $example
  89. *
  90. * @throws InvalidArgumentException
  91. */
  92. public function __construct(
  93. $description = null,
  94. bool $readable = null,
  95. bool $writable = null,
  96. bool $readableLink = null,
  97. bool $writableLink = null,
  98. bool $required = null,
  99. string $iri = null,
  100. bool $identifier = null,
  101. $default = null,
  102. $example = null,
  103. // attributes
  104. array $attributes = null,
  105. string $deprecationReason = null,
  106. bool $fetchable = null,
  107. bool $fetchEager = null,
  108. array $jsonldContext = null,
  109. array $openapiContext = null,
  110. bool $push = null,
  111. string $security = null,
  112. array $swaggerContext = null,
  113. string $securityPostDenormalize = null,
  114. ?array $types = [],
  115. ?array $builtinTypes = []
  116. ) {
  117. if (!\is_array($description)) { // @phpstan-ignore-line Doctrine annotations support
  118. [$publicProperties, $configurableAttributes] = self::getConfigMetadata();
  119. foreach ($publicProperties as $prop => $_) {
  120. $this->{$prop} = ${$prop};
  121. }
  122. $description = [];
  123. foreach ($configurableAttributes as $attribute => $_) {
  124. $description[$attribute] = ${$attribute};
  125. }
  126. }
  127. $this->hydrateAttributes($description);
  128. }
  129. }