PHP code example of event-engine / php-inspectio-graph-cody
1. Go to this page and download the library: Download event-engine/php-inspectio-graph-cody library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
event-engine / php-inspectio-graph-cody example snippets
declare(strict_types=1);
use EventEngine\InspectioGraph\VertexConnectionMap;
use EventEngine\InspectioGraph\VertexType;
use EventEngine\InspectioGraphCody\EventSourcingAnalyzer;
use EventEngine\InspectioGraphCody\EventSourcingGraph;
use EventEngine\InspectioGraphCody\JsonNode;
// assume $filter is a callable to filter sticky / node names
$filter = static function (string $value) {
return \trim($value);
};
// assume $json is a JSON string in Cody format
$node = JsonNode::fromJson($json);
$analyzer = new EventSourcingAnalyzer(new EventSourcingGraph($filter));
$connection = $analyzer->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
);
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.