PHP Class Webmozart\Expression\Expr

Use this class to build expressions:ons: php $expr = Expr::greaterThan(20)->orLessThan(10); You can evaluate the expression with another value {@link Expression::evaluate()}: php if ($expr->evaluate($value)) { do something... } You can also evaluate expressions by arrays by passing the array keys as second argument: php $expr = Expr::greaterThan(20, 'age') ->andStartsWith('Thomas', 'name'); $values = array( 'age' => 35, 'name' => 'Thomas Edison', ); if ($expr->evaluate($values)) { do something... }
Since: 1.0
Author: Bernhard Schussek ([email protected])
Datei anzeigen Open project: webmozart/expression Class Usage Examples

Public Methods

Method Description
all ( Webmozart\Expression\Expression $expr ) : All Check that all entries of a traversable value match an expression.
andX ( array $conjuncts ) : AndX Create a conjunction.
atLeast ( integer $count, Webmozart\Expression\Expression $expr ) : AtLeast Check that at least N entries of a traversable value match an expression.
atMost ( integer $count, Webmozart\Expression\Expression $expr ) : AtMost Check that at most N entries of a traversable value match an expression.
contains ( string $string ) : Contains Check that a value contains a given string.
count ( Webmozart\Expression\Expression $expr ) : Count Check that the count of a collection matches an expression.
endsWith ( string $suffix ) : EndsWith Check that a value ends with a given string.
equals ( mixed $value ) : Equals Check that a value equals another value.
exactly ( integer $count, Webmozart\Expression\Expression $expr ) : Exactly Check that exactly N entries of a traversable value match an expression.
expr ( Webmozart\Expression\Expression $expr ) : Webmozart\Expression\Expression Returns the expression.
false ( ) : AlwaysFalse Always false (contradiction).
filter ( array | ArrayAcces\ArrayAccess | Traversabl\Traversable $collection, Webmozart\Expression\Expression $expr ) : array | ArrayAcces\ArrayAccess | Traversabl\Traversable Filter a collection for entries matching the expression.
greaterThan ( mixed $value ) : GreaterThan Check that a value is greater than another value.
greaterThanEqual ( mixed $value ) : GreaterThanEqual Check that a value is greater than or equal to another value.
in ( array $values ) : In Check that a value occurs in a list of values.
isEmpty ( ) : IsEmpty Check that a value is empty.
isInstanceOf ( string $className ) : IsEmpty Check that a value is an instance of a given class.
key ( string | integer $key, Webmozart\Expression\Expression $expr ) : Key Check that the value of an array key matches an expression.
keyExists ( string $keyName ) : KeyExists Check that a value key exists.
keyNotExists ( string $keyName ) : KeyNotExists Check that a value key does not exist.
lessThan ( mixed $value ) : LessThan Check that a value is less than another value.
lessThanEqual ( mixed $value ) : LessThanEqual Check that a value is less than or equal to another value.
matches ( string $regExp ) : Matches Check that a value matches a regular expression.
method ( string $methodName, $args ) : Method Check that the result of a method call matches an expression.
not ( Webmozart\Expression\Expression $expr ) : Webmozart\Expression\Logic\Not Negate an expression.
notEmpty ( ) : Webmozart\Expression\Logic\Not Check that a value is not empty.
notEquals ( mixed $value ) : NotEquals Check that a value does not equal another value.
notNull ( ) : NotSame Check that a value is not null.
notSame ( mixed $value ) : NotSame Check that a value is not identical to another value.
null ( ) : Same Check that a value is null.
orX ( array $disjuncts ) : OrX Create a disjunction.
property ( string $propertyName, Webmozart\Expression\Expression $expr ) : Method Check that the value of a property matches an expression.
same ( mixed $value ) : Same Check that a value is identical to another value.
startsWith ( string $prefix ) : StartsWith Check that a value starts with a given string.
true ( ) : AlwaysTrue Always true (tautology).

Private Methods

Method Description
__construct ( ) This class cannot be instantiated.

Method Details

all() public static method

Check that all entries of a traversable value match an expression.
public static all ( Webmozart\Expression\Expression $expr ) : All
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\All The created expression.

andX() public static method

Create a conjunction.
public static andX ( array $conjuncts ) : AndX
$conjuncts array The conjuncts.
return Webmozart\Expression\Logic\AndX The created conjunction.

atLeast() public static method

Check that at least N entries of a traversable value match an expression.
public static atLeast ( integer $count, Webmozart\Expression\Expression $expr ) : AtLeast
$count integer The minimum number of entries that need to match.
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\AtLeast The created expression.

atMost() public static method

Check that at most N entries of a traversable value match an expression.
public static atMost ( integer $count, Webmozart\Expression\Expression $expr ) : AtMost
$count integer The maximum number of entries that need to match.
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\AtMost The created expression.

contains() public static method

Check that a value contains a given string.
public static contains ( string $string ) : Contains
$string string The sub-string.
return Webmozart\Expression\Constraint\Contains The created expression.

count() public static method

Check that the count of a collection matches an expression.
public static count ( Webmozart\Expression\Expression $expr ) : Count
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\Count The created expression.

endsWith() public static method

Check that a value ends with a given string.
public static endsWith ( string $suffix ) : EndsWith
$suffix string The suffix string.
return Webmozart\Expression\Constraint\EndsWith The created expression.

equals() public static method

Check that a value equals another value.
public static equals ( mixed $value ) : Equals
$value mixed The compared value.
return Webmozart\Expression\Constraint\Equals The created expression.

exactly() public static method

Check that exactly N entries of a traversable value match an expression.
public static exactly ( integer $count, Webmozart\Expression\Expression $expr ) : Exactly
$count integer The number of entries that need to match.
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\Exactly The created expression.

expr() public static method

Facilitates usage of expressions on PHP < 7.
public static expr ( Webmozart\Expression\Expression $expr ) : Webmozart\Expression\Expression
$expr Webmozart\Expression\Expression An expression.
return Webmozart\Expression\Expression The expression.

false() public static method

Always false (contradiction).
public static false ( ) : AlwaysFalse
return Webmozart\Expression\Logic\AlwaysFalse The created expression.

filter() public static method

Filter a collection for entries matching the expression.
public static filter ( array | ArrayAcces\ArrayAccess | Traversabl\Traversable $collection, Webmozart\Expression\Expression $expr ) : array | ArrayAcces\ArrayAccess | Traversabl\Traversable
$collection array | ArrayAcces\ArrayAccess | Traversabl\Traversable An array or an object implementing Traversable and ArrayAccess.
$expr Webmozart\Expression\Expression The expression to evaluate for each entry.
return array | ArrayAcces\ArrayAccess | Traversabl\Traversable The filtered collection.

greaterThan() public static method

Check that a value is greater than another value.
public static greaterThan ( mixed $value ) : GreaterThan
$value mixed The compared value.
return Webmozart\Expression\Constraint\GreaterThan The created expression.

greaterThanEqual() public static method

Check that a value is greater than or equal to another value.
public static greaterThanEqual ( mixed $value ) : GreaterThanEqual
$value mixed The compared value.
return Webmozart\Expression\Constraint\GreaterThanEqual The created expression.

in() public static method

Check that a value occurs in a list of values.
public static in ( array $values ) : In
$values array The compared values.
return Webmozart\Expression\Constraint\In The created expression.

isEmpty() public static method

Check that a value is empty.
public static isEmpty ( ) : IsEmpty
return Webmozart\Expression\Constraint\IsEmpty The created expression.

isInstanceOf() public static method

Check that a value is an instance of a given class.
public static isInstanceOf ( string $className ) : IsEmpty
$className string The class name.
return Webmozart\Expression\Constraint\IsEmpty The created expression.

key() public static method

Check that the value of an array key matches an expression.
public static key ( string | integer $key, Webmozart\Expression\Expression $expr ) : Key
$key string | integer The array key.
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\Key The created expression.

keyExists() public static method

Check that a value key exists.
public static keyExists ( string $keyName ) : KeyExists
$keyName string The key name.
return Webmozart\Expression\Constraint\KeyExists The created expression.

keyNotExists() public static method

Check that a value key does not exist.
public static keyNotExists ( string $keyName ) : KeyNotExists
$keyName string The key name.
return Webmozart\Expression\Constraint\KeyNotExists The created expression.

lessThan() public static method

Check that a value is less than another value.
public static lessThan ( mixed $value ) : LessThan
$value mixed The compared value.
return Webmozart\Expression\Constraint\LessThan The created expression.

lessThanEqual() public static method

Check that a value is less than or equal to another value.
public static lessThanEqual ( mixed $value ) : LessThanEqual
$value mixed The compared value.
return Webmozart\Expression\Constraint\LessThanEqual The created expression.

matches() public static method

Check that a value matches a regular expression.
public static matches ( string $regExp ) : Matches
$regExp string The regular expression.
return Webmozart\Expression\Constraint\Matches The created expression.

method() public static method

Check that the result of a method call matches an expression.
public static method ( string $methodName, $args ) : Method
$methodName string The name of the method to call.
return Webmozart\Expression\Selector\Method The created expression.

not() public static method

Negate an expression.
public static not ( Webmozart\Expression\Expression $expr ) : Webmozart\Expression\Logic\Not
$expr Webmozart\Expression\Expression The negated expression.
return Webmozart\Expression\Logic\Not The created negation.

notEmpty() public static method

Check that a value is not empty.
public static notEmpty ( ) : Webmozart\Expression\Logic\Not
return Webmozart\Expression\Logic\Not The created expression.

notEquals() public static method

Check that a value does not equal another value.
public static notEquals ( mixed $value ) : NotEquals
$value mixed The compared value.
return Webmozart\Expression\Constraint\NotEquals The created expression.

notNull() public static method

Check that a value is not null.
public static notNull ( ) : NotSame
return Webmozart\Expression\Constraint\NotSame The created expression.

notSame() public static method

Check that a value is not identical to another value.
public static notSame ( mixed $value ) : NotSame
$value mixed The compared value.
return Webmozart\Expression\Constraint\NotSame The created expression.

null() public static method

Check that a value is null.
public static null ( ) : Same
return Webmozart\Expression\Constraint\Same The created expression.

orX() public static method

Create a disjunction.
public static orX ( array $disjuncts ) : OrX
$disjuncts array The disjuncts.
return Webmozart\Expression\Logic\OrX The created disjunction.

property() public static method

Check that the value of a property matches an expression.
public static property ( string $propertyName, Webmozart\Expression\Expression $expr ) : Method
$propertyName string The name of the property.
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\Method The created expression.

same() public static method

Check that a value is identical to another value.
public static same ( mixed $value ) : Same
$value mixed The compared value.
return Webmozart\Expression\Constraint\Same The created expression.

startsWith() public static method

Check that a value starts with a given string.
public static startsWith ( string $prefix ) : StartsWith
$prefix string The prefix string.
return Webmozart\Expression\Constraint\StartsWith The created expression.

true() public static method

Always true (tautology).
public static true ( ) : AlwaysTrue
return Webmozart\Expression\Logic\AlwaysTrue The created expression.