Skip to content

Commit

Permalink
[attributes] add support for class constants
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Mar 1, 2022
1 parent 6feb15a commit b3da10a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Analysers/AttributeAnnotationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ 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();
}
$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

0 comments on commit b3da10a

Please sign in to comment.