PHP code example of reformo / backendbase-specification

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

    

reformo / backendbase-specification example snippets




use Backendbase\Specification\Specification;
use Backendbase\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