Skip to content

Commit 11dafa5

Browse files
committed
feat: add ApiProperty PHP 8 attribute
1 parent 3f4bd56 commit 11dafa5

14 files changed

+233
-438
lines changed

src/Annotation/ApiProperty.php

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@
3333
* @Attribute("swaggerContext", type="array")
3434
* )
3535
*/
36+
#[\Attribute(\Attribute::TARGET_PROPERTY|\Attribute::TARGET_METHOD)]
3637
final class ApiProperty
3738
{
3839
use AttributesHydratorTrait;
3940

41+
/**
42+
* @var array<string, array>
43+
*/
44+
private static $deprecatedAttributes = [];
45+
4046
/**
4147
* @var string
4248
*/
@@ -88,66 +94,64 @@ final class ApiProperty
8894
public $example;
8995

9096
/**
91-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
92-
*
93-
* @var string
94-
*/
95-
private $deprecationReason;
96-
97-
/**
98-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
99-
*
100-
* @var bool
101-
*/
102-
private $fetchable;
103-
104-
/**
105-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
106-
*
107-
* @var bool
108-
*/
109-
private $fetchEager;
110-
111-
/**
112-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
113-
*
114-
* @var array
115-
*/
116-
private $jsonldContext;
117-
118-
/**
119-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
97+
* @param string $description
98+
* @param bool $readable
99+
* @param bool $writable
100+
* @param bool $readableLink
101+
* @param bool $writableLink
102+
* @param bool $required
103+
* @param bool $iri
104+
* @param bool $identifier
105+
* @param string|int|float|bool|array $default
106+
* @param string|int|float|bool|array|null $example
120107
*
121-
* @var array
122-
*/
123-
private $openapiContext;
124-
125-
/**
126-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
108+
* @param string $deprecationReason
109+
* @param bool $fetchable
110+
* @param bool $fetchEager
111+
* @param array $jsonldContext
112+
* @param array $openapiContext
113+
* @param bool $push
114+
* @param string $security
115+
* @param array $swaggerContext
127116
*
128-
* @var bool
129-
*/
130-
private $push;
131-
132-
/**
133-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
134-
*
135-
* @var string
136-
*/
137-
private $security;
138-
139-
/**
140-
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
141-
*
142-
* @var array
143-
*/
144-
private $swaggerContext;
145-
146-
/**
147117
* @throws InvalidArgumentException
148118
*/
149-
public function __construct(array $values = [])
150-
{
151-
$this->hydrateAttributes($values);
119+
public function __construct(
120+
$description = null,
121+
?bool $readable = null,
122+
?bool $writable = null,
123+
?bool $readableLink = null,
124+
?bool $writableLink = null,
125+
?bool $required = null,
126+
?string $iri = null,
127+
?bool $identifier = null,
128+
$default = null,
129+
$example = null,
130+
131+
// attributes
132+
?array $attributes = null,
133+
?string $deprecationReason = null,
134+
?bool $fetchable = null,
135+
?bool $fetchEager = null,
136+
?array $jsonldContext = null,
137+
?array $openapiContext = null,
138+
?bool $push = null,
139+
?string $security = null,
140+
?array $swaggerContext = null
141+
) {
142+
if (!is_array($description)) {
143+
[$publicProperties, $configurableAttributes] = self::getConfigMetadata();
144+
145+
foreach ($publicProperties as $prop => $_) {
146+
$this->{$prop} = $$prop;
147+
}
148+
149+
$description = [];
150+
foreach ($configurableAttributes as $attribute => $_) {
151+
$description[$attribute] = $$attribute;
152+
}
153+
}
154+
155+
$this->hydrateAttributes($description);
152156
}
153157
}

0 commit comments

Comments
 (0)