ambimax/php-lib-runner
最新稳定版本:1.0.0
Composer 安装命令:
composer require ambimax/php-lib-runner
包简介
README 文档
README
Quick Start
Installation
composer require ambimax/php-lib-runner
Basic Usage
A Runner should combine and invoke the different parts of the code just like a command or scheduled task would do.
External variables should get bundled and validated in an ArgumentBag.
Implementing a ArgumentBag
use \Ambimax\Runner\ArgumentBag\ArgumentEnumInterface; use \Ambimax\Runner\ArgumentBag\ArgumentBagInterface; /* * Implementation */ class DemoArgumentBag implements ArgumentBagInterface { const DEMO_ARGUMENT_1 = 'demoArgument1'; const DEMO_ARGUMENT_2 = 'demoArgument2'; const DEMO_ARGUMENT_3 = 'demoArgument3'; public function __construct( protected string $demoArgument1, protected string $demoArgument2 protected string $demoArgument3, ) { try { $this->validateDemoArgument1($demoArgument1); } catch (ArgumentValidationException $exception) { $exceptions[] = $exception; } try { $this->validateDemoArgument2($demoArgument2); } catch (ArgumentValidationException $exception) { $exceptions[] = $exception; } if ($exceptions) { if (count($exceptions) > 1) { throw new MultipleArgumentValidationException($exceptions); } throw $exceptions[0]; } } public function getArgument(string $argument) { return match ($argument) { self::$DEMO_ARGUMENT_1 => $this->demoArgument1, self::$DEMO_ARGUMENT_2 => $this->demoArgument2, self::$DEMO_ARGUMENT_3 => $this->demoArgument3, } } // protected function validateDemoArgument1() {} // protected function validateDemoArgument2() {} }
Implementing a Runner
use \Ambimax\Runner\AbstractRunner; use \Ambimax\Runner\ArgumentBag\ArgumentEnumInterface; class DemoRunner extends AbstractRunner { public function getArgumentBagType(): string { return DemoArgumentBag::class; } public function run(): void { $demo1 = $this->getArgument(DemoArgumentBag::DEMO_ARGUMENT_1); $demo2 = $this->getArgument(DemoArgumentBag::DEMO_ARGUMENT_2); $demo3 = $this->getArgument(DemoArgumentBag::DEMO_ARGUMENT_3); // your code here } }
Usage
$argumentBag = new DemoArgumentBag('example1', 'example2', 'example3'); (new DemoRunner($argumentBag))->run();
Detailed Descriptions
Helper scripts
You can find out more about them here.
Addtitional Documentation
Add a list of links to additional documentation in ./docs.
Author(s)
- Fabian Köhnen, ambimax® GmbH
统计信息
- 总下载量: 2.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-31