Skip to content

Commit 9c4d1fe

Browse files
Added $current_item_shape to prevent impacting a query with another. (#163)
1 parent 742dd0c commit 9c4d1fe

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/Database/Query.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ class Query extends Base {
115115
*/
116116
protected $item_shape = '\\BerlinDB\\Database\\Row';
117117

118+
/**
119+
* Name of class used to turn IDs into first-class objects for the current request.
120+
*
121+
* This is used when looping through return values to guarantee their shape.
122+
*
123+
* @var mixed
124+
*/
125+
protected $current_item_shape;
126+
118127
/** Cache *****************************************************************/
119128

120129
/**
@@ -420,6 +429,9 @@ private function set_item_shape() {
420429
if ( empty( $this->item_shape ) || ! class_exists( $this->item_shape ) ) {
421430
$this->item_shape = __NAMESPACE__ . '\\Row';
422431
}
432+
if ( empty( $this->current_item_shape ) || ! class_exists( $this->current_item_shape ) ) {
433+
$this->current_item_shape = $this->item_shape;
434+
}
423435
}
424436

425437
/**
@@ -1555,8 +1567,10 @@ private function shape_items( $items = array() ) {
15551567

15561568
// Force to stdClass if querying for fields
15571569
if ( ! empty( $this->query_vars['fields'] ) ) {
1558-
$this->item_shape = 'stdClass';
1559-
}
1570+
$this->current_item_shape = 'stdClass';
1571+
} else {
1572+
$this->current_item_shape = $this->item_shape;
1573+
}
15601574

15611575
// Default return value
15621576
$retval = array();
@@ -2071,13 +2085,13 @@ private function shape_item( $item = 0 ) {
20712085
}
20722086

20732087
// Return the item if it's already shaped
2074-
if ( $item instanceof $this->item_shape ) {
2088+
if ( $item instanceof $this->current_item_shape ) {
20752089
return $item;
20762090
}
20772091

20782092
// Shape the item as needed
2079-
$item = ! empty( $this->item_shape )
2080-
? new $this->item_shape( $item )
2093+
$item = ! empty( $this->current_item_shape )
2094+
? new $this->current_item_shape( $item )
20812095
: (object) $item;
20822096

20832097
// Return the item object

0 commit comments

Comments
 (0)