Skip to content

Commit d67eae9

Browse files
committed
Component: only UI components can be added to presenter/component (BC break) WIP
1 parent cf5f5e8 commit d67eae9

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Application/UI/Component.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,27 @@ public function getUniqueId(): string
7171
}
7272

7373

74+
public function addComponent(
75+
Nette\ComponentModel\IComponent $component,
76+
?string $name,
77+
?string $insertBefore = null,
78+
): static
79+
{
80+
if (!$component instanceof SignalReceiver && !$component instanceof StatePersistent) {
81+
throw new Nette\InvalidStateException("Component '$name' of type " . get_debug_type($component) . ' is not intended to be used in the Presenter.');
82+
}
83+
84+
return parent::addComponent($component, $name, $insertBefore = null);
85+
}
86+
87+
7488
protected function createComponent(string $name): ?Nette\ComponentModel\IComponent
7589
{
7690
if (method_exists($this, $method = 'createComponent' . $name)) {
7791
(new AccessPolicy($this, $rm = new \ReflectionMethod($this, $method)))->checkAccess();
7892
$this->checkRequirements($rm);
7993
}
80-
$res = parent::createComponent($name);
81-
if ($res && !$res instanceof SignalReceiver && !$res instanceof StatePersistent) {
82-
$type = $res::class;
83-
trigger_error("It seems that component '$name' of type $type is not intended to be used in the Presenter.");
84-
}
85-
86-
return $res;
94+
return parent::createComponent($name);
8795
}
8896

8997

0 commit comments

Comments
 (0)