PHP code example of sapiet / processor

1. Go to this page and download the library: Download sapiet/processor 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/ */

    

sapiet / processor example snippets




apiet\Processor\Processor;
use Sapiet\Processor\Resolvers\ExceptionResolver;
use Sapiet\Processor\Storage\FileStorage;

$processor = (new Processor())
    ->withProcess(function (bool $success, int $sleep = 1) {
        sleep($sleep);

        if (false === $success) {
            throw new \Exception('Failed!');
        }
    })
    ->withResolver(new ExceptionResolver())
    ->withStorage(new FileStorage('processor.txt'))
    ->withOption(Processor::ERROR_CALLBACK_DELAY_OPTION, 4)
    ->onSuccess(function() {
        echo 'Yeah!'.PHP_EOL;
    })
    ->onError(function (array $bag) {
        echo sprintf('Oh noooo (%s)', $bag['exception']->getMessage()).PHP_EOL;
    })
;

$values = array_merge(
    [true],
    array_fill(0, 10, false),
    [true]
);

foreach ($values as $value) {
    $processor->process($value);
}