Skip to content

Commit 8e5351c

Browse files
committed
add mongodb tests [18]
1 parent 79540f5 commit 8e5351c

File tree

5 files changed

+145
-179
lines changed

5 files changed

+145
-179
lines changed

examples/remote-object/c2.php

Lines changed: 0 additions & 149 deletions
This file was deleted.

examples/remote-object/c3.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/core/RemoteObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ public static function create(Client $client, string $class, array $args): Remot
153153
/**
154154
* This method is only used on the server side.
155155
*/
156-
public static function serialize(int $objectId, int $ownerCoroutineId, string $clientId): string
156+
public static function marshal(int $objectId, int $ownerCoroutineId, string $clientId): RemoteObject
157157
{
158158
$object = new self($ownerCoroutineId, $clientId);
159159
$object->objectId = $objectId;
160-
return serialize($object);
160+
return $object;
161161
}
162162

163163
public function offsetGet(mixed $offset): mixed

src/core/RemoteObject/Server.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ private function addObject($object): int
107107
return $object_id;
108108
}
109109

110-
private function marshal(Context $ctx, mixed $data): string
110+
private function marshal(Context $ctx, mixed $data): mixed
111111
{
112112
if (is_object($data) or is_resource($data)) {
113113
$object_id = $this->addObject($data);
114-
return RemoteObject::serialize($object_id, $ctx->getCoroutineId(), $ctx->getClientId());
114+
return RemoteObject::marshal($object_id, $ctx->getCoroutineId(), $ctx->getClientId());
115115
}
116116
if (is_array($data)) {
117117
foreach ($data as $key => $value) {
118118
$data[$key] = $this->marshal($ctx, $value);
119119
}
120120
}
121-
return serialize($data);
121+
return $data;
122122
}
123123

124124
private function unmarshal($data): mixed
@@ -169,7 +169,7 @@ private function _call_function(Context $ctx): void
169169
throw new Exception("function[{$fn}] not found");
170170
}
171171
$result = $fn(...$args);
172-
$ctx->end(['code' => 0, 'result' => $this->marshal($ctx, $result)]);
172+
$ctx->end(['code' => 0, 'result' => serialize($this->marshal($ctx, $result))]);
173173
}
174174

175175
/**
@@ -192,7 +192,7 @@ private function _call_method(Context $ctx): void
192192
throw new Exception("method[{$class}::{$method}] not found");
193193
}
194194
$result = $obj->{$method}(...$args);
195-
$ctx->end(['code' => 0, 'result' => $this->marshal($ctx, $result)]);
195+
$ctx->end(['code' => 0, 'result' => serialize($this->marshal($ctx, $result))]);
196196
}
197197

198198
/**
@@ -207,7 +207,7 @@ private function _read_property(Context $ctx): void
207207
}
208208
$obj = $this->objects[$object_id];
209209
$result = $obj->{$property};
210-
$ctx->end(['code' => 0, 'property' => $this->marshal($ctx, $result)]);
210+
$ctx->end(['code' => 0, 'property' => serialize($this->marshal($ctx, $result))]);
211211
}
212212

213213
/**
@@ -258,7 +258,7 @@ private function _offset_get(Context $ctx): void
258258
}
259259
$obj = $this->objects[$object_id];
260260
$result = $obj->{$offset};
261-
$ctx->end(['code' => 0, 'value' => $this->marshal($ctx, $result)]);
261+
$ctx->end(['code' => 0, 'value' => serialize($this->marshal($ctx, $result))]);
262262
}
263263

264264
private function _offset_set(Context $ctx): void
@@ -295,6 +295,6 @@ private function _offset_exists(Context $ctx): void
295295
}
296296
$obj = $this->objects[$object_id];
297297
$result = isset($obj->{$offset});
298-
$ctx->end(['code' => 0, 'value' => $this->marshal($ctx, $result)]);
298+
$ctx->end(['code' => 0, 'value' => serialize($this->marshal($ctx, $result))]);
299299
}
300300
}

0 commit comments

Comments
 (0)