Skip to content

Load object access information lazily #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Encoder/ObjectEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use VeeWee\Reflecta\Lens\Lens;
use function is_array;
use function Psl\Dict\map_with_key;
use function Psl\Fun\lazy;
use function VeeWee\Reflecta\Iso\object_data;
use function VeeWee\Xml\Writer\Builder\children as writeChildren;
use function VeeWee\Xml\Writer\Builder\raw;
Expand All @@ -42,15 +43,15 @@ public function __construct(
*/
public function iso(Context $context): Iso
{
$objectAccess = ObjectAccess::forContext($context);
$objectAccess = lazy(static fn (): ObjectAccess => ObjectAccess::forContext($context));

return new Iso(
/**
* @param TObj|array $value
* @return non-empty-string
*/
function (object|array $value) use ($context, $objectAccess) : string {
return $this->to($context, $objectAccess, $value);
return $this->to($context, $objectAccess(), $value);
},
/**
* @param non-empty-string|Element $value
Expand All @@ -59,7 +60,7 @@ function (object|array $value) use ($context, $objectAccess) : string {
function (string|Element $value) use ($context, $objectAccess) : object {
return $this->from(
$context,
$objectAccess,
$objectAccess(),
($value instanceof Element ? $value : Element::fromString($value))
);
}
Expand Down
Loading