diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 82adb6199..9814199a0 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -172,8 +172,14 @@ public function loadState(array $params): void } $this->$name = &$params[$name]; - } else { + } elseif ($meta['hasDefault']) { $params[$name] = &$this->$name; + } else { + throw new Nette\InvalidArgumentException(sprintf( + 'Missing parameter $%s required by %s.', + $name, + $this instanceof Presenter ? "presenter {$this->getName()}" : "component '{$this->getUniqueId()}'", + )); } } diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 0d2e2ad70..bcbd4f971 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -30,7 +30,7 @@ final class ComponentReflection extends \ReflectionClass /** * Returns array of class properties that are public and have attribute #[Persistent] or #[Parameter]. - * @return array + * @return array */ public function getParameters(): array { @@ -48,16 +48,20 @@ public function getParameters(): array self::parseAnnotation($prop, 'persistent') || $prop->getAttributes(Attributes\Persistent::class) ) { - $params[$prop->getName()] = [ - 'def' => $prop->getDefaultValue(), + $param = [ 'type' => ParameterConverter::getType($prop), 'since' => $isPresenter ? Reflection::getPropertyDeclaringClass($prop)->getName() : null, ]; } elseif ($prop->getAttributes(Attributes\Parameter::class)) { - $params[$prop->getName()] = [ + $param = [ 'type' => (string) ($prop->getType() ?? 'mixed'), ]; + } else { + continue; } + $param['def'] = $prop->getDefaultValue(); + $param['hasDefault'] = $prop->hasDefaultValue(); + $params[$prop->getName()] = $param; } if ($this->getParentClass()->isSubclassOf(Component::class)) { @@ -77,7 +81,7 @@ public function getParameters(): array /** * Returns array of persistent properties. They are public and have attribute #[Persistent]. - * @return array + * @return array */ public function getPersistentParams(): array {