ambimax / php-lib-runner
Installs: 1 628
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan-symfony: ^1.1
- phpunit/phpunit: ~9.5.2
This package is not auto-updated.
Last update: 2025-01-10 20:48:52 UTC
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