TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ExpressionBuilder Class Reference

Public Member Functions

 __construct (Connection $connection)
 
 andX (...$expressions)
 
 orX (...$expressions)
 
 comparison ($leftExpression, string $operator, $rightExpression)
 
 eq (string $fieldName, $value)
 
 neq (string $fieldName, $value)
 
 lt ($fieldName, $value)
 
 lte (string $fieldName, $value)
 
 gt (string $fieldName, $value)
 
 gte (string $fieldName, $value)
 
 isNull (string $fieldName)
 
 isNotNull (string $fieldName)
 
 like (string $fieldName, $value)
 
 notLike (string $fieldName, $value)
 
 in (string $fieldName, $value)
 
 notIn (string $fieldName, $value)
 
 inSet (string $fieldName, string $value)
 
 bitAnd (string $fieldName, int $value)
 
 min (string $fieldName, string $alias=null)
 
 max (string $fieldName, string $alias=null)
 
 avg (string $fieldName, string $alias=null)
 
 sum (string $fieldName, string $alias=null)
 
 count (string $fieldName, string $alias=null)
 
 literal ($input, string $type=null)
 

Public Attributes

const EQ = '='
 
const NEQ = '<>'
 
const LT = '<'
 
const LTE = '<='
 
const GT = '>'
 
const GTE = '>='
 
const QUOTE_NOTHING = 0
 
const QUOTE_IDENTIFIER = 1
 
const QUOTE_PARAMETER = 2
 

Protected Member Functions

 calculation (string $aggregateName, string $fieldName, string $alias=null)
 
 unquoteLiteral (string $value)
 

Protected Attributes

 $connection
 

Detailed Description

ExpressionBuilder class is responsible to dynamically create SQL query parts.

It takes care building query conditions while ensuring table and column names are quoted within the created expressions / SQL fragments. It is a facade to the actual Doctrine ExpressionBuilder.

The ExpressionBuilder is used within the context of the QueryBuilder to ensure queries are being build based on the requirements of the database platform in use.

Definition at line 31 of file ExpressionBuilder.php.

Constructor & Destructor Documentation

__construct ( Connection  $connection)

Initializes a new ExpressionBuilder

Parameters
Connection$connection

Definition at line 56 of file ExpressionBuilder.php.

References ExpressionBuilder\$connection.

Member Function Documentation

andX (   $expressions)

Creates a conjunction of the given boolean expressions

Parameters
mixed,...$expressions Optional clause. Requires at least one defined when converting to string.
Returns
CompositeExpression

Definition at line 68 of file ExpressionBuilder.php.

Referenced by HiddenRestriction\buildExpression(), DeletedRestriction\buildExpression(), AbstractRestrictionContainer\buildExpression(), RootLevelRestriction\buildExpression(), EndTimeRestriction\buildExpression(), StartTimeRestriction\buildExpression(), and FrontendWorkspaceRestriction\buildExpression().

avg ( string  $fieldName,
string  $alias = null 
)

Creates a AVG expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
string

Definition at line 408 of file ExpressionBuilder.php.

References ExpressionBuilder\calculation().

bitAnd ( string  $fieldName,
int  $value 
)

Creates a bitwise AND expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
int$valueArgument to be used in the bitwise AND operation
Returns
string

Definition at line 358 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

calculation ( string  $aggregateName,
string  $fieldName,
string  $alias = null 
)
protected

Create a SQL aggregrate function.

Parameters
string$aggregateName
string$fieldName
string | null$alias
Returns
string

Definition at line 445 of file ExpressionBuilder.php.

Referenced by ExpressionBuilder\avg(), ExpressionBuilder\count(), ExpressionBuilder\max(), ExpressionBuilder\min(), and ExpressionBuilder\sum().

comparison (   $leftExpression,
string  $operator,
  $rightExpression 
)

Creates a comparison expression.

Parameters
mixed$leftExpressionThe left expression.
string$operatorOne of the ExpressionBuilder::* constants.
mixed$rightExpressionThe right expression.
Returns
string

Definition at line 94 of file ExpressionBuilder.php.

Referenced by ExpressionBuilder\bitAnd(), ExpressionBuilder\eq(), ExpressionBuilder\gt(), ExpressionBuilder\gte(), ExpressionBuilder\in(), ExpressionBuilder\inSet(), ExpressionBuilder\like(), ExpressionBuilder\lt(), ExpressionBuilder\lte(), ExpressionBuilder\neq(), ExpressionBuilder\notIn(), and ExpressionBuilder\notLike().

count ( string  $fieldName,
string  $alias = null 
)

Creates a COUNT expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
string

Definition at line 432 of file ExpressionBuilder.php.

References ExpressionBuilder\calculation().

eq ( string  $fieldName,
  $value 
)

Creates an equality comparison expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 107 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

Referenced by HiddenRestriction\buildExpression(), DeletedRestriction\buildExpression(), RootLevelRestriction\buildExpression(), FrontendGroupRestriction\buildExpression(), EndTimeRestriction\buildExpression(), BackendWorkspaceRestriction\buildExpression(), and FrontendWorkspaceRestriction\buildExpression().

gt ( string  $fieldName,
  $value 
)

Creates a greater-than comparison expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 165 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

Referenced by EndTimeRestriction\buildExpression().

gte ( string  $fieldName,
  $value 
)

Creates a greater-than-equal comparison expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 178 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

in ( string  $fieldName,
  $value 
)

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

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
string | array$valueThe placeholder or the array of values to be used by IN() comparison. No automatic quoting/escaping is done.
Returns
string

Definition at line 242 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

inSet ( string  $fieldName,
string  $value 
)

Returns a comparison that can find a value in a list field (CSV).

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
string$valueArgument to be used in FIND_IN_SET() comparison. No automatic quoting/escaping is done.
Returns
string
Exceptions
RuntimeException

Definition at line 277 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison(), ExpressionBuilder\literal(), and ExpressionBuilder\unquoteLiteral().

Referenced by FrontendGroupRestriction\buildExpression().

isNotNull ( string  $fieldName)

Creates an IS NOT NULL expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
Returns
string

Definition at line 202 of file ExpressionBuilder.php.

isNull ( string  $fieldName)

Creates an IS NULL expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
Returns
string

Definition at line 190 of file ExpressionBuilder.php.

Referenced by FrontendGroupRestriction\buildExpression().

like ( string  $fieldName,
  $value 
)

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

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueArgument to be used in LIKE() comparison. No automatic quoting/escaping is done.
Returns
string

Definition at line 215 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

literal (   $input,
string  $type = null 
)

Quotes a given input parameter.

Parameters
mixed$inputThe parameter to be quoted.
string | null$typeThe type of the parameter.
Returns
string

Definition at line 468 of file ExpressionBuilder.php.

Referenced by FrontendGroupRestriction\buildExpression(), and ExpressionBuilder\inSet().

lt (   $fieldName,
  $value 
)

Creates a lower-than comparison expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 139 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

lte ( string  $fieldName,
  $value 
)

Creates a lower-than-equal comparison expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 152 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

Referenced by StartTimeRestriction\buildExpression(), BackendWorkspaceRestriction\buildExpression(), and FrontendWorkspaceRestriction\buildExpression().

max ( string  $fieldName,
string  $alias = null 
)

Creates a MAX expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
string

Definition at line 396 of file ExpressionBuilder.php.

References ExpressionBuilder\calculation().

min ( string  $fieldName,
string  $alias = null 
)

Creates a MIN expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
string

Definition at line 384 of file ExpressionBuilder.php.

References ExpressionBuilder\calculation().

neq ( string  $fieldName,
  $value 
)

Creates a non 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 <left expr>=""> <> <right expr>="">. Example:

[php]
// u.id <> 1
$q->where($q->expr()->neq('u.id', '1'));
Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 126 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

Referenced by FrontendWorkspaceRestriction\buildExpression().

notIn ( string  $fieldName,
  $value 
)

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

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
string | array$valueThe placeholder or the array of values to be used by NOT IN() comparison. No automatic quoting/escaping is done.
Returns
string

Definition at line 260 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

notLike ( string  $fieldName,
  $value 
)

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

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueArgument to be used in NOT LIKE() comparison. No automatic quoting/escaping is done.
Returns
string

Definition at line 228 of file ExpressionBuilder.php.

References ExpressionBuilder\comparison().

orX (   $expressions)

Creates a disjunction of the given boolean expressions.

Parameters
mixed,...$expressions Optional clause. Requires at least one defined when converting to string.
Returns
CompositeExpression

Definition at line 80 of file ExpressionBuilder.php.

Referenced by FrontendGroupRestriction\buildExpression(), EndTimeRestriction\buildExpression(), BackendWorkspaceRestriction\buildExpression(), and FrontendWorkspaceRestriction\buildExpression().

sum ( string  $fieldName,
string  $alias = null 
)

Creates a SUM expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
string

Definition at line 420 of file ExpressionBuilder.php.

References ExpressionBuilder\calculation().

unquoteLiteral ( string  $value)
protected

Unquote a string literal. Used to unquote values for internal platform adjustments.

Parameters
string$valueThe value to be unquoted
Returns
string The unquoted value

Definition at line 479 of file ExpressionBuilder.php.

Referenced by ExpressionBuilder\inSet().

Member Data Documentation

$connection
protected

Definition at line 49 of file ExpressionBuilder.php.

Referenced by ExpressionBuilder\__construct().

const GT = '>'

Definition at line 37 of file ExpressionBuilder.php.

const GTE = '>='

Definition at line 38 of file ExpressionBuilder.php.

const LT = '<'

Definition at line 35 of file ExpressionBuilder.php.

const LTE = '<='

Definition at line 36 of file ExpressionBuilder.php.

const NEQ = '<>'
const QUOTE_IDENTIFIER = 1

Definition at line 41 of file ExpressionBuilder.php.

const QUOTE_NOTHING = 0

Definition at line 40 of file ExpressionBuilder.php.

const QUOTE_PARAMETER = 2

Definition at line 42 of file ExpressionBuilder.php.