Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferror committed Feb 3, 2024
1 parent d6d805c commit bec3143
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Attribute/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct(
public readonly string $name,
public array $properties = [],
public array $channels = [],
public array $operations = [],
) {
}

Expand Down
5 changes: 5 additions & 0 deletions src/Attribute/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function toArray(): array
),
];
}

public function addChannel(Channel $channel): void
{
$this->channels[] = $channel;
}
}
11 changes: 11 additions & 0 deletions src/DocumentationStrategy/AttributeDocumentationStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Operation>[] $operationAttributes */
$operationAttributes = $reflection->getAttributes(Operation::class);

/** @var ReflectionAttribute<Channel>[] $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);
Expand Down

0 comments on commit bec3143

Please sign in to comment.