Skip to content

Commit

Permalink
WebEngine specific handling of array-like objects
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed May 27, 2018
1 parent 862fa16 commit 3dfb6a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -55,6 +65,10 @@ protected function flattenBindings(array $bindings):array {
$b = $merged;
}

if(!is_array($b)) {
$b = [$b];
}

$flatArray = array_merge($flatArray, $b);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Result/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3dfb6a4

Please sign in to comment.