Skip to content

Commit

Permalink
feat: operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferror committed Feb 3, 2024
1 parent bec3143 commit aa2c967
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/Attribute/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function toArray(): array
'name' => $this->name,
'properties' => array_map(static fn(PropertyInterface $property) => $property->toArray(), $this->properties),
'channels' => array_map(static fn(Channel $channel) => $channel->toArray(), $this->channels),
'operations' => array_map(static fn(Operation $operation) => $operation->toArray(), $this->operations),
];
}

Expand All @@ -40,6 +41,11 @@ public function addChannel(Channel $channel): void
$this->channels[] = $channel;
}

public function addOperation(Operation $operation): void
{
$this->operations[] = $operation;
}

public function enrich(self $self): self
{
// UPDATE EXISTING
Expand Down
18 changes: 8 additions & 10 deletions src/DocumentationStrategy/AttributeDocumentationStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,7 @@ 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 All @@ -61,6 +51,14 @@ public function document(string $class): Message
$message->addChannel($channelAttribute->newInstance());
}

// Channels are optional as it's possible to document just Messages.
/** @var ReflectionAttribute<Operation>[] $operationAttributes */
$operationAttributes = $reflection->getAttributes(Operation::class);

foreach ($operationAttributes as $operationAttribute) {
$message->addOperation($operationAttribute->newInstance());
}

return $message;
}
}

0 comments on commit aa2c967

Please sign in to comment.