1. Go to this page and download the library: Download snelling/sequence 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/ */
snelling / sequence example snippets
$sequence = (new Sequence)
->then(Callable)
->then(Callable, null);
$sequence->run(Payload);
$payload = new Payload();
$payload->number = 1; // Sets a number object to 1
echo $payload->number; // Will return 1
$payload->setNumber(2); // Sets the number object to 2
echo $payload->getNumber(); // Will return 2
echo $payload->number; // Will return 2
echo $payload->notset; // Will throw exception
$payload->setNotSet(true); // Set the notset object
echo $payload->notset; // Will return true
class TimesTwoStage
{
public function __invoke($payload)
{
return $payload * 2;
}
}
class AddOneStage
{
public function __invoke($payload)
{
return $payload + 1;
}
}
$sequence = (new Sequence)
->then(new TimesTwoStage)
->then(new AddOneStage);
// Returns 21
$sequence->run(10);
class TimesTwoStage
{
public function __invoke($payload)
{
return $payload * 2;
}
}
$sequence = (new Sequence)
->then(new TimesTwoStage)
->then(function ($payload) {
return $payload + 1;
});
// Returns 21
$sequence->run(10);
class TimesTwoStage
{
public function __invoke($payload)
{
return $payload * 2;
}
}
class AddOneStage
{
public function __invoke($payload)
{
return $payload + 1;
}
}
$minusSequence = (new Sequence)
->then(function ($payload) {
return $payload - 2; // 2
});
$sequence = (new Sequence)
->then(new TimesTwoStage) // 1
->then($minusSequence) // 2
->then(new AddOneStage); // 3
// Returns 19
echo $sequence->run(10);
$sequence = (new Sequence)
->then(function () {
throw new LogicException();
});
try {
$sequence->run($payload);
} catch (LogicException $e) {
// Handle the exception.
}