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

List of available predicates

Frank Kleine edited this page Aug 4, 2014 · 9 revisions

CallablePredicate

Wraps a predicate evaluation into a callable.

Contains

Predicate to test that something is contained. This predicate works with any scalar value:

$contains = new Contains(true);
$contains->test($value); // evaluates to true if $value contains something `true`

$contains = new Contains('foo');
$contains->test($value);  // evaluates to true if $value is equal to foo or a string containing the phrase foo

Equals

Predicate to test that something is equal. It can compare any scalar value with an expected value. The value to test has to be of the same type and must have the same content as the expected value in order for the predicate to evaluate to true.

$equals = new Equals(303);
$equals->test($value); // evaluates to true if $value contains the integer 303

IsExistingDirectory

Predicate to test that a string denotes an existing directory.

$isExistingDirectory = new IsExistingDirectory('/path/where/relatives/must/reside');
$isExistingDirectory->test('foo'); // evaluates to true if the path /path/where/relatives/must/reside/foo exists and is a directory
$isExistingDirectory->test('/path/to/foo'); // evaluates to true if the path /path/where/relatives/must/reside/path/to/foo exists and is a directory

In case no base directory is specified both global and relative pathes can be evaluated:

$isExistingDirectory = new IsExistingDirectory();
$isExistingDirectory->test('/path/to/foo'); // evaluates to true if the path /path/to/foo exists and is a directory
$isExistingDirectory->test('foo'); // evaluates to true if the path getcwd() . '/foo' exists and is a directory

IsExistingFile

Predicate to test that a string denotes an existing file.

$isExistingFile = new IsExistingFile('/path/where/relatives/must/reside');
$isExistingFile->test('foo.txt'); // evaluates to true if the path /path/where/relatives/must/reside/foo.txt exists and is a file
$isExistingFile->test('/path/to/foo.txt'); // evaluates to true if the path /path/where/relatives/must/reside/path/to/foo.txt exists and is a file

In case no base directory is specified both global and relative pathes can be evaluated:

$isExistingFile = new IsExistingFile();
$isExistingFile->test('/path/to/foo.txt'); // evaluates to true if the path /path/to/foo.txt exists and is a file
$isExistingFile->test('foo.txt'); // evaluates to true if the path getcwd() . '/foo.txt' exists and is a file

IsExistingHttpUri

Predicate to test that a string is an existing http uri, i.e. has a DNS record.

IsHttpUri

Predicate to test that a string is a http uri. Does a syntactical check only, to ensure that the HTTP uri really exists use IsExistingHttpUri instead (see above).

IsIpAddress

Predicate to test that something is an IP address, either v4 or v6.

IsIpV4Address

Predicate to test that something is an IPv4 address.

IsIpV6Address

Predicate to test that something is an IPv6 address.

IsMailAddress

Predicate to test that a string is a mail address.

IsOneOf

Predicate to test a value against a list of allowed values.

Regex

Predicate to ensure a value complies to a given regular expression. The predicate uses preg_match() and checks if the value occurs exactly one time. Please make sure that the supplied regular expression contains correct delimiters, they will not be applied automatically. The test() method throws a stubbles\lang\exception\RuntimeException in case the regular expression is invalid.

Clone this wiki locally