Class OrderByExpression
An expression object for ORDER BY clauses
Property Summary
- 
        $_conditions protectedarrayA list of strings or other expression objects that represent the "branches" of the expression tree. For example one key of the array might look like "sum > :value" 
- 
        $_conjunction protectedstringString to be used for joining each of the internal expressions this object internally stores for example "AND", "OR", etc. 
- 
        $_typeMap protectedCake\Database\TypeMap|null
Method Summary
- 
          __clone() publicClone this object and its subtree of expressions. 
- 
          __construct() publicConstructor 
- 
          _addConditions() protectedAuxiliary function used for decomposing a nested array of conditions and building a tree structure inside this object to represent the full SQL expression. 
- 
          _calculateType() protectedReturns the type name for the passed field if it was stored in the typeMap 
- 
          _parseCondition() protectedParses a string conditions by trying to extract the operator inside it if any and finally returning either an adequate QueryExpression object or a plain string representation of the condition. This function is responsible for generating the placeholders and replacing the values by them, while storing the value elsewhere for future binding. 
- 
          add() publicAdds one or more conditions to this expression object. Conditions can be expressed in a one dimensional array, that will cause all conditions to be added directly at this level of the tree or they can be nested arbitrarily making it create more expression objects that will be nested inside and configured to use the specified conjunction. 
- 
          and() publicReturns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "AND" 
- 
          between() publicAdds a new condition to the expression object in the form "field BETWEEN from AND to". 
- 
          case() publicReturns a new case expression object. 
- 
          count() publicReturns the number of internal conditions that are stored in this expression. Useful to determine if this expression object is void or it will generate a non-empty string when compiled 
- 
          eq() publicAdds a new condition to the expression object in the form "field = value". 
- 
          equalFields() publicBuilds equal condition or assignment with identifier wrapping. 
- 
          exists() publicAdds a new condition to the expression object in the form "EXISTS (...)". 
- 
          getConjunction() publicGets the currently configured conjunction for the conditions at this level of the expression tree. 
- 
          getDefaultTypes() publicGets default types of current type map. 
- 
          getTypeMap() publicReturns the existing type map. 
- 
          gt() publicAdds a new condition to the expression object in the form "field > value". 
- 
          gte() publicAdds a new condition to the expression object in the form "field >= value". 
- 
          hasNestedExpression() publicReturns true if this expression contains any other nested ExpressionInterface objects 
- 
          in() publicAdds a new condition to the expression object in the form "field IN (value1, value2)". 
- 
          isNotNull() publicAdds a new condition to the expression object in the form "field IS NOT NULL". 
- 
          isNull() publicAdds a new condition to the expression object in the form "field IS NULL". 
- 
          iterateParts() publicExecutes a callback for each of the parts that form this expression. 
- 
          like() publicAdds a new condition to the expression object in the form "field LIKE value". 
- 
          lt() publicAdds a new condition to the expression object in the form "field < value". 
- 
          lte() publicAdds a new condition to the expression object in the form "field <= value". 
- 
          not() publicAdds a new set of conditions to this level of the tree and negates the final result by prepending a NOT, it will look like "NOT ( (condition1) AND (conditions2) )" conjunction depends on the one currently configured for this object. 
- 
          notEq() publicAdds a new condition to the expression object in the form "field != value". 
- 
          notExists() publicAdds a new condition to the expression object in the form "NOT EXISTS (...)". 
- 
          notIn() publicAdds a new condition to the expression object in the form "field NOT IN (value1, value2)". 
- 
          notInOrNull() publicAdds a new condition to the expression object in the form "(field NOT IN (value1, value2) OR field IS NULL". 
- 
          notLike() publicAdds a new condition to the expression object in the form "field NOT LIKE value". 
- 
          or() publicReturns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "OR" 
- 
          setConjunction() publicChanges the conjunction for the conditions at this level of the expression tree. 
- 
          setDefaultTypes() publicOverwrite the default type mappings for fields in the implementing object. 
- 
          setTypeMap() publicCreates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one. 
- 
          sql() publicConverts the Node into a SQL string fragment. 
- 
          traverse() publicIterates over each part of the expression recursively for every level of the expressions tree and executes the callback, passing as first parameter the instance of the expression currently being iterated. 
Method Detail
__construct() ¶ public
__construct(Cake\Database\ExpressionInterface|array|string $conditions = [], Cake\Database\TypeMap|array $types = [], string $conjunction = '')Constructor
Parameters
- 
                Cake\Database\ExpressionInterface|array|string$conditions optional
- The sort columns 
- 
                Cake\Database\TypeMap|array$types optional
- The types for each column. 
- 
                string$conjunction optional
- The glue used to join conditions together. 
_addConditions() ¶ protected
_addConditions(array $conditions, array<int|string, string> $types): voidAuxiliary function used for decomposing a nested array of conditions and building a tree structure inside this object to represent the full SQL expression.
New order by expressions are merged to existing ones
Parameters
- 
                array$conditions
- list of order by expressions 
- 
                array<int|string, string>$types
- list of types associated on fields referenced in $conditions 
Returns
void_calculateType() ¶ protected
_calculateType(Cake\Database\ExpressionInterface|string $field): string|nullReturns the type name for the passed field if it was stored in the typeMap
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- The field name to get a type for. 
Returns
string|nullThe computed type or null, if the type is unknown.
_parseCondition() ¶ protected
_parseCondition(string $condition, mixed $value): Cake\Database\ExpressionInterface|stringParses a string conditions by trying to extract the operator inside it if any and finally returning either an adequate QueryExpression object or a plain string representation of the condition. This function is responsible for generating the placeholders and replacing the values by them, while storing the value elsewhere for future binding.
Parameters
- 
                string$condition
- The value from which the actual field and operator will be extracted. 
- 
                mixed$value
- The value to be bound to a placeholder for the field 
Returns
Cake\Database\ExpressionInterface|stringThrows
InvalidArgumentExceptionIf operator is invalid or missing on NULL usage.
add() ¶ public
add(Cake\Database\ExpressionInterface|array|string $conditions, array<int|string, string> $types = []): $thisAdds one or more conditions to this expression object. Conditions can be expressed in a one dimensional array, that will cause all conditions to be added directly at this level of the tree or they can be nested arbitrarily making it create more expression objects that will be nested inside and configured to use the specified conjunction.
If the type passed for any of the fields is expressed "type[]" (note braces) then it will cause the placeholder to be re-written dynamically so if the value is an array, it will create as many placeholders as values are in it.
Parameters
- 
                Cake\Database\ExpressionInterface|array|string$conditions
- single or multiple conditions to be added. When using an array and the key is 'OR' or 'AND' a new expression object will be created with that conjunction and internal array value passed as conditions. 
- 
                array<int|string, string>$types optional
- Associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements. 
Returns
$thisSee Also
and() ¶ public
and(Cake\Database\ExpressionInterface|Closure|array|string $conditions, array<string, string> $types = []): staticReturns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "AND"
Parameters
- 
                Cake\Database\ExpressionInterface|Closure|array|string$conditions
- to be joined with AND 
- 
                array<string, string>$types optional
- Associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements. 
Returns
staticbetween() ¶ public
between(Cake\Database\ExpressionInterface|string $field, mixed $from, mixed $to, string|null $type = null): $thisAdds a new condition to the expression object in the form "field BETWEEN from AND to".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- The field name to compare for values in between the range. 
- 
                mixed$from
- The initial value of the range. 
- 
                mixed$to
- The ending value in the comparison range. 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thiscase() ¶ public
case(Cake\Database\ExpressionInterface|object|scalar|null $value = null, string|null $type = null): Cake\Database\Expression\CaseStatementExpressionReturns a new case expression object.
When a value is set, the syntax generated is
CASE case_value WHEN when_value ... END (simple case),
where the when_value's are compared against the
case_value.
When no value is set, the syntax generated is
CASE WHEN when_conditions ... END (searched case),
where the conditions hold the comparisons.
Note that null is a valid case value, and thus should
only be passed if you actually want to create the simple
case expression variant!
Parameters
- 
                Cake\Database\ExpressionInterface|object|scalar|null$value optional
- The case value. 
- 
                string|null$type optional
- The case value type. If no type is provided, the type will be tried to be inferred from the value. 
Returns
Cake\Database\Expression\CaseStatementExpressioncount() ¶ public
count(): intReturns the number of internal conditions that are stored in this expression. Useful to determine if this expression object is void or it will generate a non-empty string when compiled
Returns
inteq() ¶ public
eq(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field = value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. If it is suffixed with "[]" and the value is an array then multiple placeholders will be created, one per each value in the array. 
Returns
$thisequalFields() ¶ public
equalFields(string $leftField, string $rightField): $thisBuilds equal condition or assignment with identifier wrapping.
Parameters
- 
                string$leftField
- Left join condition field name. 
- 
                string$rightField
- Right join condition field name. 
Returns
$thisexists() ¶ public
exists(Cake\Database\ExpressionInterface $expression): $thisAdds a new condition to the expression object in the form "EXISTS (...)".
Parameters
- 
                Cake\Database\ExpressionInterface$expression
- the inner query 
Returns
$thisgetConjunction() ¶ public
getConjunction(): stringGets the currently configured conjunction for the conditions at this level of the expression tree.
Returns
stringgetDefaultTypes() ¶ public
getDefaultTypes(): array<int|string, string>Gets default types of current type map.
Returns
array<int|string, string>getTypeMap() ¶ public
getTypeMap(): Cake\Database\TypeMapReturns the existing type map.
Returns
Cake\Database\TypeMapgt() ¶ public
gt(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field > value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thisgte() ¶ public
gte(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field >= value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thishasNestedExpression() ¶ public
hasNestedExpression(): boolReturns true if this expression contains any other nested ExpressionInterface objects
Returns
boolin() ¶ public
in(Cake\Database\ExpressionInterface|string $field, Cake\Database\ExpressionInterface|array|string $values, string|null $type = null): $thisAdds a new condition to the expression object in the form "field IN (value1, value2)".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                Cake\Database\ExpressionInterface|array|string$values
- the value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thisisNotNull() ¶ public
isNotNull(Cake\Database\ExpressionInterface|string $field): $thisAdds a new condition to the expression object in the form "field IS NOT NULL".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- database field to be tested for not null 
Returns
$thisisNull() ¶ public
isNull(Cake\Database\ExpressionInterface|string $field): $thisAdds a new condition to the expression object in the form "field IS NULL".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- database field to be tested for null 
Returns
$thisiterateParts() ¶ public
iterateParts(Closure $callback): $thisExecutes a callback for each of the parts that form this expression.
The callback is required to return a value with which the currently visited part will be replaced. If the callback returns null then the part will be discarded completely from this expression.
The callback function will receive each of the conditions as first param and the key as second param. It is possible to declare the second parameter as passed by reference, this will enable you to change the key under which the modified part is stored.
Parameters
- 
                Closure$callback
- The callback to run for each part 
Returns
$thislike() ¶ public
like(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field LIKE value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thislt() ¶ public
lt(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field < value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thislte() ¶ public
lte(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field <= value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thisnot() ¶ public
not(Cake\Database\ExpressionInterface|Closure|array|string $conditions, array<string, string> $types = []): $thisAdds a new set of conditions to this level of the tree and negates the final result by prepending a NOT, it will look like "NOT ( (condition1) AND (conditions2) )" conjunction depends on the one currently configured for this object.
Parameters
- 
                Cake\Database\ExpressionInterface|Closure|array|string$conditions
- to be added and negated 
- 
                array<string, string>$types optional
- Associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements. 
Returns
$thisnotEq() ¶ public
notEq(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field != value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. If it is suffixed with "[]" and the value is an array then multiple placeholders will be created, one per each value in the array. 
Returns
$thisnotExists() ¶ public
notExists(Cake\Database\ExpressionInterface $expression): $thisAdds a new condition to the expression object in the form "NOT EXISTS (...)".
Parameters
- 
                Cake\Database\ExpressionInterface$expression
- the inner query 
Returns
$thisnotIn() ¶ public
notIn(Cake\Database\ExpressionInterface|string $field, Cake\Database\ExpressionInterface|array|string $values, string|null $type = null): $thisAdds a new condition to the expression object in the form "field NOT IN (value1, value2)".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                Cake\Database\ExpressionInterface|array|string$values
- the value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thisnotInOrNull() ¶ public
notInOrNull(Cake\Database\ExpressionInterface|string $field, Cake\Database\ExpressionInterface|array|string $values, string|null $type = null): $thisAdds a new condition to the expression object in the form "(field NOT IN (value1, value2) OR field IS NULL".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                Cake\Database\ExpressionInterface|array|string$values
- the value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thisnotLike() ¶ public
notLike(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null): $thisAdds a new condition to the expression object in the form "field NOT LIKE value".
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Database field to be compared against value 
- 
                mixed$value
- The value to be bound to $field for comparison 
- 
                string|null$type optional
- the type name for $value as configured using the Type map. 
Returns
$thisor() ¶ public
or(Cake\Database\ExpressionInterface|Closure|array|string $conditions, array<string, string> $types = []): staticReturns a new QueryExpression object containing all the conditions passed and set up the conjunction to be "OR"
Parameters
- 
                Cake\Database\ExpressionInterface|Closure|array|string$conditions
- to be joined with OR 
- 
                array<string, string>$types optional
- Associative array of fields pointing to the type of the values that are being passed. Used for correctly binding values to statements. 
Returns
staticsetConjunction() ¶ public
setConjunction(string $conjunction): $thisChanges the conjunction for the conditions at this level of the expression tree.
Parameters
- 
                string$conjunction
- Value to be used for joining conditions 
Returns
$thissetDefaultTypes() ¶ public
setDefaultTypes(array<int|string, string> $types): $thisOverwrite the default type mappings for fields in the implementing object.
This method is useful if you need to set type mappings that are shared across multiple functions/expressions in a query.
To add a default without overwriting existing ones
use getTypeMap()->addDefaults()
Parameters
- 
                array<int|string, string>$types
- The array of types to set. 
Returns
$thisSee Also
setTypeMap() ¶ public
setTypeMap(Cake\Database\TypeMap|array<int|string, string> $typeMap): $thisCreates a new TypeMap if $typeMap is an array, otherwise exchanges it for the given one.
Parameters
- 
                Cake\Database\TypeMap|array<int|string, string>$typeMap
- Creates a TypeMap if array, otherwise sets the given TypeMap 
Returns
$thissql() ¶ public
sql(Cake\Database\ValueBinder $binder): stringConverts the Node into a SQL string fragment.
Parameters
- 
                Cake\Database\ValueBinder$binder
Returns
stringtraverse() ¶ public
traverse(Closure $callback): $thisIterates over each part of the expression recursively for every level of the expressions tree and executes the callback, passing as first parameter the instance of the expression currently being iterated.
Parameters
- 
                Closure$callback
Returns
$thisProperty Detail
$_conditions ¶ protected
A list of strings or other expression objects that represent the "branches" of the expression tree. For example one key of the array might look like "sum > :value"
Type
array$_conjunction ¶ protected
String to be used for joining each of the internal expressions this object internally stores for example "AND", "OR", etc.
Type
string