-
Notifications
You must be signed in to change notification settings - Fork 1
Predicates
Predicates are evaluations of a value which result in boolean true
or false
. In Stubbles, predicates are represented by stubbles\predicate\Predicate
and its subclasses. For a list of all predicates provided by Stubbles Core see List of available predicates.
Actual evaluation of the provided value. The return value is either true
or false
.
Predicates itself are callable, as stubbles\predicate\Predicate
implements the magic __invoke()
method. Calling a predicate object this way invokes the test()
method.
Casts the given value to an instance of stubbles\predicate\Predicate
. If $predicate
already is an instance of stubbles\predicate\Predicate
it is simply returned. In case $predicate
is a callable
an instance of stubbles\predicate\CallablePredicate
will be created and returned. For all other arguments it throws an stubbles\lang\exception\IllegalArgumentException
.
Joins current predicate with another predicate and returns a new predicate instance which requires both predicate to evaluate to true
to return true
on evaluation.
$and = $predicate->asWellAs(function($value) { return substr($value, 0, 3) === 'foo'); });
// $and is now a new predicate instance combining both $predicate and the predicate given to the asWellAs() method
Joins current predicate with another predicate and returns a new predicate instance which evaluates to true
if one of those two predicates evaluate to true
.
Returns a new predicate instance which negates the predicate instance on which it was called.
$equalsFoo = new Equals('foo');
$notEqualsFoo = $equalsFoo->negate(); // create the negation of equals foo