Documentation

Expr
in package

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

Tags
link
www.doctrine-project.org
todo

Rename: ExpressionBuilder

Table of Contents

Methods

abs()  : Func
Creates an ABS() function expression with the given argument.
all()  : Func
Creates an instance of ALL() function, with the given DQL Subquery.
andX()  : Andx
Creates a conjunction of the given boolean expressions.
any()  : Func
Creates an ANY() function expression with the given DQL subquery.
asc()  : OrderBy
Creates an ASCending order expression.
avg()  : Func
Creates an instance of AVG() function, with the given argument.
between()  : string
Creates an instance of BETWEEN() function, with the given argument.
concat()  : Func
Creates a CONCAT() function expression with the given arguments.
count()  : Func
Creates an instance of COUNT() function, with the given argument.
countDistinct()  : string
Creates an instance of COUNT(DISTINCT) function, with the given argument.
desc()  : OrderBy
Creates a DESCending order expression.
diff()  : Math
Creates a difference mathematical expression with the given arguments.
eq()  : Comparison
Creates an equality comparison expression with the given arguments.
exists()  : Func
Creates an instance of EXISTS() function, with the given DQL Subquery.
gt()  : Comparison
Creates an instance of Expr\Comparison, with the given arguments.
gte()  : Comparison
Creates an instance of Expr\Comparison, with the given arguments.
in()  : Func
Creates an IN() expression with the given arguments.
isInstanceOf()  : Comparison
Creates an instance of INSTANCE OF function, with the given arguments.
isMemberOf()  : Comparison
Creates an instance of MEMBER OF function, with the given arguments.
isNotNull()  : string
Creates an IS NOT NULL expression with the given arguments.
isNull()  : string
Creates an IS NULL expression with the given arguments.
length()  : Func
Creates a LENGTH() function expression with the given argument.
like()  : Comparison
Creates a LIKE() comparison expression with the given arguments.
literal()  : Literal
Creates a literal expression of the given argument.
lower()  : Func
Creates a LOWER() function expression with the given argument.
lt()  : Comparison
Creates an instance of Expr\Comparison, with the given arguments.
lte()  : Comparison
Creates an instance of Expr\Comparison, with the given arguments.
max()  : Func
Creates an instance of MAX() function, with the given argument.
min()  : Func
Creates an instance of MIN() function, with the given argument.
mod()  : Func
Creates a MOD($x, $y) function expression to return the remainder of $x divided by $y.
neq()  : Comparison
Creates an instance of Expr\Comparison, with the given arguments.
not()  : Func
Creates a negation expression of the given restriction.
notIn()  : Func
Creates a NOT IN() expression with the given arguments.
notLike()  : Comparison
Creates a NOT LIKE() comparison expression with the given arguments.
orX()  : Orx
Creates a disjunction of the given boolean expressions.
prod()  : Math
Creates a product mathematical expression with the given arguments.
quot()  : Math
Creates a quotient mathematical expression with the given arguments.
some()  : Func
Creates a SOME() function expression with the given DQL subquery.
sqrt()  : Func
Creates a SQRT() function expression with the given argument.
substring()  : Func
Creates a SUBSTRING() function expression with the given arguments.
sum()  : Math
Creates a sum mathematical expression with the given arguments.
trim()  : Func
Creates an instance of TRIM() function, with the given argument.
upper()  : Func
Creates an UPPER() function expression with the given argument.
quoteLiteral()  : string
Quotes a literal value, if necessary, according to the DQL syntax.

Methods

abs()

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

public abs(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in ABS() function.

Return values
Func

all()

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

public all(mixed $subquery) : Func
Parameters
$subquery : mixed

DQL Subquery to be used in ALL() function.

Return values
Func

andX()

Creates a conjunction of the given boolean expressions.

public andX([Comparison|Func|Andx|Orx|string $x = null ]) : Andx

Example:

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

Parameters
$x : Comparison|Func|Andx|Orx|string = null

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

Tags
psalm-param

Expr\Comparison|Expr\Func|Expr\Andx|Expr\Orx|string ...$x

Return values
Andx

any()

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

public any(mixed $subquery) : Func
Parameters
$subquery : mixed

DQL Subquery to be used in ANY() function.

Return values
Func

asc()

Creates an ASCending order expression.

public asc(mixed $expr) : OrderBy
Parameters
$expr : mixed
Return values
OrderBy

avg()

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

public avg(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in AVG() function.

Return values
Func

between()

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

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

Valued to be inspected by range values.

$x : int|string

Starting range value to be used in BETWEEN() function.

$y : int|string

End point value to be used in BETWEEN() function.

Return values
string

A BETWEEN expression.

concat()

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

public concat(mixed $x, mixed $y) : Func
Parameters
$x : mixed

First argument to be used in CONCAT() function.

$y : mixed
Return values
Func

count()

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

public count(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in COUNT() function.

Return values
Func

countDistinct()

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

public countDistinct(mixed $x) : string
Parameters
$x : mixed

Argument to be used in COUNT(DISTINCT) function.

Return values
string

desc()

Creates a DESCending order expression.

public desc(mixed $expr) : OrderBy
Parameters
$expr : mixed
Return values
OrderBy

diff()

Creates a difference mathematical expression with the given arguments.

public diff(mixed $x, mixed $y) : Math

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Math

eq()

Creates an equality comparison expression with the given arguments.

public eq(mixed $x, mixed $y) : Comparison

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Comparison

exists()

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

public exists(mixed $subquery) : Func
Parameters
$subquery : mixed

DQL Subquery to be used in EXISTS() function.

Return values
Func

gt()

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

public gt(mixed $x, mixed $y) : Comparison

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Comparison

gte()

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

public gte(mixed $x, mixed $y) : Comparison

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Comparison

in()

Creates an IN() expression with the given arguments.

public in(string $x, mixed $y) : Func
Parameters
$x : string

Field in string format to be restricted by IN() function.

$y : mixed

Argument to be used in IN() function.

Return values
Func

isInstanceOf()

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

public isInstanceOf(string $x, string $y) : Comparison
Parameters
$x : string

Value to be checked

$y : string

Value to be checked against

Return values
Comparison

isMemberOf()

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

public isMemberOf(string $x, string $y) : Comparison
Parameters
$x : string

Value to be checked

$y : string

Value to be checked against

Return values
Comparison

isNotNull()

Creates an IS NOT NULL expression with the given arguments.

public isNotNull(string $x) : string
Parameters
$x : string

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

Return values
string

isNull()

Creates an IS NULL expression with the given arguments.

public isNull(string $x) : string
Parameters
$x : string

Field in string format to be restricted by IS NULL.

Return values
string

length()

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

public length(mixed $x) : Func
Parameters
$x : mixed

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

Return values
Func

A LENGTH function expression.

like()

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

public like(string $x, mixed $y) : Comparison
Parameters
$x : string

Field in string format to be inspected by LIKE() comparison.

$y : mixed

Argument to be used in LIKE() comparison.

Return values
Comparison

literal()

Creates a literal expression of the given argument.

public literal(scalar $literal) : Literal
Parameters
$literal : scalar

Argument to be converted to literal.

Return values
Literal

lower()

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

public lower(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in LOWER() function.

Return values
Func

A LOWER function expression.

lt()

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

public lt(mixed $x, mixed $y) : Comparison

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Comparison

lte()

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

public lte(mixed $x, mixed $y) : Comparison

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Comparison

max()

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

public max(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in MAX() function.

Return values
Func

min()

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

public min(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in MIN() function.

Return values
Func

mod()

Creates a MOD($x, $y) function expression to return the remainder of $x divided by $y.

public mod(mixed $x, mixed $y) : Func
Parameters
$x : mixed
$y : mixed
Return values
Func

neq()

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

public neq(mixed $x, mixed $y) : Comparison

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Comparison

not()

Creates a negation expression of the given restriction.

public not(mixed $restriction) : Func
Parameters
$restriction : mixed

Restriction to be used in NOT() function.

Return values
Func

notIn()

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

public notIn(string $x, mixed $y) : Func
Parameters
$x : string

Field in string format to be restricted by NOT IN() function.

$y : mixed

Argument to be used in NOT IN() function.

Return values
Func

notLike()

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

public notLike(string $x, mixed $y) : Comparison
Parameters
$x : string

Field in string format to be inspected by LIKE() comparison.

$y : mixed

Argument to be used in LIKE() comparison.

Return values
Comparison

orX()

Creates a disjunction of the given boolean expressions.

public orX([Comparison|Func|Andx|Orx|string $x = null ]) : Orx

Example:

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

Parameters
$x : Comparison|Func|Andx|Orx|string = null

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

Tags
psalm-param

Expr\Comparison|Expr\Func|Expr\Andx|Expr\Orx|string ...$x

Return values
Orx

prod()

Creates a product mathematical expression with the given arguments.

public prod(mixed $x, mixed $y) : Math

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Math

quot()

Creates a quotient mathematical expression with the given arguments.

public quot(mixed $x, mixed $y) : Math

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Math

some()

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

public some(mixed $subquery) : Func
Parameters
$subquery : mixed

DQL Subquery to be used in SOME() function.

Return values
Func

sqrt()

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

public sqrt(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in SQRT() function.

Return values
Func

substring()

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

public substring(mixed $x, int $from[, int|null $len = null ]) : Func
Parameters
$x : mixed

Argument to be used as string to be cropped by SUBSTRING() function.

$from : int

Initial offset to start cropping string. May accept negative values.

$len : int|null = null

Length of crop. May accept negative values.

Return values
Func

sum()

Creates a sum mathematical expression with the given arguments.

public sum(mixed $x, mixed $y) : Math

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
$x : mixed

Left expression.

$y : mixed

Right expression.

Return values
Math

trim()

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

public trim(mixed $x) : Func
Parameters
$x : mixed

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

Return values
Func

a TRIM expression.

upper()

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

public upper(mixed $x) : Func
Parameters
$x : mixed

Argument to be used in UPPER() function.

Return values
Func

An UPPER function expression.

quoteLiteral()

Quotes a literal value, if necessary, according to the DQL syntax.

private quoteLiteral(scalar $literal) : string
Parameters
$literal : scalar

The literal value.

Return values
string

        
On this page

Search results