Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.

Predicates

Frank Kleine edited this page Aug 4, 2014 · 1 revision

Introduction

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.

Methods on predicates

test($value)

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.

castFrom($predicate)

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.

asWellAs($other)

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

orElse($other)

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.

negate()

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
Clone this wiki locally