Skip to content

Commit

Permalink
Make registries implement EventDispatcherInterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Jul 20, 2015
1 parent d5b2551 commit c123ca3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Controller/ComponentRegistry.php
Expand Up @@ -17,14 +17,15 @@
use Cake\Controller\Exception\MissingComponentException;
use Cake\Core\App;
use Cake\Core\ObjectRegistry;
use Cake\Event\EventDispatcherInterface;
use Cake\Event\EventManagerTrait;

/**
* ComponentRegistry is a registry for loaded components
*
* Handles loading, constructing and binding events for component class objects.
*/
class ComponentRegistry extends ObjectRegistry
class ComponentRegistry extends ObjectRegistry implements EventDispatcherInterface
{

use EventManagerTrait;
Expand Down
5 changes: 3 additions & 2 deletions src/Core/ObjectRegistry.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Core;

use Cake\Event\EventDispatcherInterface;
use Cake\Event\EventListenerInterface;
use RuntimeException;

Expand Down Expand Up @@ -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;
Expand All @@ -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]);
Expand Down
3 changes: 2 additions & 1 deletion src/ORM/BehaviorRegistry.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/View/HelperRegistry.php
Expand Up @@ -16,14 +16,15 @@

use Cake\Core\App;
use Cake\Core\ObjectRegistry;
use Cake\Event\EventDispatcherInterface;
use Cake\Event\EventManagerTrait;
use Cake\View\View;

/**
* 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;
Expand Down

0 comments on commit c123ca3

Please sign in to comment.