PHP code example of ambimax / php-lib-runner

1. Go to this page and download the library: Download ambimax/php-lib-runner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ambimax / php-lib-runner example snippets


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() {}
}

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
    }
}

$argumentBag = new DemoArgumentBag('example1', 'example2', 'example3');
(new DemoRunner($argumentBag))->run();
shell
composer