dev-master
9999999-devCondition library
MIT
The Requires
The Development Requires
v0.0.2
0.0.2.0Condition library
MIT
The Requires
The Development Requires
v0.0.1
0.0.1.0Condition library
MIT
The Requires
The Development Requires
Wallogit.com
2017 © Pedro PelĂĄez
Condition library
This library allows to build complex conditions connected with AND/OR statements with subconditions support and then check them in some context., (*1)
Let's say we want to match books that are hard to read or those ones with titles longer than 50 characters:, (*3)
$wiseBookCondition = (new ConditionComposite())
->addOR(new Difficulty(Difficulty::HARD))
->addOR(new TitleOfMoreCharsThan(50));
Or easy books with short titles for children:, (*4)
$booksForChildrenCondition = (new ConditionComposite())
->addAND(new Difficulty(Difficulty::EASY))
->addAND((new TitleOfMoreCharsThan(15))->negate());
Or those with really long titles:, (*5)
$titleLogerThan99Condition = new TitleOfMoreCharsThan(99);
An easy to read book with a long title:, (*6)
$easyBookWithLongTitle = (new Book())
->setTitle("A really long title of some book that must be wise.")
->markAsEasy();
A hard to read book with short title:, (*7)
$hardBookWithShortTitle = (new Book())
->markAsHard()
->setTitle("How?");
An easy to read book with a short title:, (*8)
$easyBookWithShortTitle = (new Book())
->markAsEasy()
->setTitle("Cats");
Is this book wise?, (*9)
$wiseBookCondition->isTrueIn($easyBookWithLongTitle); //true $wiseBookCondition->isTrueIn($hardBookWithShortTitle); //true $wiseBookCondition->isTrueIn($easyBookWithShortTitle); //false
Is it for children?, (*10)
$booksForChildrenCondition->isTrueIn($easyBookWithLongTitle); //false $booksForChildrenCondition->isTrueIn($hardBookWithShortTitle); //false $booksForChildrenCondition->isTrueIn($easyBookWithShortTitle); //true
Is the title longer than 99 characters?, (*11)
$titleLogerThan99Condition->isTrueIn($easyBookWithLongTitle); //false $titleLogerThan99Condition->isTrueIn($hardBookWithShortTitle); //false $titleLogerThan99Condition->isTrueIn($easyBookWithShortTitle);//false
A title of a wise book may be longer than 99 characters., (*12)
/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
$wiseBookCondition,
$titleLogerThan99Condition
); //true
But books for children have no titles that long., (*13)
/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
$booksForChildrenCondition,
$titleLogerThan99Condition
); //false
Two condition objects may be equal., (*14)
/* @var $comparator EqualityComparator */
$comparator->equal(
$titleLogerThan99Condition,
new TitleOfMoreCharsThan(99)
); //true
Use composer to get the latest version:, (*15)
$ composer require lukaszmakuch/lmcondition
The above code is taken from an example code located in ./examples. You can check there all files needed to provide this functionality., (*16)
For more information check the best documentation - unit tests in ./tests. There's also documentation generated in ./doc., (*17)
Condition library
MIT
Condition library
MIT
Condition library
MIT