diff --git a/src/Attribute/Message.php b/src/Attribute/Message.php index 73f8d98..daf7faf 100644 --- a/src/Attribute/Message.php +++ b/src/Attribute/Message.php @@ -17,6 +17,7 @@ public function __construct( public readonly string $name, public array $properties = [], public array $channels = [], + public array $operations = [], ) { } diff --git a/src/Attribute/Operation.php b/src/Attribute/Operation.php index 743c3a6..f52fcdb 100644 --- a/src/Attribute/Operation.php +++ b/src/Attribute/Operation.php @@ -28,4 +28,9 @@ public function toArray(): array ), ]; } + + public function addChannel(Channel $channel): void + { + $this->channels[] = $channel; + } } diff --git a/src/DocumentationStrategy/AttributeDocumentationStrategy.php b/src/DocumentationStrategy/AttributeDocumentationStrategy.php index d3fe12b..931f7e9 100644 --- a/src/DocumentationStrategy/AttributeDocumentationStrategy.php +++ b/src/DocumentationStrategy/AttributeDocumentationStrategy.php @@ -6,6 +6,7 @@ use Ferror\AsyncapiDocBundle\Attribute\Channel; use Ferror\AsyncapiDocBundle\Attribute\Message; +use Ferror\AsyncapiDocBundle\Attribute\Operation; use ReflectionAttribute; use ReflectionClass; use ReflectionException; @@ -36,7 +37,17 @@ public function document(string $class): Message throw new DocumentationStrategyException('Error: class ' . $class . ' must have at least ' . Message::class . ' attribute.'); } + /** @var ReflectionAttribute[] $operationAttributes */ + $operationAttributes = $reflection->getAttributes(Operation::class); + + /** @var ReflectionAttribute[] $channelAttributes */ + $channelAttributes = $reflection->getAttributes(Channel::class); + $message = $messageAttributes[0]->newInstance(); + $operation = $operationAttributes[0]->newInstance(); + $channel = $channelAttributes[0]->newInstance(); + + $operation->addChannel($channel); foreach ($this->propertyExtractor->extract($class) as $property) { $message->addProperty($property);