theaentmachine / aent-console
一个PHP工具包,用于使用Symfony控制台创建aents。
dev-master / 1.0.x-dev
2018-11-06 14:14 UTC
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-08-29 05:06:09 UTC
README
一个PHP工具包,用于使用Symfony控制台创建Aents。
为什么我需要这个?
此包包含一系列扩展Symfony控制台类的类,帮助您开始构建Aent。
Docker Aents必须包含一个“aent”程序,该程序接受由其他aents触发的事件作为参数。
$ aent event-name payload
在PHP中编写命令行应用程序时,通常使用Symfony控制台。
Aents有一些与Symfony控制台不兼容的特异之处。
- 如果找不到事件,aent不应返回错误代码。在Symfony控制台,如果第一个参数不是已知的命令,将引发错误。
- Aents使用PHEROMONE_LOG_LEVEL环境变量进行配置。Symfony控制台的日志级别使用“-vvv”选项进行配置。
用法
一个典型的Aent将看起来像这样
#!/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();
您编写的每个命令都应该扩展"\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 } }
如果您的有效负载是JSON消息,甚至可以扩展"\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 } }