diff --git a/src/Query/Query.php b/src/Query/Query.php index d3de8bf..6ff9744 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -35,11 +35,21 @@ abstract public function execute(array $bindings = []):ResultSet; * key-value-pair bindings may be double or triple nested at this point. */ protected function flattenBindings(array $bindings):array { - if(!isset($bindings[0]) - || !is_array($bindings[0])) { + if(!isset($bindings[0])) { return $bindings; } + if(is_object($bindings[0]) + && method_exists($bindings[0], "toArray")) { + $bindings = array_map(function($element) { + if(method_exists($element, "toArray")) { + return $element->toArray(); + } + + return $element; + }, $bindings); + } + $flatArray = []; foreach($bindings as $i => $b) { while(isset($b[0]) @@ -55,6 +65,10 @@ protected function flattenBindings(array $bindings):array { $b = $merged; } + if(!is_array($b)) { + $b = [$b]; + } + $flatArray = array_merge($flatArray, $b); } diff --git a/src/Result/Row.php b/src/Result/Row.php index 01d1435..52a66bc 100644 --- a/src/Result/Row.php +++ b/src/Result/Row.php @@ -14,6 +14,10 @@ public function __construct(array $data = []) { $this->setProperties($data); } + public function toArray():array { + return $this->data; + } + public function __get($name) { if(!isset($this->$name)) { throw new NoSuchColumnException($name);