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 protected
string|arrayCake\Database\ExpressionInterface
The field name or expression to be used in the left hand side of the operator
-
$_isMultiple protected
bool
Whether or not the value in this expression is a traversable
-
$_operator protected
string
The operator used for comparing field and value
-
$_type protected
string|null
The type to be used for casting the value to a database representation
-
$_value protected
mixed
The value to be used in the right hand side of the operation
-
$_valueExpressions protected
Cake\Database\ExpressionInterface[]
A cached list of ExpressionInterface objects that were found in the value for this expression.
Method Summary
-
__clone() public
Create a deep clone.
-
__construct() public
Constructor
-
_bindValue() protected
Registers a value in the placeholder generator and returns the generated placeholder
-
_castToExpression() protected
Conditionally converts the passed value to an ExpressionInterface object if the type class implements the ExpressionTypeInterface. Otherwise, returns the value unmodified.
-
_collectExpressions() protected
Returns an array with the original $values in the first position and all ExpressionInterface objects that could be found in the second position.
-
_flattenValue() protected
Converts a traversable value into a set of placeholders generated by $generator and separated by
,
-
_requiresToExpressionCasting() protected
Returns an array with the types that require values to be casted to expressions, out of the list of type names passed as parameter.
-
_stringExpression() protected
Returns a template and a placeholder for the value after registering it with the placeholder $generator
-
getField() public
Returns the field name
-
getOperator() public
Returns the operator used for comparison
-
getValue() public
Returns the value used for comparison
-
setField() public
Sets the field name
-
setOperator() public
Sets the operator to use for the comparison
-
setValue() public
Sets the value
-
sql() public
Convert the expression into a SQL fragment.
-
traverse() public
Iterates 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
__clone() ¶ public
__clone(): void
Create a deep clone.
Clones the field and value if they are expression objects.
Returns
void
__construct() ¶ public
__construct(stringCake\Database\ExpressionInterface $field, mixed $value, string|null $type = null, string $operator = '=')
Constructor
Parameters
-
stringCake\Database\ExpressionInterface
$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 $generator, string|null $type = null): string
Registers 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|null
$type optional The type of $value
Returns
string
_castToExpression() ¶ protected
_castToExpression(mixed $value, string|null $type = null): mixed
Conditionally 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 converto to ExpressionInterface
-
string|null
$type optional The type name
Returns
mixed
_collectExpressions() ¶ protected
_collectExpressions(iterableCake\Database\ExpressionInterface $values): array
Returns an array with the original $values in the first position and all ExpressionInterface objects that could be found in the second position.
Parameters
-
iterableCake\Database\ExpressionInterface
$values The rows to insert
Returns
array
_flattenValue() ¶ protected
_flattenValue(iterable $value, Cake\Database\ValueBinder $generator, string|null $type = null): string
Converts a traversable value into a set of placeholders generated by
$generator and separated by ,
Parameters
-
iterable
$value the value to flatten
-
Cake\Database\ValueBinder
$generator The value binder to use
-
string|null
$type optional the type to cast values to
Returns
string
_requiresToExpressionCasting() ¶ protected
_requiresToExpressionCasting(array $types): array
Returns 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 $generator): array
Returns 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
array
getField() ¶ public
getField(): string|arrayCake\Database\ExpressionInterface
Returns the field name
Returns
string|arrayCake\Database\ExpressionInterface
getOperator() ¶ public
getOperator(): string
Returns the operator used for comparison
Returns
string
setField() ¶ public
setField(string|arrayCake\Database\ExpressionInterface $field): void
Sets the field name
Parameters
-
string|arrayCake\Database\ExpressionInterface
$field The field to compare with.
Returns
void
setOperator() ¶ public
setOperator(string $operator): void
Sets the operator to use for the comparison
Parameters
-
string
$operator The operator to be used for the comparison.
Returns
void
setValue() ¶ public
setValue(mixed $value): void
Sets the value
Parameters
-
mixed
$value The value to compare
Returns
void
sql() ¶ public
sql(Cake\Database\ValueBinder $generator): string
Convert the expression into a SQL fragment.
Parameters
-
Cake\Database\ValueBinder
$generator Placeholder generator object
Returns
string
traverse() ¶ public
traverse(Closure $visitor): $this
Iterates 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
-
Closure
$visitor
Returns
$this
Property Detail
$_field ¶ protected
The field name or expression to be used in the left hand side of the operator
Type
string|arrayCake\Database\ExpressionInterface
$_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
Cake\Database\ExpressionInterface[]