diff --git a/composer.json b/composer.json index 9c41d38..3acdd91 100644 --- a/composer.json +++ b/composer.json @@ -6,22 +6,22 @@ "zf2", "eventmanager" ], + "homepage": "https://github.com/zendframework/zend-event-manager", "autoload": { "psr-4": { "Zend\\EventManager\\": "src/" } }, "require": { - "php": ">=5.3.3", + "php": ">=5.3.23", "zendframework/zend-stdlib": "self.version" }, "extra": { "branch-alias": { - "dev-master": "2.2-dev", - "dev-develop": "2.3-dev" + "dev-master": "2.3-dev", + "dev-develop": "2.4-dev" } }, - "homepage": "https://github.com/zendframework/zend-event-manager", "autoload-dev": { "psr-4": { "ZendTest\\EventManager\\": "test/" diff --git a/src/EventManagerAwareTrait.php b/src/EventManagerAwareTrait.php index faa8244..31e47a4 100644 --- a/src/EventManagerAwareTrait.php +++ b/src/EventManagerAwareTrait.php @@ -9,8 +9,69 @@ namespace Zend\EventManager; +use Traversable; +/** + * A trait for objects that provide events. + * + * If you use this trait in an object, you will probably want to also implement + * EventManagerAwareInterface, which will make it so the default initializer in + * a ZF2 MVC application will automatically inject an instance of the + * EventManager into your object when it is pulled from the ServiceManager. + * + * @see Zend\Mvc\Service\ServiceManagerConfig + */ trait EventManagerAwareTrait { - use ProvidesEvents; + /** + * @var EventManagerInterface + */ + protected $events; + + /** + * Set the event manager instance used by this context. + * + * For convenience, this method will also set the class name / LSB name as + * identifiers, in addition to any string or array of strings set to the + * $this->eventIdentifier property. + * + * @param EventManagerInterface $events + * @return mixed + */ + public function setEventManager(EventManagerInterface $events) + { + $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(array_merge($identifiers, (array) $this->eventIdentifier)); + } elseif (is_object($this->eventIdentifier)) { + $identifiers[] = $this->eventIdentifier; + } + // silently ignore invalid eventIdentifier types + } + $events->setIdentifiers($identifiers); + $this->events = $events; + if (method_exists($this, 'attachDefaultListeners')) { + $this->attachDefaultListeners(); + } + return $this; + } + + /** + * Retrieve the event manager + * + * Lazy-loads an EventManager instance if none registered. + * + * @return EventManagerInterface + */ + public function getEventManager() + { + if (!$this->events instanceof EventManagerInterface) { + $this->setEventManager(new EventManager()); + } + return $this->events; + } } diff --git a/src/ProvidesEvents.php b/src/ProvidesEvents.php index 0da7a0b..0cfeb19 100644 --- a/src/ProvidesEvents.php +++ b/src/ProvidesEvents.php @@ -9,55 +9,15 @@ namespace Zend\EventManager; -use Traversable; +trigger_error('Zend\EventManager\ProvidesEvents has been deprecated in favor of Zend\EventManager\EventManagerAwareTrait; please update your code', E_USER_DEPRECATED); /** - * A trait for objects that provide events + * @deprecated Please use EventManagerAwareTrait instead. + * + * This trait exists solely for backwards compatibility in the 2.x branch and + * will likely be removed in 3.x. */ trait ProvidesEvents { - /** - * @var EventManagerInterface - */ - protected $events; - - /** - * Set the event manager instance used by this context - * - * @param EventManagerInterface $events - * @return mixed - */ - public function setEventManager(EventManagerInterface $events) - { - $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(array_merge($identifiers, (array) $this->eventIdentifier)); - } elseif (is_object($this->eventIdentifier)) { - $identifiers[] = $this->eventIdentifier; - } - // silently ignore invalid eventIdentifier types - } - $events->setIdentifiers($identifiers); - $this->events = $events; - return $this; - } - - /** - * Retrieve the event manager - * - * Lazy-loads an EventManager instance if none registered. - * - * @return EventManagerInterface - */ - public function getEventManager() - { - if (!$this->events instanceof EventManagerInterface) { - $this->setEventManager(new EventManager()); - } - return $this->events; - } + use EventManagerAwareTrait; } diff --git a/src/SharedEventManager.php b/src/SharedEventManager.php index c673b38..0542431 100644 --- a/src/SharedEventManager.php +++ b/src/SharedEventManager.php @@ -109,7 +109,7 @@ public function detach($id, CallbackHandler $listener) /** * Detach a listener aggregate * - * Listener aggregates accept an SharedEventManagerInterface instance, and call detachShared() + * Listener aggregates accept a SharedEventManagerInterface instance, and call detachShared() * of all previously attached listeners. * * @param SharedListenerAggregateInterface $aggregate diff --git a/src/SharedListenerAggregateInterface.php b/src/SharedListenerAggregateInterface.php index 2c997db..0c592f7 100644 --- a/src/SharedListenerAggregateInterface.php +++ b/src/SharedListenerAggregateInterface.php @@ -13,7 +13,7 @@ * Interface for self-registering event listeners. * * Classes implementing this interface may be registered by name or instance - * with an SharedEventManager, without an event name. The {@link attach()} method will + * with a SharedEventManager, without an event name. The {@link attach()} method will * then be called with the current SharedEventManager instance, allowing the class to * wire up one or more listeners. */ diff --git a/test/AbstractListenerAggregateTest.php b/test/AbstractListenerAggregateTest.php index 9b40652..02262de 100644 --- a/test/AbstractListenerAggregateTest.php +++ b/test/AbstractListenerAggregateTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/EventManagerAwareTraitTest.php b/test/EventManagerAwareTraitTest.php index b282164..78d9005 100644 --- a/test/EventManagerAwareTraitTest.php +++ b/test/EventManagerAwareTraitTest.php @@ -3,14 +3,14 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\EventManager; -use \PHPUnit_Framework_TestCase as TestCase; -use \Zend\EventManager\EventManager; +use PHPUnit_Framework_TestCase as TestCase; +use Zend\EventManager\EventManager; /** * @requires PHP 5.4 diff --git a/test/EventManagerTest.php b/test/EventManagerTest.php index 0b6722a..5889f92 100644 --- a/test/EventManagerTest.php +++ b/test/EventManagerTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/FilterChainTest.php b/test/FilterChainTest.php index d4a97d4..8d378fd 100644 --- a/test/FilterChainTest.php +++ b/test/FilterChainTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/GlobalEventManagerTest.php b/test/GlobalEventManagerTest.php index df97f49..1e58b2b 100644 --- a/test/GlobalEventManagerTest.php +++ b/test/GlobalEventManagerTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/ListenerAggregateTraitTest.php b/test/ListenerAggregateTraitTest.php index facf4b2..31d3162 100644 --- a/test/ListenerAggregateTraitTest.php +++ b/test/ListenerAggregateTraitTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/StaticEventManagerTest.php b/test/StaticEventManagerTest.php index b1c6068..b8d7e1e 100644 --- a/test/StaticEventManagerTest.php +++ b/test/StaticEventManagerTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/StaticIntegrationTest.php b/test/StaticIntegrationTest.php index 0c95e9b..bd7085d 100644 --- a/test/StaticIntegrationTest.php +++ b/test/StaticIntegrationTest.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/TestAsset/ClassWithEvents.php b/test/TestAsset/ClassWithEvents.php index 26bfd10..5f6bc2e 100644 --- a/test/TestAsset/ClassWithEvents.php +++ b/test/TestAsset/ClassWithEvents.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/TestAsset/Functor.php b/test/TestAsset/Functor.php index 05e70da..574dd95 100644 --- a/test/TestAsset/Functor.php +++ b/test/TestAsset/Functor.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/TestAsset/MockAbstractListenerAggregate.php b/test/TestAsset/MockAbstractListenerAggregate.php index 96929ba..5585e39 100644 --- a/test/TestAsset/MockAbstractListenerAggregate.php +++ b/test/TestAsset/MockAbstractListenerAggregate.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/TestAsset/MockAggregate.php b/test/TestAsset/MockAggregate.php index af4b932..2b02740 100644 --- a/test/TestAsset/MockAggregate.php +++ b/test/TestAsset/MockAggregate.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/TestAsset/MockListenerAggregateTrait.php b/test/TestAsset/MockListenerAggregateTrait.php index 648ed91..b9f4c74 100644 --- a/test/TestAsset/MockListenerAggregateTrait.php +++ b/test/TestAsset/MockListenerAggregateTrait.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/TestAsset/SharedMockAggregate.php b/test/TestAsset/SharedMockAggregate.php index f558813..5f61745 100644 --- a/test/TestAsset/SharedMockAggregate.php +++ b/test/TestAsset/SharedMockAggregate.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/test/TestAsset/StaticEventsMock.php b/test/TestAsset/StaticEventsMock.php index 89c62f9..3dc5ad3 100644 --- a/test/TestAsset/StaticEventsMock.php +++ b/test/TestAsset/StaticEventsMock.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */