{"id":29746378,"url":"https://github.com/event-engine/php-code-generator-event-engine-ast","last_synced_at":"2025-07-26T07:11:02.927Z","repository":{"id":43694463,"uuid":"314587009","full_name":"event-engine/php-code-generator-event-engine-ast","owner":"event-engine","description":"PHP Code Generator based on PHP Abstract Syntax Tree. It provides a comprehensive high level API to generate PHP code from InspectIO for Event Engine.","archived":false,"fork":false,"pushed_at":"2022-09-16T06:55:01.000Z","size":223,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T20:11:25.558Z","etag":null,"topics":["code-generator","php"],"latest_commit_sha":null,"homepage":"","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-20T15:03:34.000Z","updated_at":"2024-05-17T11:17:35.000Z","dependencies_parsed_at":"2022-08-21T08:40:42.619Z","dependency_job_id":null,"html_url":"https://github.com/event-engine/php-code-generator-event-engine-ast","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/event-engine/php-code-generator-event-engine-ast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-code-generator-event-engine-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-code-generator-event-engine-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-code-generator-event-engine-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-code-generator-event-engine-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/event-engine","download_url":"https://codeload.github.com/event-engine/php-code-generator-event-engine-ast/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/event-engine%2Fphp-code-generator-event-engine-ast/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267133958,"owners_count":24040789,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["code-generator","php"],"created_at":"2025-07-26T07:11:01.887Z","updated_at":"2025-07-26T07:11:02.918Z","avatar_url":"https://github.com/event-engine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Event Engine - PHP Code Generator via PHP AST\n\nPHP Code Generator based on PHP Abstract Syntax Tree. It provides a comprehensive high level API to\ngenerate PHP code from [prooph board](https://prooph-board.com/ \"prooph board\") for [Event Engine](https://event-engine.github.io/ \"Event Engine\").\n\nIt supports the following code generation:\n\n- Event Engine API description for commands, aggregates and domain events\n- Command, aggregate and domain event classes with corresponding value objects based on metadata (JSON schema)\n- Glue code between command, corresponding aggregate and corresponding domain events \n\n## Installation\n\nRun the following to install this library:\n\n```bash\n$ composer require event-engine/php-code-generator-event-engine-ast\n```\n\nIf you want to use `Config\\PreConfiguredNaming` please install also `laminas/laminas-filter`.\n\n```bash\n$ composer require laminas/laminas-filter\n```\n\n## Usage\n\nThe code generation is based on the [InspectIO Graph](https://github.com/event-engine/php-inspectio-graph \"InspectIO Graph\").\nThere are two implementations of *InspectIO Graph*. The first one is based on the [InspectIO GraphML graph format](https://github.com/event-engine/php-inspectio-graph-ml \"InspectIO Graph GraphML\") \nand the second is based on the [InspectIO Cody graph format](https://github.com/event-engine/php-inspectio-graph-cody \"InspectIO Graph Cody\").\n\n\u003e It is recommended to use the [InspectIO Cody graph format](https://github.com/event-engine/php-inspectio-graph-cody \"InspectIO Graph Cody\")\nbecause it's based on a simple JSON structure. \n\nFor out-of-the-box usage you can use the preconfigured configuration file `Config\\PreConfiguredNaming`. You are free to \nchange the configuration for your needs. The following example uses the preconfigured configurations.\n\n\u003e Feel free to modify the generated PHP code, because your changes will *NOT* be overwritten (can be overwritten if you want)!\n\n### Code Generation\n\nThe following quick example shows how to generate PHP code for *Command* classes with the preconfigured configuration.\n\n- Please see command unit tests (`tests/CommantTest.php`) for comprehensive examples which code will be generated.\n- Please see event unit tests (`tests/EventTest.php`) for comprehensive examples which code will be generated.\n- Please see aggregate unit tests (`tests/AggregateTest.php`) for comprehensive examples which code will be generated.\n- Please see query unit tests (`tests/QueryTest.php`) for comprehensive examples which code will be generated.\n- Please see value object unit tests (`tests/ValueObjectTest.php`) for comprehensive examples which code will be generated.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse EventEngine\\CodeGenerator\\EventEngineAst\\Command;\nuse EventEngine\\CodeGenerator\\EventEngineAst\\Config\\EventEngineConfig;\nuse EventEngine\\CodeGenerator\\EventEngineAst\\Config\\PreConfiguredNaming;\nuse EventEngine\\CodeGenerator\\EventEngineAst\\Metadata;\nuse EventEngine\\InspectioGraphCody\\EventSourcingAnalyzer;\nuse EventEngine\\InspectioGraphCody\\EventSourcingGraph;\n\n$contextName = 'Acme';\n$basePath = '../app';\n$composerFile = $basePath . '/composer.json';\n\n$config = new EventEngineConfig();\n$config-\u003esetBasePath($basePath);\n$config-\u003eaddComposerInfo($composerFile);\n\n$namingConfig = new PreConfiguredNaming($config);\n$namingConfig-\u003esetDefaultContextName($contextName);\n\n$analyzer = new EventSourcingAnalyzer(\n    new EventSourcingGraph(\n        $config-\u003egetFilterConstName(),\n        new Metadata\\MetadataFactory(new Metadata\\InspectioJson\\MetadataFactory())\n    )\n);\n// create class to generate code for commands\n// same behaviour for the other classes e.g. EventEngine\\CodeGenerator\\EventEngineAst\\Event\n$commandGenerator = new Command($namingConfig);\n\n// contains all generated PHP classes\n$fileCollection = \\OpenCodeModeling\\CodeAst\\Builder\\FileCollection::emptyList();\n\n// assume that $codyNode is an instance of \\EventEngine\\InspectioGraphCody\\Node which describes a command\n$connection = $analyzer-\u003eanalyse($codyNode);\n\n// generate JSON schema file of the command\n$schemas = $commandGenerator-\u003egenerateJsonSchemaFile($connection, $analyzer);\n\nforeach ($schemas as $schema) {\n    $schema['filename']; // contains path with filename depending on your configuration\n    $schema['code']; // contains generated JSON schema\n}\n\n// call the different generate methods of the code generator class\n$commandGenerator-\u003egenerateApiDescription($connection, $analyzer, $fileCollection);\n$commandGenerator-\u003egenerateApiDescriptionClassMap($connection, $analyzer, $fileCollection);\n$commandGenerator-\u003egenerateCommandFile($connection, $analyzer, $fileCollection);\n\n$files = $config-\u003egetObjectGenerator()-\u003egenerateFiles($fileCollection);\n\n// loop over files and store them in filesystem\nforeach ($files as $file) {\n    $file['filename']; // contains path with filename depending on your configuration e.g. src/Domain/Aggregate\n    $file['code']; // contains generated PHP code\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevent-engine%2Fphp-code-generator-event-engine-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevent-engine%2Fphp-code-generator-event-engine-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevent-engine%2Fphp-code-generator-event-engine-ast/lists"}