theaentmachine / aent-console
A utility PHP package to create aents using Symfony console.
Installs: 1 641
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: >=7.1
- docker-php/docker-php: ^2
- guzzlehttp/guzzle: ^6.3.3
- opis/json-schema: ^1.0
- psr/log: ^1
- symfony/console: ^4.0
- symfony/filesystem: ^4.1
- symfony/finder: ^4.1
- symfony/process: ^4.1
- symfony/yaml: 4.1.1
Requires (Dev)
- gamez/psr-testlogger: ^3
- phpstan/phpstan: ^0.10.3
- phpunit/phpunit: ^7
- squizlabs/php_codesniffer: ^3.2
- thecodingmachine/phpstan-safe-rule: ^0.1.0@dev
- thecodingmachine/phpstan-strict-rules: ^0.10.3
This package is auto-updated.
Last update: 2024-11-29 05:56:46 UTC
README
A utility PHP package to create Aents using the Symfony console.
Why do I need this?
This package contains a set of classes that extend Symfony console classes to help you get started building an Aent.
Docker Aents must contain a "aent" program that accepts in argument events triggered by other aents.
$ aent event-name payload
When writing a command line application in PHP, it is fairly common to use Symfony console.
However, Aents have some peculiarities that do not fit with the Symfony console:
- If an event is not found, the aent must not return an error code. In Symfony console, if the first argument is not a known command, an error is raised
- Aents are configured using the PHEROMONE_LOG_LEVEL environment variable. Symfony console log level is configured using the "-vvv" option.
Usage
A typical Aent will look like this:
#!/usr/bin/env php <?php require __DIR__ . '/../vendor/autoload.php'; use TheAentMachine\AentApplication; use MyAent\AddEventCommand; use MyAent\DeleteDockerServiceEventCommand; use MyAent\NewDockerServiceInfoEventCommand; use MyAent\RemoveEventCommand; // Notice how the application is a "AentApplication" and not a classical Symfony Console "Application" $application = new AentApplication(); // Each event is a Symfony command $application->add(new AddEventCommand()); $application->add(new RemoveEventCommand()); $application->add(new NewDockerServiceInfoEventCommand()); $application->add(new DeleteDockerServiceEventCommand()); $application->run();
Each command you write should extend "\TheAentMachine\EventCommand".
class MyCommand extends EventCommand { protected function getEventName(): string { return 'my-event-name'; } protected function executeEvent(?string $payload): void { // Do some stuff with this event } }
If your payload is a JSON message, you can even extend the "\TheAentMachine\JsonEventCommand".
class MyCommand extends JsonEventCommand { protected function getEventName(): string { return 'my-event-name'; } protected function executeJsonEvent(array $payload): void { // Do some stuff with this event } }