Skip to content

Commit

Permalink
Merge pull request #1 from event-engine/feature/add-missing-types
Browse files Browse the repository at this point in the history
Add missing types
  • Loading branch information
sandrokeil authored Feb 22, 2022
2 parents e506205 + f3e98be commit e78c504
Show file tree
Hide file tree
Showing 32 changed files with 5,015 additions and 811 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.3"
- "7.4"
- "8.0"
os: [ubuntu-latest]
experimental: [false]
include:
- php-version: "8.0"
os: ubuntu-latest
experimental: true
runs-on: ${{ matrix.os }}
name: PHP ${{ matrix.php-version }} Test on ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
Expand Down
16 changes: 16 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

$config = new Prooph\CS\Config\Prooph();
$finder = $config->getFinder();

$finder->exclude('vendor');
$finder->in(__DIR__);
$finder->append(['.php_cs']);

$cacheDir = \getenv('TRAVIS') ? \getenv('HOME') . '/.php-cs-fixer' : __DIR__;

$config->setCacheFile($cacheDir . '/.php_cs.cache');

return $config;
10 changes: 0 additions & 10 deletions .php_cs

This file was deleted.

63 changes: 41 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,64 @@ $ composer require event-engine/php-inspectio-graph-cody

## Usage

> See unit tests in `tests` folder for comprehensive examples and how a Cody JSON looks like.
> 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
<?php

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 $json is a JSON string in Cody format
// assume $filter is a callable to filter names / labels
// assume $filter is a callable to filter sticky / node names
$filter = static function (string $value) {
return \trim($value);
};

// create a node instance from json
// assume $json is a JSON string in Cody format
$node = JsonNode::fromJson($json);

// analyze the given Cody node
$eventSourcingAnalyzer = new EventSourcingAnalyzer($node, $filter);
$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

// get a list of all commands
$commands = $eventSourcingAnalyzer->commandMap();
$identity = $connection->identity();

// get a list of all domain events
$events = $eventSourcingAnalyzer->eventMap();
if ($identity->type() === VertexType::TYPE_AGGREGATE) {
// get connected commands of connection, in this case the aggregate
$commands = $connection->from()->filterByType(VertexType::TYPE_COMMAND);

// get a list of all aggregates
$aggregates = $eventSourcingAnalyzer->aggregateMap();
// get connected events of connection, in this case the aggregate
$events = $connection->to()->filterByType(VertexType::TYPE_EVENT);

foreach ($aggregates as $aggregate) {
// returns the aggregate
$aggregate->aggregate();
// get parent of identity, could be a feature or bounded context
$parent = $connection->parent();

// returns the corresponding commands for this aggregate
$aggregate->commandMap();
if ($parent->type() === VertexType::TYPE_FEATURE) {
// get parent connection to get connected vertices
$parentConnection = $analyzer->connection($parent->id());

// returns the corresponding domain events for this aggregate
$aggregate->eventMap();

// returns commands with corresponding domain event(s) (the connection between command -> domain event(s))
$aggregate->commandsToEventsMap();
// 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
);
```
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
}
},
"require": {
"php": "^7.3 || ^8.0",
"event-engine/php-inspectio-graph": "^0.3.0",
"php": "^7.4 || ^8.0",
"event-engine/php-inspectio-graph": "^0.4.0",
"ext-json": "*"
},
"require-dev": {
Expand All @@ -40,11 +40,10 @@
"phpstan/phpstan": "^0.12.33",
"phpstan/phpstan-strict-rules": "^0.12.4",
"phpunit/phpunit": "^9.2.6",
"prooph/php-cs-fixer-config": "^0.3",
"roave/security-advisories": "dev-master"
"prooph/php-cs-fixer-config": "^0.5.0",
"roave/security-advisories": "dev-latest"
},
"suggest": {
"open-code-modeling/php-code-generator": "To use the static factory methods of Transformator classes for Code Generator workflow configuration",
"open-code-modeling/php-filter": "For pre-configured filters for proper class / method / property names etc."
},
"conflict": {
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ parameters:
level: 5
paths:
- src/
ignoreErrors:
29 changes: 29 additions & 0 deletions src/BoundedContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* @see https://github.com/event-engine/php-inspectio-graph-cody for the canonical source repository
* @copyright https://github.com/event-engine/php-inspectio-graph-cody/blob/master/COPYRIGHT.md
* @license https://github.com/event-engine/php-inspectio-graph-cody/blob/master/LICENSE.md MIT License
*/

declare(strict_types=1);

namespace EventEngine\InspectioGraphCody;

use EventEngine\InspectioGraph\BoundedContextType;
use EventEngine\InspectioGraph\Metadata;

final class BoundedContext extends Vertex implements BoundedContextType
{
protected const TYPE = self::TYPE_BOUNDED_CONTEXT;

/**
* @var Metadata\Metadata|null
*/
protected $metadataInstance;

public function metadataInstance(): ?Metadata\Metadata
{
return $this->metadataInstance;
}
}
4 changes: 2 additions & 2 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace EventEngine\InspectioGraphCody;

use EventEngine\InspectioGraph\EventType;
use EventEngine\InspectioGraph\DocumentType;
use EventEngine\InspectioGraph\Metadata;

final class Document extends Vertex implements EventType
final class Document extends Vertex implements DocumentType
{
protected const TYPE = self::TYPE_DOCUMENT;

Expand Down
Loading

0 comments on commit e78c504

Please sign in to comment.