PHP code example of danfekete / spec

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

    

danfekete / spec example snippets


$d = [2];
$spec = new Specification(new ExpressionSpec('1 > d[0]'));
$spec->isSatisfiedBy(['d' => $d]); // return false

/*
 * You can use classes in expression code
*/
class Nan {

    public function isNan($value)
    {
        return is_nan($value);
    }

}

$spec = new Specification(new AndSpec(
    new NotSpec(new ExpressionSpec('checker.isNan(d)')),
    new OrSpec(
        new ExpressionSpec('d != 12'),
        new ExpressionSpec('d > 10')
    ),
    new AndSpec(
        new ExpressionSpec('d > 5'),
        new ExpressionSpec('d < 20')
    )
));

$spec->isSatisfiedBy(['d' => 17, 'checker' => new Nan()]); // return true