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

[attributes] add support for class constants #1147

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions src/Analysers/AttributeAnnotationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ public function build(\Reflector $reflector, Context $context): array
}
}
}

if ($reflector instanceof \ReflectionClass) {
foreach ($reflector->getReflectionConstants() as $rc) {
foreach ($rc->getAttributes(Property::class) as $attribute) {
$instance = $attribute->newInstance();
if (Generator::isDefault($instance->property)) {
$instance->property = $rc->getName();
}
if (Generator::isDefault($instance->type)) {
$instance->type = 'const';
cdaguerre marked this conversation as resolved.
Show resolved Hide resolved
$instance->const = [$rc->getValue()];
cdaguerre marked this conversation as resolved.
Show resolved Hide resolved
}
$annotations[] = $instance;
}
}
}
} finally {
Generator::$context = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use OpenApi\Generator;

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER)]
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT)]
class Property extends \OpenApi\Annotations\Property
{
/**
Expand Down