https://github.com/event-engine/php-inspectio-graph-cody
https://github.com/event-engine/php-inspectio-graph-cody
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/event-engine/php-inspectio-graph-cody
- Owner: event-engine
- License: mit
- Created: 2020-11-27T08:48:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-22T16:31:00.000Z (over 3 years ago)
- Last Synced: 2025-02-22T05:19:17.695Z (4 months ago)
- Language: PHP
- Size: 137 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Event Engine - PHP InspectIO Graph Cody
Implementation of the [*InspectIO Graph* specification](https://github.com/event-engine/php-inspectio-graph "InspectIO Graph specification")
for [Cody Bot](https://github.com/event-engine/inspectio/wiki/PHP-Cody-Tutorial "PHP Cody Tutorial") to generate PHP code
based on the [InspectIO Event Map](https://github.com/event-engine/inspectio "InspectIO Event Map").## Installation
```bash
$ composer require event-engine/php-inspectio-graph-cody
```## Usage
> See unit tests (`EventSourcingAnalyzerTest`) in `tests` folder for comprehensive examples and how a Cody JSON looks like.
The following example gives a quick overview how to retrieve information from the `EventSourcingAnalyzer`.
```php
analyse($node); // analyze the Cody JSON node
// call $analyzer->analyse($anotherNode) again with other nodes to build up the graph$identity = $connection->identity();
if ($identity->type() === VertexType::TYPE_AGGREGATE) {
// get connected commands of connection, in this case the aggregate
$commands = $connection->from()->filterByType(VertexType::TYPE_COMMAND);// get connected events of connection, in this case the aggregate
$events = $connection->to()->filterByType(VertexType::TYPE_EVENT);// get parent of identity, could be a feature or bounded context
$parent = $connection->parent();if ($parent->type() === VertexType::TYPE_FEATURE) {
// get parent connection to get connected vertices
$parentConnection = $analyzer->connection($parent->id());// cycle through all children (vertices e.g. commands, events, etc) of this parent
foreach ($parentConnection->children() as $child) {
if ($child->type() === VertexType::TYPE_COMMAND) {
// ...
}
}
}
}// search in graph for first document in forwarding mode (a "to" connection)
$documentConnection = $analyzer->graph()->findInGraph(
$identity->id(),
static function (VertexType $vertex): bool {
return $vertex->type() === VertexType::TYPE_DOCUMENT;
},
VertexConnectionMap::WALK_FORWARD
);
```