1717 * Base class for all components. Components have a parent, name, and can be monitored by ancestors.
1818 *
1919 * @property-read string $name
20- * @property-read IContainer|null $parent
20+ * @property-read ? IContainer $parent
2121 */
2222abstract class Component implements IComponent
2323{
@@ -31,7 +31,7 @@ abstract class Component implements IComponent
3131 * Combines cached lookup results with callback registrations for each monitored type.
3232 * Depth is used to detect when monitored ancestor becomes unreachable during detachment.
3333 * Structure: [type => [found object, depth to object, path to object, [[attached, ...], [detached, ...]]]]
34- * @var array<string, array{?IComponent, ?int, ?string, array<int, ?array{\Closure[], \Closure[]}> }>
34+ * @var array<''|class- string<Nette\ComponentModel\IComponent> , array{?IComponent, ?int, ?string, ?array{list< \Closure(IComponent): void>, list< \Closure(IComponent): void>} }>
3535 */
3636 private array $ monitors = [];
3737
@@ -41,8 +41,10 @@ abstract class Component implements IComponent
4141
4242 /**
4343 * Finds the closest ancestor of specified type.
44- * @param bool $throw throw exception if component doesn't exist?
45- * @return ($throw is true ? IComponent : ?IComponent)
44+ * @template T of IComponent
45+ * @param ?class-string<T> $type
46+ * @param bool $throw throw exception if component doesn't exist?
47+ * @return ($type is null ? ($throw is true ? IComponent : ?IComponent) : ($throw is true ? T : ?T))
4648 */
4749 final public function lookup (?string $ type , bool $ throw = true ): ?IComponent
4850 {
@@ -81,7 +83,9 @@ final public function lookup(?string $type, bool $throw = true): ?IComponent
8183
8284 /**
8385 * Finds the closest ancestor specified by class or interface name and returns backtrace path.
84- * A path is the concatenation of component names separated by self::NAME_SEPARATOR.
86+ * A path is the concatenation of component names separated by self::NameSeparator.
87+ * @param ?class-string<IComponent> $type
88+ * @param bool $throw throw exception if component doesn't exist?
8589 * @return ($throw is true ? string : ?string)
8690 */
8791 final public function lookupPath (?string $ type = null , bool $ throw = true ): ?string
@@ -93,6 +97,10 @@ final public function lookupPath(?string $type = null, bool $throw = true): ?str
9397
9498 /**
9599 * Starts monitoring ancestors for attach/detach events.
100+ * @template T of IComponent
101+ * @param class-string<T> $type
102+ * @param ?(callable(T): void) $attached called when attached to a monitored ancestor
103+ * @param ?(callable(T): void) $detached called before detaching from a monitored ancestor
96104 */
97105 final public function monitor (string $ type , ?callable $ attached = null , ?callable $ detached = null ): void
98106 {
@@ -119,6 +127,7 @@ final public function monitor(string $type, ?callable $attached = null, ?callabl
119127
120128 /**
121129 * Stops monitoring ancestors of specified type.
130+ * @param class-string<IComponent> $type
122131 */
123132 final public function unmonitor (string $ type ): void
124133 {
@@ -218,7 +227,7 @@ protected function validateParent(IContainer $parent): void
218227 /**
219228 * Refreshes monitors when attaching/detaching from component tree.
220229 * @param ?array<string, true> $missing null = detaching, array = attaching
221- * @param array<int, array{\Closure, IComponent}> $listeners
230+ * @param array<int, array{\Closure(IComponent): void , IComponent}> $listeners
222231 */
223232 private function refreshMonitors (int $ depth , ?array &$ missing = null , array &$ listeners = []): void
224233 {
0 commit comments