Skip to content

Commit a1c74e4

Browse files
committed
minor #1780 [TwigComponent] Throws if exposed public prop is uninitialized (smnandre)
This PR was merged into the 2.x branch. Discussion ---------- [TwigComponent] Throws if exposed public prop is uninitialized Fix #1686, fix ~~#1704~~ Commits ------- 52ec806 [TwigComponent] Throws if some exposed public props are uninitialized
2 parents 3a2937e + 52ec806 commit a1c74e4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/TwigComponent/src/ComponentRenderer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ private function preRender(MountedComponent $mounted, array $context = []): PreR
141141
private function exposedVariables(object $component, bool $exposePublicProps): \Iterator
142142
{
143143
if ($exposePublicProps) {
144-
yield from get_object_vars($component);
144+
$publicProps = get_object_vars($component);
145+
if ($uninitializedProps = array_diff_key(get_class_vars($component::class), $publicProps)) {
146+
throw new \LogicException(sprintf('Cannot expose uninitialized property "$%s" from "%s".', array_keys($uninitializedProps)[0], $component::class));
147+
}
148+
yield from $publicProps;
145149
}
146150

147151
$class = new \ReflectionClass($component);

0 commit comments

Comments
 (0)