Skip to content

Commit

Permalink
Make sure $object implements EventListenerInterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed May 4, 2015
1 parent 52feab2 commit 62e1e2a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Core/ObjectRegistry.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Core;

use Cake\Event\EventListenerInterface;
use RuntimeException;

/**
Expand Down Expand Up @@ -277,7 +278,7 @@ public function set($objectName, $object)
{
list(, $name) = pluginSplit($objectName);
$this->unload($objectName);
if (isset($this->_eventManager)) {
if (isset($this->_eventManager) && $object instanceof EventListenerInterface) {
$this->eventManager()->attach($object);
}
$this->_loaded[$name] = $object;
Expand All @@ -297,7 +298,7 @@ public function unload($objectName)
return;
}
$object = $this->_loaded[$objectName];
if (isset($this->_eventManager)) {
if (isset($this->_eventManager) && $object instanceof EventListenerInterface) {
$this->eventManager()->off($object);
}
unset($this->_loaded[$objectName]);
Expand Down

0 comments on commit 62e1e2a

Please sign in to comment.