Skip to content
Permalink
Browse files

Implmented ValueBinder::generateMany() as a way to reduce funcitons c…

…alls

Also calling bindValue() directly instead of the bind() proxy for the same
reaason.
  • Loading branch information...
lorenzo committed Mar 21, 2016
1 parent 98a5267 commit adce2893850d5e6b33d82635e26096bcdddfbc42
@@ -84,7 +84,7 @@ public function __construct($field, $value, $type, $operator)
*/
public function setValue($value)
{
$hasType = isset($this->_type);
$hasType = isset($this->_type) && is_string($this->_type);
$isMultiple = $hasType && strpos($this->_type, '[]') !== false;
if ($hasType) {
@@ -170,11 +170,9 @@ public function traverse(callable $callable)
$this->_value->traverse($callable);
}
if (!empty($this->_valueExpressions)) {
foreach ($this->_valueExpressions as $v) {
$callable($v);
$v->traverse($callable);
}
foreach ($this->_valueExpressions as $v) {
$callable($v);
$v->traverse($callable);
}
}
@@ -254,15 +252,19 @@ protected function _bindValue($value, $generator, $type)
* @param string|array|null $type the type to cast values to
* @return string
*/
protected function _flattenValue($value, $generator, $type = null)
protected function _flattenValue($value, $generator, $type = 'string')
{
$parts = [];
foreach ($value as $k => $v) {
if (isset($this->_valueExpressions[$k])) {
$parts[] = $this->_valueExpressions[$k]->sql($generator);
continue;
}
$parts[] = $this->_bindValue($v, $generator, $type);
$expressions = [];
foreach ($this->_valueExpressions as $k => $v) {
$expressions[$k] = $v->sql($generator);
unset($value[$k]);
}
$parts = $expressions;
if (!empty($value)) {
$parts += $generator->generateManyNamed($value, $type);
}
return implode(',', $parts);
@@ -73,6 +73,23 @@ public function placeholder($token)
return $token;
}
public function generateManyNamed($values, $type = 'string')
{
$placeholders = [];
foreach ($values as $k => $value) {
$param = ":c" . $this->_bindingsCount;
$this->_bindings[$param] = [
'value' => $value,
'type' => $type,
'placeholder' => $param
];
$placeholders[$k] = $param;
$this->_bindingsCount++;
}
return $placeholders;
}
/**
* Returns all values bound to this expression object at this nesting level.
* Subexpression bound values will not be returned with this function.
@@ -119,9 +136,7 @@ public function attachTo($statement)
}
$params = $types = [];
foreach ($bindings as $b) {
$params[$b['placeholder']] = $b['value'];
$types[$b['placeholder']] = $b['type'];
$statement->bindValue($b['placeholder'], $b['value'], $b['type']);
}
$statement->bind($params, $types);
}
}
@@ -35,7 +35,7 @@ public function toExpression($value)
* using the type classes
*
*/
class FunctionsBuilderTest extends TestCase
class ExpressionTypeCastingTest extends TestCase
{
/**

0 comments on commit adce289

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