Skip to content

Commit 20cbfa9

Browse files
committed
Component: only UI components can be added to presenter/component (BC break) WIP
1 parent 7b4e1f7 commit 20cbfa9

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
@@ -72,19 +72,27 @@ public function getUniqueId(): string
7272
}
7373

7474

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

9098

0 commit comments

Comments
 (0)