1. Go to this page and download the library: Download skrip42/strategy-bundle 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/ */
skrip42 / strategy-bundle example snippets
namespace App\Services\Test;
use Skrip42\Bundle\StrategyBundle\StrategyManagerAbstract;
class TestStrategyManager extends StrategyManagerAbstract
{
}
namespace App\Services\Test;
use Skrip42\Bundle\StrategyBundle\StrategyInterface;
abstract class TestStrategyAbstract implements StrategyInterface
{
abstract public function doSomething();
}
namespace App\Services\Test;
class Strategy1 extends TestStrategyAbstract
{
public function doSomething()
{
.....
}
}
class Strategy2 extends TestStrategyAbstract
{
public function doSomething()
{
.....
}
}
public function test(TestStrategyManager $manager): Response
{
$strategy = $manager->get('strategy1');
$anotherStrategy = $manager->get('strategy2');
}
namespace App\Services\Test;
use Skrip42\Bundle\StrategyBundle\StrategyManagerAbstract;
class TestSpecificationManager extends SpecificationManagerAbstract
{
}
namespace App\Services\Test;
use Skrip42\Bundle\StrategyBundle\SpecificationInterface;
abstract class TestSpecificationAbstract implements SpecificationInterface
{
abstract public function isStatisfiedBy($criteria) : bool;
abstract public function doSomething();
}
namespace App\Services\Test;
class Specification1 extends TestSpecificationAbstract
{
public function isStatisfiedBy($criteria) : bool
{
...check condition
}
public function doSomething()
{
.....
}
}
class Specification2 extends TestSpecificationAbstract
{
public function isStatisfiedBy($criteria) : bool
{
...check condition
}
public function doSomething()
{
.....
}
}
public function test(TestSpecificationManager $manager): Response
{
$specification = $manager->getFirst($condition); //get the first specification that meets the condition
$specification = $manager->getAll($condition); //get all specifications that meets the condition
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.