|
|
@@ -41,7 +41,7 @@ class Comparison implements ExpressionInterface, FieldInterface
|
|
|
/**
|
|
|
* The type to be used for casting the value to a database representation
|
|
|
*
|
|
|
- * @var string
|
|
|
+ * @var string|null
|
|
|
*/
|
|
|
protected $_type;
|
|
|
|
|
|
@@ -50,7 +50,7 @@ class Comparison implements ExpressionInterface, FieldInterface
|
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $_operator;
|
|
|
+ protected $_operator = '=';
|
|
|
|
|
|
/**
|
|
|
* Whether or not the value in this expression is a traversable
|
|
|
@@ -75,7 +75,7 @@ class Comparison implements ExpressionInterface, FieldInterface
|
|
|
* @param string|array|null $type the type name used to cast the value
|
|
|
* @param string $operator the operator used for comparing field and value
|
|
|
*/
|
|
|
- public function __construct($field, $value, $type, string $operator)
|
|
|
+ public function __construct($field, $value, $type = null, string $operator = '=')
|
|
|
{
|
|
|
if (is_string($type)) {
|
|
|
$this->_type = $type;
|
|
|
@@ -94,13 +94,9 @@ class Comparison implements ExpressionInterface, FieldInterface
|
|
|
*/
|
|
|
public function setValue($value): void
|
|
|
{
|
|
|
- $hasType = isset($this->_type) && is_string($this->_type);
|
|
|
- $isMultiple = $hasType && strpos($this->_type, '[]') !== false;
|
|
|
-
|
|
|
- if ($hasType) {
|
|
|
- $value = $this->_castToExpression($value, $this->_type);
|
|
|
- }
|
|
|
+ $value = $this->_castToExpression($value, $this->_type);
|
|
|
|
|
|
+ $isMultiple = $this->_type && strpos($this->_type, '[]') !== false;
|
|
|
if ($isMultiple) {
|
|
|
[$value, $this->_valueExpressions] = $this->_collectExpressions($value);
|
|
|
}
|
|
|
@@ -221,7 +217,10 @@ class Comparison implements ExpressionInterface, FieldInterface
|
|
|
|
|
|
if ($this->_isMultiple) {
|
|
|
$template .= '%s (%s)';
|
|
|
- $type = str_replace('[]', '', $this->_type);
|
|
|
+ $type = $this->_type;
|
|
|
+ if ($type !== null) {
|
|
|
+ $type = str_replace('[]', '', $type);
|
|
|
+ }
|
|
|
$value = $this->_flattenValue($this->_value, $generator, $type);
|
|
|
|
|
|
// To avoid SQL errors when comparing a field to a list of empty values,
|
|
|
@@ -246,10 +245,10 @@ class Comparison implements ExpressionInterface, FieldInterface
|
|
|
*
|
|
|
* @param mixed $value The value to bind
|
|
|
* @param \Cake\Database\ValueBinder $generator The value binder to use
|
|
|
- * @param string $type The type of $value
|
|
|
+ * @param string|null $type The type of $value
|
|
|
* @return string generated placeholder
|
|
|
*/
|
|
|
- protected function _bindValue($value, ValueBinder $generator, $type): string
|
|
|
+ protected function _bindValue($value, ValueBinder $generator, ?string $type = null): string
|
|
|
{
|
|
|
$placeholder = $generator->placeholder('c');
|
|
|
$generator->bind($placeholder, $value, $type);
|
|
|
@@ -263,10 +262,10 @@ class Comparison implements ExpressionInterface, FieldInterface
|
|
|
*
|
|
|
* @param iterable $value the value to flatten
|
|
|
* @param \Cake\Database\ValueBinder $generator The value binder to use
|
|
|
- * @param string $type the type to cast values to
|
|
|
+ * @param string|null $type the type to cast values to
|
|
|
* @return string
|
|
|
*/
|
|
|
- protected function _flattenValue(iterable $value, ValueBinder $generator, string $type = 'string'): string
|
|
|
+ protected function _flattenValue(iterable $value, ValueBinder $generator, ?string $type = null): string
|
|
|
{
|
|
|
$parts = [];
|
|
|
if (is_array($value)) {
|