Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add an ApiResource PHP 8 attribute #3851

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/tests/Fixtures/app/var/
/tests/Fixtures/app/public/bundles/
/vendor/
/Dockerfile
118 changes: 61 additions & 57 deletions src/Annotation/ApiProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@
* @Attribute("swaggerContext", type="array")
* )
*/
#[\Attribute(\Attribute::TARGET_PROPERTY|\Attribute::TARGET_METHOD)]
final class ApiProperty
{
use AttributesHydratorTrait;

/**
* @var array<string, array>
*/
private static $deprecatedAttributes = [];

/**
* @var string
*/
Expand Down Expand Up @@ -88,66 +94,64 @@ final class ApiProperty
public $example;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var string
*/
private $deprecationReason;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var bool
*/
private $fetchable;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var bool
*/
private $fetchEager;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var array
*/
private $jsonldContext;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
* @param string $description
* @param bool $readable
* @param bool $writable
* @param bool $readableLink
* @param bool $writableLink
* @param bool $required
* @param bool $iri
* @param bool $identifier
* @param string|int|float|bool|array $default
* @param string|int|float|bool|array|null $example
*
* @var array
*/
private $openapiContext;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
* @param string $deprecationReason
* @param bool $fetchable
* @param bool $fetchEager
* @param array $jsonldContext
* @param array $openapiContext
* @param bool $push
* @param string $security
* @param array $swaggerContext
*
* @var bool
*/
private $push;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var string
*/
private $security;

/**
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
*
* @var array
*/
private $swaggerContext;

/**
* @throws InvalidArgumentException
*/
public function __construct(array $values = [])
{
$this->hydrateAttributes($values);
public function __construct(
$description = null,
?bool $readable = null,
?bool $writable = null,
?bool $readableLink = null,
?bool $writableLink = null,
?bool $required = null,
?string $iri = null,
?bool $identifier = null,
$default = null,
$example = null,

// attributes
?array $attributes = null,
?string $deprecationReason = null,
?bool $fetchable = null,
?bool $fetchEager = null,
?array $jsonldContext = null,
?array $openapiContext = null,
?bool $push = null,
?string $security = null,
?array $swaggerContext = null
) {
if (!is_array($description)) {
[$publicProperties, $configurableAttributes] = self::getConfigMetadata();

foreach ($publicProperties as $prop => $_) {
$this->{$prop} = $$prop;
}

$description = [];
foreach ($configurableAttributes as $attribute => $_) {
$description[$attribute] = $$attribute;
}
}

$this->hydrateAttributes($description);
}
}
Loading