diff --git a/src/Controller/ComponentRegistry.php b/src/Controller/ComponentRegistry.php index df97edc9408..2c1c13a7d21 100644 --- a/src/Controller/ComponentRegistry.php +++ b/src/Controller/ComponentRegistry.php @@ -17,6 +17,7 @@ use Cake\Controller\Exception\MissingComponentException; use Cake\Core\App; use Cake\Core\ObjectRegistry; +use Cake\Event\EventDispatcherInterface; use Cake\Event\EventManagerTrait; /** @@ -24,7 +25,7 @@ * * Handles loading, constructing and binding events for component class objects. */ -class ComponentRegistry extends ObjectRegistry +class ComponentRegistry extends ObjectRegistry implements EventDispatcherInterface { use EventManagerTrait; diff --git a/src/Core/ObjectRegistry.php b/src/Core/ObjectRegistry.php index 0a6dc625514..dc0a686a08f 100644 --- a/src/Core/ObjectRegistry.php +++ b/src/Core/ObjectRegistry.php @@ -14,6 +14,7 @@ */ namespace Cake\Core; +use Cake\Event\EventDispatcherInterface; use Cake\Event\EventListenerInterface; use RuntimeException; @@ -281,7 +282,7 @@ public function set($objectName, $object) { list(, $name) = pluginSplit($objectName); $this->unload($objectName); - if (isset($this->_eventManager) && $object instanceof EventListenerInterface) { + if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) { $this->eventManager()->on($object); } $this->_loaded[$name] = $object; @@ -301,7 +302,7 @@ public function unload($objectName) return; } $object = $this->_loaded[$objectName]; - if (isset($this->_eventManager) && $object instanceof EventListenerInterface) { + if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) { $this->eventManager()->off($object); } unset($this->_loaded[$objectName]); diff --git a/src/ORM/BehaviorRegistry.php b/src/ORM/BehaviorRegistry.php index 46876a56821..7e092aa8f20 100644 --- a/src/ORM/BehaviorRegistry.php +++ b/src/ORM/BehaviorRegistry.php @@ -17,6 +17,7 @@ use BadMethodCallException; use Cake\Core\App; use Cake\Core\ObjectRegistry; +use Cake\Event\EventDispatcherInterface; use Cake\Event\EventManagerTrait; use Cake\ORM\Behavior; use Cake\ORM\Exception\MissingBehaviorException; @@ -29,7 +30,7 @@ * * This class also provides method for checking and dispatching behavior methods. */ -class BehaviorRegistry extends ObjectRegistry +class BehaviorRegistry extends ObjectRegistry implements EventDispatcherInterface { use EventManagerTrait; diff --git a/src/View/HelperRegistry.php b/src/View/HelperRegistry.php index 7729839a78c..50cf625289e 100644 --- a/src/View/HelperRegistry.php +++ b/src/View/HelperRegistry.php @@ -16,6 +16,7 @@ use Cake\Core\App; use Cake\Core\ObjectRegistry; +use Cake\Event\EventDispatcherInterface; use Cake\Event\EventManagerTrait; use Cake\View\View; @@ -23,7 +24,7 @@ * HelperRegistry is used as a registry for loaded helpers and handles loading * and constructing helper class objects. */ -class HelperRegistry extends ObjectRegistry +class HelperRegistry extends ObjectRegistry implements EventDispatcherInterface { use EventManagerTrait;