event-engine / php-code-generator-cody
PHP Code Generator for Event Engine powered by Cody
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- event-engine/php-code-generator-event-engine-ast: master
- event-engine/php-inspectio-cody: dev-master
- event-engine/php-inspectio-graph-cody: dev-master
- fig/http-message-util: ^1.1
- laminas/laminas-filter: ^2.9
- nikic/php-parser: ^v4.10.3
- open-code-modeling/json-schema-to-php-ast: ^0.5.3
- open-code-modeling/php-code-ast: ^0.12.2
- open-code-modeling/php-code-generator-transformator: ^0.1.0
- open-code-modeling/php-filter: ^0.1.3
- psr/http-message: ^1.0
Requires (Dev)
- league/flysystem: ^2.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^0.12.33
- phpstan/phpstan-strict-rules: ^0.12.4
- phpunit/phpunit: ^9.5.0
- prooph/php-cs-fixer-config: ^v0.4.0
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-11-23 22:42:03 UTC
README
PHP Code Generator for Event Engine powered by Cody.
If you not familiar with PHP code generation by Cody please take a look at the PHP Cody tutorial.
Preparation
Please make sure you have installed Docker and Docker Compose.
Usage with Event Engine Skeleton
The following tutorial shows how to connect and use the Cody bot with the Event Engine Skeleton to generate PHP code from InspectIO event map.
It's important to follow each setup step. It requires a specific folder structure to function correctly!
- Create a new folder (f.e. in your home directory) that will contain the Event Engine Skeleton as well as the coding bot.
mkdir cody-tutorial
cd cody-tutorial
- Install Event Engine Skeleton via Composer
docker run --rm -it \
-v $(pwd):/app \
-u $(id -u ${USER}):$(id -g ${USER}) \
prooph/composer:7.4 create-project -v \
--stability dev \
--remove-vcs \
event-engine/php-engine-skeleton \
php-engine-tutorial-demo
- Setup Event Engine Skeleton
cd php-engine-tutorial-demo
sudo chown $(id -u -n):$(id -g -n) . -R
docker-compose up -d
docker-compose run php php scripts/create_event_stream.php
Head over to https://localhost to check if the containers are up and running. Accept the self-signed certificate and you should see a "It works" message.
- Setup coding bot
# Change back to root directory cody-tutorial
cd ..
# Install Cody Server using composer
docker run --rm -it \
-v $(pwd):/app \
-u $(id -u ${USER}):$(id -g ${USER}) \
prooph/composer:7.4 create-project -v \
--stability dev \
--remove-vcs \
event-engine/php-code-generator-cody \
/app/cody-bot
# Change into bot directory and prepare first start
cd cody-bot
cp .env.dist .env # Adjust UID in .env if needed
cp docker-compose.yml.dist docker-compose.yml
cp codyconfig.php.dist codyconfig.php
- Mount Event Engine Skeleton to Cody Bot
The Cody Server (coding bot) runs in a docker container. To be able to generate source code it needs access to a
code repository. In our case this is the php-engine-tutorial-demo
directory. We can mount the directory to the server
by modifying docker-compose.yml
located in the server directory cody-bot
. The file should look like this.
version: '2' services: # The actual client application iio-cody: image: prooph/php:7.4-cli volumes: - .:/app # mount your business application folder to /service - ../php-engine-tutorial-demo:/service user: ${UID} ports: - 3311:8080 command: vendor/bin/php-watcher public/index.php
- Prepare codyconfig
Cody is a proxy to your own code generation logic. A central codyconfig.php
file tells Cody what to do when it
receives tasks from InspectIO. As a first step
we change to Context
config to fit the Event Engine Skeleton configuration. Open cody-bot/codyconfig.php
and replace
$context
line with this:
$context = new Context( 'MyService', 'CodyTutorial', '/service/src' );
- Start Cody
Finally let's start Cody:
./dev.sh
Please Note: When adding or changing something in the Cody Bot source code a file watcher takes care of restarting the server.
InspectIO
InspectIO is a modeling tool specifically designed for remote Event Storming. It ships with realtime collaboration features for teams (only available in paid version). The free version is a standalone variant without any backend connection. Your work is stored in local storage and can be exported. It is hosted on Github Pages and has the same code generation capabilities as the SaaS version.
You can use InspectIO free version and model the building tutorial on the event map (no login required).
Create a new board called "Cody Tutorial". You'll be redirected to the fresh board. Choose "Cody" from top menu to open the Cody Console. Just hit ENTER in the console to connect to the default Cody server that we've setup and started in the previous step.
Finally type "/help" in the console to let Cody explain the basic functionality.
Cody will generate the following boilerplate for you:
- Event Engine API description for commands, aggregates and domain events
- Command, aggregate and domain event classes with corresponding value objects based on metadata (JSON schema)
- Glue code between command, corresponding aggregate and corresponding domain events
Cockpit
Cockpit is an admin UI for Event Engine. You can access it on port 4444
: https://localhost:4444.
The Event Engine skeleton is preconfigured with the cockpit-php-backend handler.
Note: To avoid CORS issues the Nginx configuration of the Cockpit server is modified to also act as a reverse proxy for requests from Cockpit to the backend.
You can execute the built-in HealthCheck
query to very that Cockpit can access the Event Engine backend.