Skip to content

Commit 52ec806

Browse files
committed
[TwigComponent] Throws if some exposed public props are uninitialized
1 parent ba75b9f commit 52ec806

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)