-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return toArray value only for traversable which are not iterator
Signed-off-by: Gary Gitton <[email protected]>
- Loading branch information
1 parent
6422838
commit 2d3358f
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
namespace Laminas\Stdlib; | ||
|
||
use Iterator; | ||
use Laminas\Stdlib\ArrayUtils\MergeRemoveKey; | ||
use Laminas\Stdlib\ArrayUtils\MergeReplaceKeyInterface; | ||
use Traversable; | ||
|
@@ -240,7 +241,11 @@ public static function iteratorToArray($iterator, $recursive = true) | |
return iterator_to_array($iterator); | ||
} | ||
|
||
if (is_object($iterator) && method_exists($iterator, 'toArray')) { | ||
if ( | ||
is_object($iterator) | ||
&& ! $iterator instanceof Iterator | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Ocramius
Member
|
||
&& method_exists($iterator, 'toArray') | ||
) { | ||
return $iterator->toArray(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\Stdlib\TestAsset; | ||
|
||
use Iterator; | ||
use ReturnTypeWillChange; | ||
|
||
use function current; | ||
use function is_array; | ||
use function key; | ||
use function next; | ||
use function reset; | ||
|
||
class IteratorWithToArrayMethod implements Iterator | ||
{ | ||
private array $elements = []; | ||
|
||
public function __construct(array $elements) | ||
{ | ||
if (is_array($elements)) { | ||
$this->elements = $elements; | ||
} | ||
} | ||
|
||
/** @return void */ | ||
#[ReturnTypeWillChange] | ||
public function rewind() | ||
{ | ||
reset($this->elements); | ||
} | ||
|
||
/** @return mixed */ | ||
#[ReturnTypeWillChange] | ||
public function current() | ||
{ | ||
return current($this->elements); | ||
} | ||
|
||
/** @return int|string */ | ||
#[ReturnTypeWillChange] | ||
public function key() | ||
{ | ||
return key($this->elements); | ||
} | ||
|
||
/** @return mixed */ | ||
#[ReturnTypeWillChange] | ||
public function next() | ||
{ | ||
return next($this->elements); | ||
} | ||
|
||
/** @return bool */ | ||
#[ReturnTypeWillChange] | ||
public function valid() | ||
{ | ||
$key = key($this->elements); | ||
return $key !== null && $key !== false; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'data from to array' => 'not good', | ||
]; | ||
} | ||
} |
Hi,
in my projext i've a JsonModel whith an entry of type HydratingResultSet. When JSON serialize for response the array is empty. before this update i've the json data filled from HydratingResultSet.
can you help me can i solve?
thans