nette/component-model
Nette Component Model provides a lightweight component hierarchy for PHP apps. It supports parent/child relationships, naming, lookup, and lifecycle hooks, making it easy to build reusable UI or service components that can be composed, traversed, and managed consistently.
A focused, modern major release. The component model drops legacy baggage, demands PHP 8.3+, and ships a smarter monitoring system that finally behaves predictably when listeners reshape the tree. If you've been carrying around deprecated attached()/detached() hooks or the magic getComponents() parameters, this is your cue to clean up – the payoff is a leaner, stricter, more reliable foundation.
Monitoring handlers now fire top-down (ancestor → descendant). When a subtree is attached, monitor() listeners are invoked from the outermost ancestor inward, matching the natural order of tree construction. The new implementation is robust against listeners that mutate the tree mid-flight: it re-checks validity before descending into children, deduplicates so the same listener never runs twice, and guards against reentry to prevent infinite loops. If your code relied on the old ordering, review listeners that depend on sibling or parent state.
attached() / detached() methods removed. These long-deprecated lifecycle hooks are gone. Migrate to explicit callbacks: replace overridden attached($obj) / detached($obj) with monitor($type, attached: ..., detached: ...). Calling monitor() with no handler at all now throws an InvalidStateException – at least one of attached or detached is required.
Container::getComponents() parameters removed. The method now takes no arguments and returns a plain array of immediate children (previously iterable). The old recursive flag and filter-type argument are gone – passing them throws a DeprecatedException. For recursive traversal use getComponentTree() instead. The internal RecursiveComponentIterator has been removed.
IContainer::addComponent() signature tightened. Now declared as addComponent(IComponent $component, ?string $name): static. Implementations and callers must match the new return type hint.
Nette\SmartObject dropped from Component. The component no longer pulls in the SmartObject trait, and the magic $name, $parent, and $components properties are gone. Use the explicit methods (getName(), getParent(), getComponents()) directly.
IComponent::NAME_SEPARATOR removed. Use IComponent::NameSeparator instead.
PHP 8.3 required.
A focused, modern major release. The component model drops legacy baggage, demands PHP 8.3+, and ships a smarter monitoring system that finally behaves predictably when listeners reshape the tree. If you've been carrying around deprecated attached()/detached() hooks or the magic getComponents() parameters, this is your cue to clean up – the payoff is a leaner, stricter, more reliable foundation.
Monitoring handlers now fire top-down (ancestor → descendant). When a subtree is attached, monitor() listeners are invoked from the outermost ancestor inward, matching the natural order of tree construction. The new implementation is robust against listeners that mutate the tree mid-flight: it re-checks validity before descending into children, deduplicates so the same listener never runs twice, and guards against reentry to prevent infinite loops. If your code relied on the old ordering, review listeners that depend on sibling or parent state.
attached() / detached() methods removed. These long-deprecated lifecycle hooks are gone. Migrate to explicit callbacks: replace overridden attached($obj) / detached($obj) with monitor($type, attached: ..., detached: ...). Calling monitor() with no handler at all now throws an InvalidStateException – at least one of attached or detached is required.
Container::getComponents() parameters removed. The method now takes no arguments and returns a plain array of immediate children (previously iterable). The old recursive flag and filter-type argument are gone – passing them throws a DeprecatedException. For recursive traversal use getComponentTree() instead. The internal RecursiveComponentIterator has been removed.
IContainer::addComponent() signature tightened. Now declared as addComponent(IComponent $component, ?string $name): static. Implementations and callers must match the new return type hint.
Nette\SmartObject dropped from Component. The component no longer pulls in the SmartObject trait, and the magic $name, $parent, and $components properties are gone. Use the explicit methods (getName(), getParent(), getComponents()) directly.
IComponent::NAME_SEPARATOR removed. Use IComponent::NameSeparator instead.
PHP 8.3 required.
A transitional release ahead of 4.0. Nothing is removed yet, this version just lights up deprecation notices on things that will disappear in 4.0, so you can get your code ready in peace.
Component::$name, Component::$parent and Container::$components – use getName(), getParent(), getComponents() instead.monitor($type) without callbacks – pass them directly: monitor($type, $attached, $detached). Overriding attached() / detached() in subclasses is on its way out.IComponent::NAME_SEPARATOR – switch to IComponent::NameSeparator (the deprecation is now reported via the native #[\Deprecated] attribute).A focused maintenance release for the Component layer. The headline is hardening of the monitor callback machinery: nested re-entry is now safely guarded, callbacks are normalized to \Closure for consistent deduplication, and the whole codebase has been brought under mandatory static analysis with nette/phpstan-rules.
Component::refreshMonitors() now refuses to re-enter itself while listeners are running. If a listener removes and re-adds the same component (or otherwise triggers another refresh), each component is processed exactly once instead of looping or double-firing.=== to each other unless they are literally the same instance, so the previous strict check silently let duplicates through.nette/phpstan-rules – stricter ruleset enabled, with a dedicated tests/types/component-types.php driving type tests.support for PHP 8.5
Container::getComponentTree()Container::getComponents() parameters are silently deprecated, returns array when $deep is false (BC break)For the details you can have a look at the diff.
Container::getComponent() optimizationComponent::__construct() parameters $parent & $name are deprecatedFor the details you can have a look at the diff.
For the details you can have a look at the diff.
For the details you can have a look at the diff.
attached() is called only once for each object #2For the details you can have a look at the diff.
The first standalone release. For more information see readme.md.
How can I help you explore Laravel packages today?