PHP code example of lukaszmakuch / lmcondition

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

    

lukaszmakuch / lmcondition example snippets


$wiseBookCondition = (new ConditionComposite())
    ->addOR(new Difficulty(Difficulty::HARD))
    ->addOR(new TitleOfMoreCharsThan(50));

$booksForChildrenCondition = (new ConditionComposite())
    ->addAND(new Difficulty(Difficulty::EASY))
    ->addAND((new TitleOfMoreCharsThan(15))->negate());

$titleLogerThan99Condition = new TitleOfMoreCharsThan(99);

$easyBookWithLongTitle = (new Book())
    ->setTitle("A really long title of some book that must be wise.")
    ->markAsEasy();

$hardBookWithShortTitle = (new Book())
    ->markAsHard()
    ->setTitle("How?");

$easyBookWithShortTitle = (new Book())
    ->markAsEasy()
    ->setTitle("Cats");

$wiseBookCondition->isTrueIn($easyBookWithLongTitle); //true
$wiseBookCondition->isTrueIn($hardBookWithShortTitle); //true
$wiseBookCondition->isTrueIn($easyBookWithShortTitle); //false

$booksForChildrenCondition->isTrueIn($easyBookWithLongTitle); //false
$booksForChildrenCondition->isTrueIn($hardBookWithShortTitle); //false
$booksForChildrenCondition->isTrueIn($easyBookWithShortTitle); //true

$titleLogerThan99Condition->isTrueIn($easyBookWithLongTitle); //false
$titleLogerThan99Condition->isTrueIn($hardBookWithShortTitle); //false
$titleLogerThan99Condition->isTrueIn($easyBookWithShortTitle);//false

/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
    $wiseBookCondition,
    $titleLogerThan99Condition
); //true

/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
    $booksForChildrenCondition,
    $titleLogerThan99Condition
); //false

/* @var $comparator EqualityComparator */
$comparator->equal(
    $titleLogerThan99Condition,
    new TitleOfMoreCharsThan(99)
); //true