PHP code example of widi / filter-specification

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

    

widi / filter-specification example snippets


    $candidate = $this->prophesize(MyCandidateInterface::class);
    $candidate->getValue()->willReturn($value);

    $builderFactory = new BuilderFactory();

    $specificationBuilder = $builderFactory->create();
    $firstSpecification   =
        $specificationBuilder
            ->and(new CandidateIsHigherThanFiveCompositeSpecification())
            ->and(new CandidateIsLowerThanTwentyCompositeSpecification())
            ->or(new CandidateIsDivisableByFive())
            ->build();

    $secondSpecification =
        $specificationBuilder
            ->and(new CandidateIsHigherThanOneHundredCompositeSpecification())
            ->and(new CandidateIsLowerThanTwoHundredCompositeSpecification())
            ->build();

    $compositeSpecification =
        $specificationBuilder
            ->or($firstSpecification)
            ->or($secondSpecification)
            ->build();

    $result = $compositeSpecification->meetsSpecification($candidate->reveal());

    $this->assertEquals($expectedResult, $result, 'Value failed: ' . $value);