PHP code example of tanigami / specification
1. Go to this page and download the library: Download tanigami/specification 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/ */
tanigami / specification example snippets
use Tanigami\Specification\Specification;
use Tanigami\Specification\OneOfSpecification;
class Order
{
public function isPaid()
{
return true;
}
public function isShipped()
{
return false;
}
public function isCancelled()
{
return false;
}
}
class UnshippedOrderSpecification extends Specification
{
public function isSatisfiedBy($order): bool
{
return !$order->isShipped();
}
}
class PaidOrderSpecification extends Specification
{
public function isSatisfiedBy($order): bool
{
return $order->isPaid();
}
}
class CancelledOrderSpecification extends Specification
{
public function isSatisfiedBy($order): bool
{
return $order->isCancelled();
}
}
$paid = new PaidOrderSpecification;
$unshipped = new UnshippedOrderSpecification;
$cancelled = new CancelledOrderSpecification;
$paid->and($unshipped)->isSatisfiedBy(new Order); // => true
(new OneOfSpecification($paid, $unshipped, $cancelled))->isSatisfiedBy(new Order); // => true