Overview

Namespaces

  • Webmozart
    • Expression
      • Constraint
      • Logic
      • PhpUnit
      • Selector
      • Traversal
      • Util

Classes

  • Expr

Interfaces

  • Expression
  • Overview
  • Namespace
  • Class

Class Expr

Factory for Webmozart\Expression\Expression instances.

Use this class to build expressions:ons:

$expr = Expr::greaterThan(20)->orLessThan(10);

You can evaluate the expression with another value Expression::evaluate():

if ($expr->evaluate($value)) { // do something...
}

You can also evaluate expressions by arrays by passing the array keys as second argument:

$expr = Expr::greaterThan(20, 'age') ->andStartsWith('Thomas', 'name');

$values = array( 'age' => 35, 'name' => 'Thomas Edison',
);

if ($expr->evaluate($values)) { // do something...
}
Namespace: Webmozart\Expression
Author: Bernhard Schussek bschussek@gmail.com
Since: 1.0
Located at Expr.php
Methods summary
public static Webmozart\Expression\Logic\Not
# not( Webmozart\Expression\Expression $expr )

Negate an expression.

Negate an expression.

Parameters

$expr
The negated expression.

Returns

Webmozart\Expression\Logic\Not
The created negation.
public static Webmozart\Expression\Logic\AlwaysTrue
# true( )

Always true (tautology).

Always true (tautology).

Returns

Webmozart\Expression\Logic\AlwaysTrue
The created expression.
public static Webmozart\Expression\Logic\AlwaysFalse
# false( )

Always false (contradiction).

Always false (contradiction).

Returns

Webmozart\Expression\Logic\AlwaysFalse
The created expression.
public static Webmozart\Expression\Selector\Key
# key( string|integer $key, Webmozart\Expression\Expression $expr )

Check that the value of an array key matches an expression.

Check that the value of an array key matches an expression.

Parameters

$key
The array key.
$expr
The evaluated expression.

Returns

Webmozart\Expression\Selector\Key
The created expression.
public static Webmozart\Expression\Selector\Method
# method( string $methodName, mixed $args, Webmozart\Expression\Expression $expr,… )

Check that the result of a method call matches an expression.

Check that the result of a method call matches an expression.

Parameters

$methodName
The name of the method to call.
$args
$args... The method arguments.
$expr,…
The evaluated expression.

Returns

Webmozart\Expression\Selector\Method
The created expression.
public static Webmozart\Expression\Selector\Method
# property( string $propertyName, Webmozart\Expression\Expression $expr )

Check that the value of a property matches an expression.

Check that the value of a property matches an expression.

Parameters

$propertyName
The name of the property.
$expr
The evaluated expression.

Returns

Webmozart\Expression\Selector\Method
The created expression.
public static Webmozart\Expression\Selector\AtLeast
# atLeast( integer $count, Webmozart\Expression\Expression $expr )

Check that at least N entries of a traversable value match an expression.

Check that at least N entries of a traversable value match an expression.

Parameters

$count
The minimum number of entries that need to match.
$expr
The evaluated expression.

Returns

Webmozart\Expression\Selector\AtLeast
The created expression.
public static Webmozart\Expression\Selector\AtMost
# atMost( integer $count, Webmozart\Expression\Expression $expr )

Check that at most N entries of a traversable value match an expression.

Check that at most N entries of a traversable value match an expression.

Parameters

$count
The maximum number of entries that need to match.
$expr
The evaluated expression.

Returns

Webmozart\Expression\Selector\AtMost
The created expression.
public static Webmozart\Expression\Selector\Exactly
# exactly( integer $count, Webmozart\Expression\Expression $expr )

Check that exactly N entries of a traversable value match an expression.

Check that exactly N entries of a traversable value match an expression.

Parameters

$count
The number of entries that need to match.
$expr
The evaluated expression.

Returns

Webmozart\Expression\Selector\Exactly
The created expression.
public static Webmozart\Expression\Selector\All
# all( Webmozart\Expression\Expression $expr )

Check that all entries of a traversable value match an expression.

Check that all entries of a traversable value match an expression.

Parameters

$expr
The evaluated expression.

Returns

Webmozart\Expression\Selector\All
The created expression.
public static Webmozart\Expression\Selector\Count
# count( Webmozart\Expression\Expression $expr )

Check that the count of a collection matches an expression.

Check that the count of a collection matches an expression.

Parameters

$expr
The evaluated expression.

Returns

Webmozart\Expression\Selector\Count
The created expression.
public static Webmozart\Expression\Constraint\Same
# null( )

Check that a value is null.

Check that a value is null.

Returns

Webmozart\Expression\Constraint\Same
The created expression.
public static Webmozart\Expression\Constraint\NotSame
# notNull( )

Check that a value is not null.

Check that a value is not null.

Returns

Webmozart\Expression\Constraint\NotSame
The created expression.
public static Webmozart\Expression\Constraint\IsEmpty
# isEmpty( )

Check that a value is empty.

Check that a value is empty.

Returns

Webmozart\Expression\Constraint\IsEmpty
The created expression.
public static Webmozart\Expression\Logic\Not
# notEmpty( )

Check that a value is not empty.

Check that a value is not empty.

Returns

Webmozart\Expression\Logic\Not
The created expression.
public static Webmozart\Expression\Constraint\IsEmpty
# isInstanceOf( string $className )

Check that a value is an instance of a given class.

Check that a value is an instance of a given class.

Parameters

$className
The class name.

Returns

Webmozart\Expression\Constraint\IsEmpty
The created expression.
public static Webmozart\Expression\Constraint\Equals
# equals( mixed $value )

Check that a value equals another value.

Check that a value equals another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\Equals
The created expression.
public static Webmozart\Expression\Constraint\NotEquals
# notEquals( mixed $value )

Check that a value does not equal another value.

Check that a value does not equal another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\NotEquals
The created expression.
public static Webmozart\Expression\Constraint\Same
# same( mixed $value )

Check that a value is identical to another value.

Check that a value is identical to another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\Same
The created expression.
public static Webmozart\Expression\Constraint\NotSame
# notSame( mixed $value )

Check that a value is not identical to another value.

Check that a value is not identical to another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\NotSame
The created expression.
public static Webmozart\Expression\Constraint\GreaterThan
# greaterThan( mixed $value )

Check that a value is greater than another value.

Check that a value is greater than another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\GreaterThan
The created expression.
public static Webmozart\Expression\Constraint\GreaterThanEqual
# greaterThanEqual( mixed $value )

Check that a value is greater than or equal to another value.

Check that a value is greater than or equal to another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\GreaterThanEqual
The created expression.
public static Webmozart\Expression\Constraint\LessThan
# lessThan( mixed $value )

Check that a value is less than another value.

Check that a value is less than another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\LessThan
The created expression.
public static Webmozart\Expression\Constraint\LessThanEqual
# lessThanEqual( mixed $value )

Check that a value is less than or equal to another value.

Check that a value is less than or equal to another value.

Parameters

$value
The compared value.

Returns

Webmozart\Expression\Constraint\LessThanEqual
The created expression.
public static Webmozart\Expression\Constraint\In
# in( array $values )

Check that a value occurs in a list of values.

Check that a value occurs in a list of values.

Parameters

$values
The compared values.

Returns

Webmozart\Expression\Constraint\In
The created expression.
public static Webmozart\Expression\Constraint\Matches
# matches( string $regExp )

Check that a value matches a regular expression.

Check that a value matches a regular expression.

Parameters

$regExp
The regular expression.

Returns

Webmozart\Expression\Constraint\Matches
The created expression.
public static Webmozart\Expression\Constraint\StartsWith
# startsWith( string $prefix )

Check that a value starts with a given string.

Check that a value starts with a given string.

Parameters

$prefix
The prefix string.

Returns

Webmozart\Expression\Constraint\StartsWith
The created expression.
public static Webmozart\Expression\Constraint\EndsWith
# endsWith( string $suffix )

Check that a value ends with a given string.

Check that a value ends with a given string.

Parameters

$suffix
The suffix string.

Returns

Webmozart\Expression\Constraint\EndsWith
The created expression.
public static Webmozart\Expression\Constraint\Contains
# contains( string $string )

Check that a value contains a given string.

Check that a value contains a given string.

Parameters

$string
The sub-string.

Returns

Webmozart\Expression\Constraint\Contains
The created expression.
public static Webmozart\Expression\Constraint\KeyExists
# keyExists( string $keyName )

Check that a value key exists.

Check that a value key exists.

Parameters

$keyName
The key name.

Returns

Webmozart\Expression\Constraint\KeyExists
The created expression.
public static Webmozart\Expression\Constraint\KeyNotExists
# keyNotExists( string $keyName )

Check that a value key does not exist.

Check that a value key does not exist.

Parameters

$keyName
The key name.

Returns

Webmozart\Expression\Constraint\KeyNotExists
The created expression.
Webmozart Expression API API documentation generated by ApiGen