Skip to content

Commit 3265f1c

Browse files
authored
Merge pull request #35 from veewee/lazy-object-access
Load object access information lazily
2 parents 356e5dd + 3d0f163 commit 3265f1c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Encoder/ObjectEncoder.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use VeeWee\Reflecta\Lens\Lens;
1818
use function is_array;
1919
use function Psl\Dict\map_with_key;
20+
use function Psl\Fun\lazy;
2021
use function VeeWee\Reflecta\Iso\object_data;
2122
use function VeeWee\Xml\Writer\Builder\children as writeChildren;
2223
use function VeeWee\Xml\Writer\Builder\raw;
@@ -42,15 +43,15 @@ public function __construct(
4243
*/
4344
public function iso(Context $context): Iso
4445
{
45-
$objectAccess = ObjectAccess::forContext($context);
46+
$objectAccess = lazy(static fn (): ObjectAccess => ObjectAccess::forContext($context));
4647

4748
return new Iso(
4849
/**
4950
* @param TObj|array $value
5051
* @return non-empty-string
5152
*/
5253
function (object|array $value) use ($context, $objectAccess) : string {
53-
return $this->to($context, $objectAccess, $value);
54+
return $this->to($context, $objectAccess(), $value);
5455
},
5556
/**
5657
* @param non-empty-string|Element $value
@@ -59,7 +60,7 @@ function (object|array $value) use ($context, $objectAccess) : string {
5960
function (string|Element $value) use ($context, $objectAccess) : object {
6061
return $this->from(
6162
$context,
62-
$objectAccess,
63+
$objectAccess(),
6364
($value instanceof Element ? $value : Element::fromString($value))
6465
);
6566
}

0 commit comments

Comments
 (0)