PHP code example of sroze / chain-of-responsibility
1. Go to this page and download the library: Download sroze/chain-of-responsibility 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/ */
sroze / chain-of-responsibility example snippets
use SRIO\ChainOfResponsibility\ChainContext;
use SRIO\ChainOfResponsibility\ChainProcessInterface;
class LambdaProcess implements ChainProcessInterface
{
/**
* {@inheritdoc}
*/
public function execute(ChainContext $context)
{
// Do whatever you want in this small process, such as
// sending a mail, manipulating files, ...
}
}
$runner = new ChainRunner([
new FirstProcess(),
new SecondProcess(),
new ThirdProcess()
]);
use SRIO\ChainOfResponsibility\ChainContext;
use SRIO\ChainOfResponsibility\DependentChainProcessInterface;
class FooProcess implements DependentChainProcessInterface
{
/**
* {@inheritdoc}
*/
public function execute(ChainContext $context)
{
// Do whatever you want...
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'foo';
}
/**
* {@inheritdoc}
*/
public function dependsOn()
{
return ['bar'];
}
}
$builder = new ChainBuilder([
new FooProcess(),
new BarProcess(),
]);
$runner = $builder->getRunner();
$runner->run();
$decoratorFactory = new DecoratorFactory();
$runner = new ChainRunner([], $decoratorFactory);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.