Commit
resolves a potential issue that was made evident on cyclic references not being able to be traversed
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,12 @@ public function traverse(callable $visitor) { | |
if (!$this->_hasQuery) { | ||
return; | ||
} | ||
|
||
foreach ($this->_values as $v) { | ||
if ($v instanceof ExpressionInterface) { | ||
$v->traverse($visitor); | ||
} | ||
} | ||
$this->_values[0]->traverse($visitor); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lorenzo
Author
Member
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,10 +240,10 @@ public function sql($transform = true) { | |
* }); | ||
* }}} | ||
* | ||
* @param callback $visitor a function or callable to be executed for each part | ||
* @param callable $visitor a function or callable to be executed for each part | ||
* @return Query | ||
*/ | ||
public function traverse($visitor) { | ||
public function traverse(callable $visitor) { | ||
$this->{'_traverse' . ucfirst($this->_type)}($visitor); | ||
return $this; | ||
} | ||
|
@@ -1449,24 +1449,28 @@ protected function _bindParams($statement) { | |
$statement->bind($params, $types); | ||
}; | ||
|
||
$binder = function($expression, $name) use ($statement, $visitor, &$binder) { | ||
$refs = []; | ||
$binder = function($expression, $name = null) use ($statement, $visitor, &$binder, &$refs) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lorenzo
Author
Member
|
||
if (is_array($expression)) { | ||
foreach ($expression as $e) { | ||
$binder($e, $name); | ||
} | ||
return; | ||
} | ||
|
||
if ($expression instanceof self) { | ||
return $expression->traverse($binder); | ||
} | ||
if ($expression instanceof ExpressionInterface) { | ||
$id = spl_object_hash($expression); | ||
|
||
if ($expression instanceof QueryExpression) { | ||
// Visit all expressions and subexpressions to get every bound value | ||
$expression->traverse($visitor); | ||
} | ||
if ($expression instanceof ValuesExpression) { | ||
if (isset($refs[$id])) { | ||
return; | ||
} | ||
|
||
$refs[$id] = 1; | ||
$expression->traverse($binder); | ||
$visitor($expression); | ||
|
||
if (!($expression instanceof self)) { | ||
$visitor($expression); | ||
} | ||
} | ||
}; | ||
|
||
|
This will double traverse the 0'th index.