{"id":24498896,"url":"https://github.com/event-engine/php-inspectio-graph-cody","last_synced_at":"2025-03-15T07:14:23.430Z","repository":{"id":43707242,"uuid":"316447383","full_name":"event-engine/php-inspectio-graph-cody","owner":"event-engine","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-22T16:31:00.000Z","size":140,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T05:19:17.695Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/event-engine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-27T08:48:35.000Z","updated_at":"2022-02-22T16:23:38.000Z","dependencies_parsed_at":"2022-08-21T10:50:25.439Z","dependency_job_id":null,"html_url":"https://github.com/event-engine/php-inspectio-graph-cody","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-inspectio-graph-cody","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-inspectio-graph-cody/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-inspectio-graph-cody/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-inspectio-graph-cody/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/event-engine","download_url":"https://codeload.github.com/event-engine/php-inspectio-graph-cody/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243695600,"owners_count":20332629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T22:12:41.476Z","updated_at":"2025-03-15T07:14:23.405Z","avatar_url":"https://github.com/event-engine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Event Engine - PHP InspectIO Graph Cody\n\nImplementation of the [*InspectIO Graph* specification](https://github.com/event-engine/php-inspectio-graph \"InspectIO Graph specification\") \nfor [Cody Bot](https://github.com/event-engine/inspectio/wiki/PHP-Cody-Tutorial \"PHP Cody Tutorial\") to generate PHP code\nbased on the [InspectIO Event Map](https://github.com/event-engine/inspectio \"InspectIO Event Map\").\n\n## Installation\n\n```bash\n$ composer require event-engine/php-inspectio-graph-cody\n```\n\n## Usage\n\n\u003e See unit tests (`EventSourcingAnalyzerTest`) in `tests` folder for comprehensive examples and how a Cody JSON looks like.\n\nThe following example gives a quick overview how to retrieve information from the `EventSourcingAnalyzer`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse EventEngine\\InspectioGraph\\VertexConnectionMap;\nuse EventEngine\\InspectioGraph\\VertexType;\nuse EventEngine\\InspectioGraphCody\\EventSourcingAnalyzer;\nuse EventEngine\\InspectioGraphCody\\EventSourcingGraph;\nuse EventEngine\\InspectioGraphCody\\JsonNode;\n\n// assume $filter is a callable to filter sticky / node names\n$filter = static function (string $value) {\n    return \\trim($value);\n};\n\n// assume $json is a JSON string in Cody format\n$node = JsonNode::fromJson($json);\n\n$analyzer = new EventSourcingAnalyzer(new EventSourcingGraph($filter));\n$connection = $analyzer-\u003eanalyse($node); // analyze the Cody JSON node\n// call $analyzer-\u003eanalyse($anotherNode) again with other nodes to build up the graph\n\n$identity = $connection-\u003eidentity();\n\nif ($identity-\u003etype() === VertexType::TYPE_AGGREGATE) {\n    // get connected commands of connection, in this case the aggregate\n    $commands = $connection-\u003efrom()-\u003efilterByType(VertexType::TYPE_COMMAND);\n\n    // get connected events of connection, in this case the aggregate\n    $events = $connection-\u003eto()-\u003efilterByType(VertexType::TYPE_EVENT);\n\n    // get parent of identity, could be a feature or bounded context\n    $parent = $connection-\u003eparent();\n\n    if ($parent-\u003etype() === VertexType::TYPE_FEATURE) {\n        // get parent connection to get connected vertices\n        $parentConnection = $analyzer-\u003econnection($parent-\u003eid());\n\n        // cycle through all children (vertices e.g. commands, events, etc) of this parent\n        foreach ($parentConnection-\u003echildren() as $child) {\n            if ($child-\u003etype() === VertexType::TYPE_COMMAND) {\n                // ...\n            }\n        }\n    }\n}\n\n// search in graph for first document in forwarding mode (a \"to\" connection)\n$documentConnection = $analyzer-\u003egraph()-\u003efindInGraph(\n    $identity-\u003eid(),\n    static function (VertexType $vertex): bool {\n        return $vertex-\u003etype() === VertexType::TYPE_DOCUMENT;\n    },\n    VertexConnectionMap::WALK_FORWARD\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevent-engine%2Fphp-inspectio-graph-cody","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevent-engine%2Fphp-inspectio-graph-cody","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevent-engine%2Fphp-inspectio-graph-cody/lists"}