class Expr (View source)

This class is used to generate DQL expressions via a set of PHP static functions.

Methods

andX(Comparison|Func|Orx $x = null)

Creates a conjunction of the given boolean expressions.

Orx
orX(mixed $x = null)

Creates a disjunction of the given boolean expressions.

asc(mixed $expr)

Creates an ASCending order expression.

desc(mixed $expr)

Creates a DESCending order expression.

eq(mixed $x, mixed $y)

Creates an equality comparison expression with the given arguments.

neq(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

lt(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

lte(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

gt(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

gte(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

avg(mixed $x)

Creates an instance of AVG() function, with the given argument.

max(mixed $x)

Creates an instance of MAX() function, with the given argument.

min(mixed $x)

Creates an instance of MIN() function, with the given argument.

count(mixed $x)

Creates an instance of COUNT() function, with the given argument.

string
countDistinct(mixed $x)

Creates an instance of COUNT(DISTINCT) function, with the given argument.

exists(mixed $subquery)

Creates an instance of EXISTS() function, with the given DQL Subquery.

all(mixed $subquery)

Creates an instance of ALL() function, with the given DQL Subquery.

some(mixed $subquery)

Creates a SOME() function expression with the given DQL subquery.

any(mixed $subquery)

Creates an ANY() function expression with the given DQL subquery.

not(mixed $restriction)

Creates a negation expression of the given restriction.

abs(mixed $x)

Creates an ABS() function expression with the given argument.

prod(mixed $x, mixed $y)

Creates a product mathematical expression with the given arguments.

diff(mixed $x, mixed $y)

Creates a difference mathematical expression with the given arguments.

sum(mixed $x, mixed $y)

Creates a sum mathematical expression with the given arguments.

quot(mixed $x, mixed $y)

Creates a quotient mathematical expression with the given arguments.

sqrt(mixed $x)

Creates a SQRT() function expression with the given argument.

in(string $x, mixed $y)

Creates an IN() expression with the given arguments.

notIn(string $x, mixed $y)

Creates a NOT IN() expression with the given arguments.

string
isNull(string $x)

Creates an IS NULL expression with the given arguments.

string
isNotNull(string $x)

Creates an IS NOT NULL expression with the given arguments.

like(string $x, mixed $y)

Creates a LIKE() comparison expression with the given arguments.

notLike(string $x, mixed $y)

Creates a NOT LIKE() comparison expression with the given arguments.

concat($x, $y)

Creates a CONCAT() function expression with the given arguments.

substring(mixed $x, int $from, int|null $len = null)

Creates a SUBSTRING() function expression with the given arguments.

lower(mixed $x)

Creates a LOWER() function expression with the given argument.

upper(mixed $x)

Creates an UPPER() function expression with the given argument.

length(mixed $x)

Creates a LENGTH() function expression with the given argument.

literal(mixed $literal)

Creates a literal expression of the given argument.

between(mixed $val, int|string $x, int|string $y)

Creates an instance of BETWEEN() function, with the given argument.

trim(mixed $x)

Creates an instance of TRIM() function, with the given argument.

isMemberOf(string $x, string $y)

Creates an instance of MEMBER OF function, with the given arguments.

isInstanceOf(string $x, string $y)

Creates an instance of INSTANCE OF function, with the given arguments.

Details

Andx andX(Comparison|Func|Orx $x = null)

Creates a conjunction of the given boolean expressions.

Example:

[php]
// (u.type = ?1) AND (u.role = ?2)
$expr->andX($expr->eq('u.type', ':1'), $expr->eq('u.role', ':2'));

Parameters

Comparison|Func|Orx $x Optional clause. Defaults to null, but requires at least one defined when converting to string.

Return Value

Andx

Orx orX(mixed $x = null)

Creates a disjunction of the given boolean expressions.

Example:

[php]
// (u.type = ?1) OR (u.role = ?2)
$q->where($q->expr()->orX('u.type = ?1', 'u.role = ?2'));

Parameters

mixed $x Optional clause. Defaults to null, but requires at least one defined when converting to string.

Return Value

Orx

OrderBy asc(mixed $expr)

Creates an ASCending order expression.

Parameters

mixed $expr

Return Value

OrderBy

OrderBy desc(mixed $expr)

Creates a DESCending order expression.

Parameters

mixed $expr

Return Value

OrderBy

Comparison eq(mixed $x, mixed $y)

Creates an equality comparison expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a = . Example:

[php]
// u.id = ?1
$expr->eq('u.id', '?1');

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Comparison

Comparison neq(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a <> . Example:

[php]
// u.id <> ?1
$q->where($q->expr()->neq('u.id', '?1'));

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Comparison

Comparison lt(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a < . Example:

[php]
// u.id < ?1
$q->where($q->expr()->lt('u.id', '?1'));

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Comparison

Comparison lte(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a <= . Example:

[php]
// u.id <= ?1
$q->where($q->expr()->lte('u.id', '?1'));

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Comparison

Comparison gt(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a > . Example:

[php]
// u.id > ?1
$q->where($q->expr()->gt('u.id', '?1'));

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Comparison

Comparison gte(mixed $x, mixed $y)

Creates an instance of Expr\Comparison, with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a >= . Example:

[php]
// u.id >= ?1
$q->where($q->expr()->gte('u.id', '?1'));

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Comparison

Func avg(mixed $x)

Creates an instance of AVG() function, with the given argument.

Parameters

mixed $x Argument to be used in AVG() function.

Return Value

Func

Func max(mixed $x)

Creates an instance of MAX() function, with the given argument.

Parameters

mixed $x Argument to be used in MAX() function.

Return Value

Func

Func min(mixed $x)

Creates an instance of MIN() function, with the given argument.

Parameters

mixed $x Argument to be used in MIN() function.

Return Value

Func

Func count(mixed $x)

Creates an instance of COUNT() function, with the given argument.

Parameters

mixed $x Argument to be used in COUNT() function.

Return Value

Func

string countDistinct(mixed $x)

Creates an instance of COUNT(DISTINCT) function, with the given argument.

Parameters

mixed $x Argument to be used in COUNT(DISTINCT) function.

Return Value

string

Func exists(mixed $subquery)

Creates an instance of EXISTS() function, with the given DQL Subquery.

Parameters

mixed $subquery DQL Subquery to be used in EXISTS() function.

Return Value

Func

Func all(mixed $subquery)

Creates an instance of ALL() function, with the given DQL Subquery.

Parameters

mixed $subquery DQL Subquery to be used in ALL() function.

Return Value

Func

Func some(mixed $subquery)

Creates a SOME() function expression with the given DQL subquery.

Parameters

mixed $subquery DQL Subquery to be used in SOME() function.

Return Value

Func

Func any(mixed $subquery)

Creates an ANY() function expression with the given DQL subquery.

Parameters

mixed $subquery DQL Subquery to be used in ANY() function.

Return Value

Func

Func not(mixed $restriction)

Creates a negation expression of the given restriction.

Parameters

mixed $restriction Restriction to be used in NOT() function.

Return Value

Func

Func abs(mixed $x)

Creates an ABS() function expression with the given argument.

Parameters

mixed $x Argument to be used in ABS() function.

Return Value

Func

Math prod(mixed $x, mixed $y)

Creates a product mathematical expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a * . Example:

[php]
// u.salary * u.percentAnnualSalaryIncrease
$q->expr()->prod('u.salary', 'u.percentAnnualSalaryIncrease')

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Math

Math diff(mixed $x, mixed $y)

Creates a difference mathematical expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a - . Example:

[php]
// u.monthlySubscriptionCount - 1
$q->expr()->diff('u.monthlySubscriptionCount', '1')

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Math

Math sum(mixed $x, mixed $y)

Creates a sum mathematical expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a + . Example:

[php]
// u.numChildren + 1
$q->expr()->sum('u.numChildren', '1')

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Math

Math quot(mixed $x, mixed $y)

Creates a quotient mathematical expression with the given arguments.

First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a / . Example:

[php]
// u.total / u.period
$expr->quot('u.total', 'u.period')

Parameters

mixed $x Left expression.
mixed $y Right expression.

Return Value

Math

Func sqrt(mixed $x)

Creates a SQRT() function expression with the given argument.

Parameters

mixed $x Argument to be used in SQRT() function.

Return Value

Func

Func in(string $x, mixed $y)

Creates an IN() expression with the given arguments.

Parameters

string $x Field in string format to be restricted by IN() function.
mixed $y Argument to be used in IN() function.

Return Value

Func

Func notIn(string $x, mixed $y)

Creates a NOT IN() expression with the given arguments.

Parameters

string $x Field in string format to be restricted by NOT IN() function.
mixed $y Argument to be used in NOT IN() function.

Return Value

Func

string isNull(string $x)

Creates an IS NULL expression with the given arguments.

Parameters

string $x Field in string format to be restricted by IS NULL.

Return Value

string

string isNotNull(string $x)

Creates an IS NOT NULL expression with the given arguments.

Parameters

string $x Field in string format to be restricted by IS NOT NULL.

Return Value

string

Comparison like(string $x, mixed $y)

Creates a LIKE() comparison expression with the given arguments.

Parameters

string $x Field in string format to be inspected by LIKE() comparison.
mixed $y Argument to be used in LIKE() comparison.

Return Value

Comparison

Comparison notLike(string $x, mixed $y)

Creates a NOT LIKE() comparison expression with the given arguments.

Parameters

string $x Field in string format to be inspected by LIKE() comparison.
mixed $y Argument to be used in LIKE() comparison.

Return Value

Comparison

Func concat($x, $y)

Creates a CONCAT() function expression with the given arguments.

Parameters

$x
$y

Return Value

Func

Func substring(mixed $x, int $from, int|null $len = null)

Creates a SUBSTRING() function expression with the given arguments.

Parameters

mixed $x Argument to be used as string to be cropped by SUBSTRING() function.
int $from Initial offset to start cropping string. May accept negative values.
int|null $len Length of crop. May accept negative values.

Return Value

Func

Func lower(mixed $x)

Creates a LOWER() function expression with the given argument.

Parameters

mixed $x Argument to be used in LOWER() function.

Return Value

Func A LOWER function expression.

Func upper(mixed $x)

Creates an UPPER() function expression with the given argument.

Parameters

mixed $x Argument to be used in UPPER() function.

Return Value

Func An UPPER function expression.

Func length(mixed $x)

Creates a LENGTH() function expression with the given argument.

Parameters

mixed $x Argument to be used as argument of LENGTH() function.

Return Value

Func A LENGTH function expression.

Literal literal(mixed $literal)

Creates a literal expression of the given argument.

Parameters

mixed $literal Argument to be converted to literal.

Return Value

Literal

Func between(mixed $val, int|string $x, int|string $y)

Creates an instance of BETWEEN() function, with the given argument.

Parameters

mixed $val Valued to be inspected by range values.
int|string $x Starting range value to be used in BETWEEN() function.
int|string $y End point value to be used in BETWEEN() function.

Return Value

Func A BETWEEN expression.

Func trim(mixed $x)

Creates an instance of TRIM() function, with the given argument.

Parameters

mixed $x Argument to be used as argument of TRIM() function.

Return Value

Func a TRIM expression.

Comparison isMemberOf(string $x, string $y)

Creates an instance of MEMBER OF function, with the given arguments.

Parameters

string $x Value to be checked
string $y Value to be checked against

Return Value

Comparison

Comparison isInstanceOf(string $x, string $y)

Creates an instance of INSTANCE OF function, with the given arguments.

Parameters

string $x Value to be checked
string $y Value to be checked against

Return Value

Comparison