Skip to content
Permalink
Browse files

Adding doc blocks and fixing some failing tests

  • Loading branch information...
lorenzo committed Mar 24, 2016
1 parent bff49bd commit a4c1222fcec70fd6547be6020f1e8df6b64d4dac
@@ -53,8 +53,19 @@ class Comparison implements ExpressionInterface, FieldInterface
*/
protected $_operator;
/**
* Whether or not the value in this expressions is a traversable
*
* @var bool
*/
protected $_isMultiple = false;
/**
* A cached list of ExpressionInterface objects that were
* found in the value for this expression.
*
* @var array
*/
protected $_valueExpressions = [];
/**
@@ -92,7 +103,7 @@ public function setValue($value)
}
if ($isMultiple) {
$this->_valueExpressions = $this->_collectExpressions($value);
list($value, $this->_valueExpressions) = $this->_collectExpressions($value);
}
$this->_isMultiple = $isMultiple;
@@ -255,7 +266,6 @@ protected function _bindValue($value, $generator, $type)
protected function _flattenValue($value, $generator, $type = 'string')
{
$expressions = [];
foreach ($this->_valueExpressions as $k => $v) {
$expressions[$k] = $v->sql($generator);
unset($value[$k]);
@@ -270,15 +280,37 @@ protected function _flattenValue($value, $generator, $type = 'string')
return implode(',', $parts);
}
/**
* Returns an array with the original $values in the first poisition
* and all ExpressionInterface objects that could be found in the second
* position.
*
* @param array|Traversable $values
* @return array
*/
protected function _collectExpressions($values)
{
$result = [];
if ($values instanceof ExpressionInterface) {
return [$values, []];
}
$expressions = $result = [];
$isArray = is_array($values);
if ($isArray) {
$result = $values;
}
foreach ($values as $k => $v) {
if ($v instanceof ExpressionInterface) {
$expressions[$k] = $v;
}
if ($isArray) {
$result[$k] = $v;
}
}
return $result;
return [$result, $expressions];
}
}
@@ -18,12 +18,22 @@
use Cake\Database\Type\ExpressionTypeInterface;
/**
* Offers a method to convert values to ExpressionInterface objects
* if the type they should be converted to implements ExpressionTypeInterface
*
* @internal
*/
trait TypeExpressionCasterTrait
{
/**
* Conditionally converts the passed value to an ExpressionInterface object
* if the type class implementes the ExpressionTypeInterface. Otherwise,
* returns the value unmodified.
*
* @param mixed $value The value to converto to ExpressionInterface
* @param string $type The type name
* @return mixed
*/
protected function _castToExpression($value, $type)
{
if (empty($type)) {
@@ -73,6 +73,14 @@ public function placeholder($token)
return $token;
}
/**
* Creates unique named placeholders for each of the passed values
* and binds them with the specifed type.
*
* @param array|Traversable $values The list of values to be bound
* @param string $type The type with wich all values will be bound
* @return array with the placeholders to put in the query
*/
public function generateManyNamed($values, $type = 'string')
{
$placeholders = [];

0 comments on commit a4c1222

Please sign in to comment.
You can’t perform that action at this time.