Class ComparisonExpression
A Comparison is a type of query expression that represents an operation
involving a field an operator and a value. In its most common form the
string representation of a comparison is field = value
Property Summary
- 
        $_field protectedCake\Database\ExpressionInterface|array|stringThe field name or expression to be used in the left hand side of the operator 
- 
        $_isMultiple protectedboolWhether the value in this expression is a traversable 
- 
        $_operator protectedstringThe operator used for comparing field and value 
- 
        $_type protectedstring|nullThe type to be used for casting the value to a database representation 
- 
        $_value protectedmixedThe value to be used in the right hand side of the operation 
- 
        $_valueExpressions protectedarray<Cake\Database\ExpressionInterface>A cached list of ExpressionInterface objects that were found in the value for this expression. 
Method Summary
- 
          __clone() publicCreate a deep clone. 
- 
          __construct() publicConstructor 
- 
          _bindValue() protectedRegisters a value in the placeholder generator and returns the generated placeholder 
- 
          _castToExpression() protectedConditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified. 
- 
          _collectExpressions() protectedReturns an array with the original $values in the first position and all ExpressionInterface objects that could be found in the second position. 
- 
          _flattenValue() protectedConverts a traversable value into a set of placeholders generated by $binder and separated by ,
- 
          _requiresToExpressionCasting() protectedReturns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter. 
- 
          _stringExpression() protectedReturns a template and a placeholder for the value after registering it with the placeholder $binder 
- 
          getField() publicReturns the field name 
- 
          getOperator() publicReturns the operator used for comparison 
- 
          getValue() publicReturns the value used for comparison 
- 
          setField() publicSets the field name 
- 
          setOperator() publicSets the operator to use for the comparison 
- 
          setValue() publicSets the value 
- 
          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 callable passing as first parameter the instance of the expression currently being iterated. 
Method Detail
__clone() ¶ public
__clone(): voidCreate a deep clone.
Clones the field and value if they are expression objects.
Returns
void__construct() ¶ public
__construct(Cake\Database\ExpressionInterface|string $field, mixed $value, string|null $type = null, string $operator = '=')Constructor
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- the field name to compare to a value 
- 
                mixed$value
- The value to be used in comparison 
- 
                string|null$type optional
- the type name used to cast the value 
- 
                string$operator optional
- the operator used for comparing field and value 
_bindValue() ¶ protected
_bindValue(mixed $value, Cake\Database\ValueBinder $binder, string|null $type = null): stringRegisters a value in the placeholder generator and returns the generated placeholder
Parameters
- 
                mixed$value
- The value to bind 
- 
                Cake\Database\ValueBinder$binder
- The value binder to use 
- 
                string|null$type optional
- The type of $value 
Returns
stringgenerated placeholder
_castToExpression() ¶ protected
_castToExpression(mixed $value, string|null $type = null): mixedConditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
Parameters
- 
                mixed$value
- The value to convert to ExpressionInterface 
- 
                string|null$type optional
- The type name 
Returns
mixed_collectExpressions() ¶ protected
_collectExpressions(Cake\Database\ExpressionInterface|iterable $values): arrayReturns an array with the original $values in the first position and all ExpressionInterface objects that could be found in the second position.
Parameters
- 
                Cake\Database\ExpressionInterface|iterable$values
- The rows to insert 
Returns
array_flattenValue() ¶ protected
_flattenValue(iterable $value, Cake\Database\ValueBinder $binder, string|null $type = null): stringConverts a traversable value into a set of placeholders generated by
$binder and separated by ,
Parameters
- 
                iterable$value
- the value to flatten 
- 
                Cake\Database\ValueBinder$binder
- The value binder to use 
- 
                string|null$type optional
- the type to cast values to 
Returns
string_requiresToExpressionCasting() ¶ protected
_requiresToExpressionCasting(array $types): arrayReturns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
Parameters
- 
                array$types
- List of type names 
Returns
array_stringExpression() ¶ protected
_stringExpression(Cake\Database\ValueBinder $binder): arrayReturns a template and a placeholder for the value after registering it with the placeholder $binder
Parameters
- 
                Cake\Database\ValueBinder$binder
- The value binder to use. 
Returns
arrayFirst position containing the template and the second a placeholder
getField() ¶ public
getField(): Cake\Database\ExpressionInterface|array|stringReturns the field name
Returns
Cake\Database\ExpressionInterface|array|stringgetOperator() ¶ public
getOperator(): stringReturns the operator used for comparison
Returns
stringsetField() ¶ public
setField(Cake\Database\ExpressionInterface|array|string $field): voidSets the field name
Parameters
- 
                Cake\Database\ExpressionInterface|array|string$field
- The field to compare with. 
Returns
voidsetOperator() ¶ public
setOperator(string $operator): voidSets the operator to use for the comparison
Parameters
- 
                string$operator
- The operator to be used for the comparison. 
Returns
voidsetValue() ¶ public
setValue(mixed $value): voidSets the value
Parameters
- 
                mixed$value
- The value to compare 
Returns
voidsql() ¶ 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 callable passing as first parameter the instance of the expression currently being iterated.
Parameters
- 
                Closure$callback
Returns
$thisProperty Detail
$_field ¶ protected
The field name or expression to be used in the left hand side of the operator
Type
Cake\Database\ExpressionInterface|array|string$_type ¶ protected
The type to be used for casting the value to a database representation
Type
string|null$_valueExpressions ¶ protected
A cached list of ExpressionInterface objects that were found in the value for this expression.
Type
array<Cake\Database\ExpressionInterface>