Class Comparison
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 protectedstringThe field name or expression to be used in the left hand side of the operator 
- 
        $_operator protectedstringThe operator used for comparing field and value 
- 
        $_type protectedstringThe 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 
Method Summary
- 
          __construct() publicConstructor 
- 
          _bindValue() protectedRegisters a value in the placeholder generator and returns the generated placeholder 
- 
          _flattenValue() protectedConverts a traversable value into a set of placeholders generated by $generator and separated by ,
- 
          _stringExpression() protectedReturns a template and a placeholder for the value after registering it with the placeholder $generator 
- 
          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() publicConvert the expression into a SQL fragment. 
- 
          traverse() publicIterates over each part of the expression recursively for every level of the expressions tree and executes the $visitor callable passing as first parameter the instance of the expression currently being iterated. 
Method Detail
__construct() ¶ public
__construct(string $field, mixed $value, string $type, string $operator)Constructor
Parameters
- 
                string$field
- the field name to compare to a value 
- 
                mixed$value
- The value to be used in comparison 
- 
                string$type
- the type name used to cast the value 
- 
                string$operator
- the operator used for comparing field and value 
_bindValue() ¶ protected
_bindValue(mixed $value, Cake\Database\ValueBinder $generator, string $type): stringRegisters a value in the placeholder generator and returns the generated placeholder
Parameters
- 
                mixed$value
- The value to bind 
- 
                Cake\Database\ValueBinder$generator
- The value binder to use 
- 
                string$type
- The type of $value 
Returns
stringgenerated placeholder
_flattenValue() ¶ protected
_flattenValue(array|Traversable $value, Cake\Database\ValueBinder $generator, string|array $type = null): stringConverts a traversable value into a set of placeholders generated by
$generator and separated by ,
Parameters
- 
                array|Traversable$value
- the value to flatten 
- 
                Cake\Database\ValueBinder$generator
- The value binder to use 
- 
                string|array$type optional
- the type to cast values to 
Returns
string_stringExpression() ¶ protected
_stringExpression(Cake\Database\ValueBinder $generator): arrayReturns a template and a placeholder for the value after registering it with the placeholder $generator
Parameters
- 
                Cake\Database\ValueBinder$generator
- The value binder to use. 
Returns
arrayFirst position containing the template and the second a placeholder
getField() ¶ public
getField(): string|Cake\Database\ExpressionInterfaceReturns the field name
Returns
string|Cake\Database\ExpressionInterfacegetOperator() ¶ public
getOperator(): stringReturns the operator used for comparison
Returns
stringsetField() ¶ public
setField(string $field): voidSets the field name
Parameters
- 
                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 $generator): stringConvert the expression into a SQL fragment.
Parameters
- 
                Cake\Database\ValueBinder$generator
- Placeholder generator object 
Returns
stringtraverse() ¶ public
traverse(callable $callable): voidIterates over each part of the expression recursively for every level of the expressions tree and executes the $visitor callable passing as first parameter the instance of the expression currently being iterated.
Parameters
- 
                callable$callable
Returns
void