From 8182346659b8b6f52f351cdbf227d94b9e3d668f Mon Sep 17 00:00:00 2001 From: Evan Coury Date: Fri, 4 Nov 2011 09:05:05 -0700 Subject: [PATCH] Add Zend\EventManager\ProvidesEvents trait - Cannot use in core until 3.0 - Comments added to classes that could use it --- library/Zend/EventManager/ProvidesEvents.php | 79 +++++++++++++++++++ .../Zend/Mvc/Controller/ActionController.php | 2 + .../library/Zend/Application/Application.php | 2 + 3 files changed, 83 insertions(+) create mode 100644 library/Zend/EventManager/ProvidesEvents.php diff --git a/library/Zend/EventManager/ProvidesEvents.php b/library/Zend/EventManager/ProvidesEvents.php new file mode 100644 index 00000000000..2ca8cc5a3d8 --- /dev/null +++ b/library/Zend/EventManager/ProvidesEvents.php @@ -0,0 +1,79 @@ +events = $events; + return $this; + } + + /** + * Retrieve the event manager + * + * Lazy-loads an EventManager instance if none registered. + * + * @return EventCollection + */ + public function events() + { + if (!$this->events instanceof EventCollection) { + $identifiers = array(__CLASS__, get_class($this)); + if (isset($this->eventIdentifier)) { + if ((is_string($this->eventIdentifier)) + || (is_array($this->eventIdentifier)) + || ($this->eventIdentifier instanceof Traversable) + ) { + $identifiers = array_unique($identifiers + (array) $this->eventIdentifier); + } + // silently ignore invalid eventIdentifier types + } + $this->setEventManager(new EventManager($identifiers)); + } + return $this->events; + } +} diff --git a/library/Zend/Mvc/Controller/ActionController.php b/library/Zend/Mvc/Controller/ActionController.php index a60fd7378a5..c127c09b9ae 100644 --- a/library/Zend/Mvc/Controller/ActionController.php +++ b/library/Zend/Mvc/Controller/ActionController.php @@ -23,6 +23,8 @@ */ abstract class ActionController implements Dispatchable, InjectApplicationEvent, LocatorAware, Pluggable { + //use \Zend\EventManager\ProvidesEvents; + protected $broker; protected $event; protected $events; diff --git a/modules/ZendFramework1Mvc/library/Zend/Application/Application.php b/modules/ZendFramework1Mvc/library/Zend/Application/Application.php index cc357ff09e1..8b7ceddca6d 100644 --- a/modules/ZendFramework1Mvc/library/Zend/Application/Application.php +++ b/modules/ZendFramework1Mvc/library/Zend/Application/Application.php @@ -37,6 +37,8 @@ */ class Application { + //use \Zend\EventManager\ProvidesEvents; + /** * Autoloader to use *