Skip to content

Commit 73f3d8a

Browse files
authored
use resultsetinterface instead of resultset for serializing collections (#115)
1 parent b8342d4 commit 73f3d8a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

plugins/hal-view/src/JsonSerializer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
use Cake\Collection\CollectionInterface;
77
use Cake\Datasource\EntityInterface;
8+
use Cake\Datasource\ResultSetInterface;
89
use Cake\Http\ServerRequest;
910
use Cake\ORM\Entity;
10-
use Cake\ORM\ResultSet;
1111
use Cake\Utility\Inflector;
1212
use Cake\View\Helper\PaginatorHelper;
1313
use MixerApi\Core\View\SerializableAssociation;
@@ -45,7 +45,7 @@ public function __construct(mixed $serialize, ?ServerRequest $request = null, ?P
4545

4646
$hal = $this->recursion($serialize);
4747

48-
if ($hal instanceof ResultSet) {
48+
if ($hal instanceof ResultSetInterface) {
4949
$this->data = $this->collection($hal);
5050
} elseif (is_subclass_of($hal, Entity::class)) {
5151
$this->data = $this->item($hal);
@@ -87,20 +87,20 @@ public function getData(): ?array
8787
* HAL resources, but does not serialize the data.
8888
*
8989
* @param mixed $mixed data to be serialized
90-
* @return array|\Cake\Datasource\EntityInterface|\Cake\ORM\ResultSet
90+
* @return array|\Cake\Datasource\EntityInterface|\Cake\Datasource\ResultSetInterface
9191
*/
9292
private function recursion(mixed &$mixed): mixed
9393
{
94-
if ($mixed instanceof ResultSet || is_array($mixed)) {
95-
foreach ($mixed as $x => $item) {
94+
if ($mixed instanceof ResultSetInterface || is_array($mixed)) {
95+
foreach ($mixed as $item) {
9696
$this->recursion($item);
9797
}
9898
} elseif ($mixed instanceof EntityInterface) {
9999
$serializableAssociation = new SerializableAssociation($mixed);
100100

101101
$mixed = $this->resource($mixed, $serializableAssociation);
102102

103-
foreach ($serializableAssociation->getAssociations() as $property => $value) {
103+
foreach ($serializableAssociation->getAssociations() as $value) {
104104
$this->recursion($value);
105105
}
106106
}

plugins/json-ld-view/src/JsonSerializer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
use Cake\Core\Configure;
77
use Cake\Datasource\EntityInterface;
8+
use Cake\Datasource\ResultSetInterface;
89
use Cake\Http\ServerRequest;
910
use Cake\ORM\Entity;
10-
use Cake\ORM\ResultSet;
1111
use Cake\View\Helper\PaginatorHelper;
1212
use MixerApi\Core\View\SerializableAssociation;
1313
use ReflectionException;
@@ -63,7 +63,7 @@ public function __construct(mixed $serialize, ?ServerRequest $request = null, ?P
6363
$this->hydra = 'hydra:';
6464
}
6565

66-
if ($jsonLd instanceof ResultSet) {
66+
if ($jsonLd instanceof ResultSetInterface) {
6767
$this->data = $this->collection($jsonLd);
6868
} elseif (is_subclass_of($jsonLd, Entity::class)) {
6969
$this->data = $this->item($jsonLd);
@@ -105,20 +105,20 @@ public function getData(): ?array
105105
* JSON-LD resources, but does not serialize the data.
106106
*
107107
* @param mixed $mixed data to be serialized
108-
* @return array|\Cake\Datasource\EntityInterface|\Cake\ORM\ResultSet
108+
* @return array|\Cake\Datasource\EntityInterface|\Cake\Datasource\ResultSetInterface
109109
*/
110110
private function recursion(mixed &$mixed): mixed
111111
{
112-
if ($mixed instanceof ResultSet || is_array($mixed)) {
113-
foreach ($mixed as $x => $item) {
112+
if ($mixed instanceof ResultSetInterface || is_array($mixed)) {
113+
foreach ($mixed as $item) {
114114
$this->recursion($item);
115115
}
116116
} elseif ($mixed instanceof EntityInterface) {
117117
$serializableAssocation = new SerializableAssociation($mixed);
118118

119119
$mixed = $this->resource($mixed, $serializableAssocation);
120120

121-
foreach ($serializableAssocation->getAssociations() as $property => $value) {
121+
foreach ($serializableAssocation->getAssociations() as $value) {
122122
$this->recursion($value);
123123
}
124124
}

0 commit comments

Comments
 (0)