Skip to content

Commit b342351

Browse files
committed
Remove assert for keys and use get_object_vars when building LazyBSONDocument from an object
1 parent d9405fb commit b342351

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Model/LazyBSONDocument.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
use ReturnTypeWillChange;
3131

3232
use function array_key_exists;
33-
use function assert;
33+
use function get_object_vars;
3434
use function is_array;
3535
use function is_object;
36-
use function is_string;
3736
use function MongoDB\recursive_copy;
3837
use function sprintf;
3938
use function trigger_error;
@@ -84,7 +83,7 @@ public function __clone()
8483
/**
8584
* Constructs a lazy BSON document.
8685
*
87-
* @param Document<TValue>|array<TValue>|object|null $input An input for a lazy object.
86+
* @param Document<TValue>|array<string, TValue>|object|null $input An input for a lazy object.
8887
* When given a BSON document, this is treated as input. For arrays
8988
* and objects this constructs a new BSON document using fromPHP.
9089
*/
@@ -97,8 +96,11 @@ public function __construct($input = null, ?CodecLibrary $codecLibrary = null)
9796
} elseif (is_array($input) || is_object($input)) {
9897
$this->bson = Document::fromPHP([]);
9998

99+
if (is_object($input)) {
100+
$input = get_object_vars($input);
101+
}
102+
100103
foreach ($input as $key => $value) {
101-
assert(is_string($key));
102104
$this->set[$key] = $value;
103105
$this->exists[$key] = true;
104106
}

0 commit comments

Comments
 (0)