Skip to content

Commit

Permalink
Added $current_item_shape to prevent impacting a query with another. (b…
Browse files Browse the repository at this point in the history
  • Loading branch information
CrochetFeve0251 authored Nov 12, 2023
1 parent 742dd0c commit 9c4d1fe
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ class Query extends Base {
*/
protected $item_shape = '\\BerlinDB\\Database\\Row';

/**
* Name of class used to turn IDs into first-class objects for the current request.
*
* This is used when looping through return values to guarantee their shape.
*
* @var mixed
*/
protected $current_item_shape;

/** Cache *****************************************************************/

/**
Expand Down Expand Up @@ -420,6 +429,9 @@ private function set_item_shape() {
if ( empty( $this->item_shape ) || ! class_exists( $this->item_shape ) ) {
$this->item_shape = __NAMESPACE__ . '\\Row';
}
if ( empty( $this->current_item_shape ) || ! class_exists( $this->current_item_shape ) ) {
$this->current_item_shape = $this->item_shape;
}
}

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

// Force to stdClass if querying for fields
if ( ! empty( $this->query_vars['fields'] ) ) {
$this->item_shape = 'stdClass';
}
$this->current_item_shape = 'stdClass';
} else {
$this->current_item_shape = $this->item_shape;
}

// Default return value
$retval = array();
Expand Down Expand Up @@ -2071,13 +2085,13 @@ private function shape_item( $item = 0 ) {
}

// Return the item if it's already shaped
if ( $item instanceof $this->item_shape ) {
if ( $item instanceof $this->current_item_shape ) {
return $item;
}

// Shape the item as needed
$item = ! empty( $this->item_shape )
? new $this->item_shape( $item )
$item = ! empty( $this->current_item_shape )
? new $this->current_item_shape( $item )
: (object) $item;

// Return the item object
Expand Down

0 comments on commit 9c4d1fe

Please sign in to comment.