Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into feature/db-story-35
Browse files Browse the repository at this point in the history
Conflicts:
	library/Zend/Db/Sql/Exception/RuntimeException.php
  • Loading branch information
Show file tree
Hide file tree
Showing 24 changed files with 329 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Event implements EventDescription
class Event implements EventInterface
{
/**
* @var string Event name
Expand Down
4 changes: 2 additions & 2 deletions src/EventDescription.php → src/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface EventDescription
interface EventInterface
{
/**
* Get event name
Expand Down Expand Up @@ -94,7 +94,7 @@ public function setParams($params);
public function setParam($name, $value);

/**
* Indicate whether or not the parent EventCollection should stop propagating events
* Indicate whether or not the parent EventManagerInterface should stop propagating events
*
* @param bool $flag
* @return void
Expand Down
92 changes: 46 additions & 46 deletions src/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class EventManager implements EventCollection, SharedEventCollectionAware
class EventManager implements EventManagerInterface
{
/**
* Subscribed events and their listeners
Expand All @@ -52,22 +52,22 @@ class EventManager implements EventCollection, SharedEventCollectionAware
protected $eventClass = 'Zend\EventManager\Event';

/**
* Identifiers, used to pull shared signals from SharedEventCollection instance
* Identifiers, used to pull shared signals from SharedEventManagerInterface instance
* @var array
*/
protected $identifiers = array();

/**
* Shared connections
* @var false|null|SharedEventCollection
* Shared event manager
* @var false|null|SharedEventManagerInterface
*/
protected $sharedCollections = null;
protected $sharedManager = null;

/**
* Constructor
*
* Allows optionally specifying identifier(s) to use to pull signals from a
* SharedEventCollection.
* SharedEventManagerInterface.
*
* @param null|string|int|array|Traversable $identifiers
* @return void
Expand All @@ -90,38 +90,38 @@ public function setEventClass($class)
}

/**
* Set shared collections container
* Set shared event manager
*
* @param SharedEventCollection $connections
* @return void
* @param SharedEventManagerInterface $connections
* @return EventManager
*/
public function setSharedCollections(SharedEventCollection $sharedEventCollection)
public function setSharedManager(SharedEventManagerInterface $sharedEventManager)
{
$this->sharedCollections = $sharedEventCollection;
$this->sharedManager = $sharedEventManager;
return $this;
}

/**
* Remove any shared collections
* Remove any shared event manager currently attached
*
* @return void
*/
public function unsetSharedCollections()
public function unsetSharedManager()
{
$this->sharedCollections = false;
$this->sharedManager = false;
}

/**
* Get shared collections container
* Get shared event manager
*
* @return false|SharedEventCollection
* @return false|SharedEventManagerInterface
*/
public function getSharedCollections()
public function getSharedManager()
{
if (null === $this->sharedCollections) {
$this->setSharedCollections(StaticEventManager::getInstance());
if (null === $this->sharedManager) {
$this->setSharedManager(StaticEventManager::getInstance());
}
return $this->sharedCollections;
return $this->sharedManager;
}

/**
Expand Down Expand Up @@ -179,15 +179,15 @@ public function addIdentifiers($identifiers)
*/
public function trigger($event, $target = null, $argv = array(), $callback = null)
{
if ($event instanceof EventDescription) {
if ($event instanceof EventInterface) {
$e = $event;
$event = $e->getName();
$callback = $target;
} elseif ($target instanceof EventDescription) {
} elseif ($target instanceof EventInterface) {
$e = $target;
$e->setName($event);
$callback = $argv;
} elseif ($argv instanceof EventDescription) {
} elseif ($argv instanceof EventInterface) {
$e = $argv;
$e->setName($event);
$e->setTarget($target);
Expand Down Expand Up @@ -220,15 +220,15 @@ public function trigger($event, $target = null, $argv = array(), $callback = nul
*/
public function triggerUntil($event, $target, $argv = null, $callback = null)
{
if ($event instanceof EventDescription) {
if ($event instanceof EventInterface) {
$e = $event;
$event = $e->getName();
$callback = $target;
} elseif ($target instanceof EventDescription) {
} elseif ($target instanceof EventInterface) {
$e = $target;
$e->setName($event);
$callback = $argv;
} elseif ($argv instanceof EventDescription) {
} elseif ($argv instanceof EventInterface) {
$e = $argv;
$e->setName($event);
$e->setTarget($target);
Expand Down Expand Up @@ -260,15 +260,15 @@ public function triggerUntil($event, $target, $argv = null, $callback = null)
* You can specify "*" for the event name. In such cases, the listener will
* be triggered for every event.
*
* @param string|array|ListenerAggregate $event An event or array of event names. If a ListenerAggregate, proxies to {@link attachAggregate()}.
* @param callback|int $callback If string $event provided, expects PHP callback; for a ListenerAggregate $event, this will be the priority
* @param string|array|ListenerAggregateInterface $event An event or array of event names. If a ListenerAggregateInterface, proxies to {@link attachAggregate()}.
* @param callback|int $callback If string $event provided, expects PHP callback; for a ListenerAggregateInterface $event, this will be the priority
* @param int $priority If provided, the priority at which to register the callback
* @return CallbackHandler|mixed CallbackHandler if attaching callback (to allow later unsubscribe); mixed if attaching aggregate
*/
public function attach($event, $callback = null, $priority = 1)
{
// Proxy ListenerAggregate arguments to attachAggregate()
if ($event instanceof ListenerAggregate) {
// Proxy ListenerAggregateInterface arguments to attachAggregate()
if ($event instanceof ListenerAggregateInterface) {
return $this->attachAggregate($event, $callback);
}

Expand Down Expand Up @@ -305,35 +305,35 @@ public function attach($event, $callback = null, $priority = 1)
/**
* Attach a listener aggregate
*
* Listener aggregates accept an EventCollection instance, and call attach()
* Listener aggregates accept an EventManagerInterface instance, and call attach()
* one or more times, typically to attach to multiple events using local
* methods.
*
* @param ListenerAggregate $aggregate
* @param ListenerAggregateInterface $aggregate
* @param int $priority If provided, a suggested priority for the aggregate to use
* @return mixed return value of {@link ListenerAggregate::attach()}
* @return mixed return value of {@link ListenerAggregateInterface::attach()}
*/
public function attachAggregate(ListenerAggregate $aggregate, $priority = 1)
public function attachAggregate(ListenerAggregateInterface $aggregate, $priority = 1)
{
return $aggregate->attach($this, $priority);
}

/**
* Unsubscribe a listener from an event
*
* @param CallbackHandler|ListenerAggregate $listener
* @param CallbackHandler|ListenerAggregateInterface $listener
* @return bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
* @throws Exception\InvalidArgumentException if invalid listener provided
*/
public function detach($listener)
{
if ($listener instanceof ListenerAggregate) {
if ($listener instanceof ListenerAggregateInterface) {
return $this->detachAggregate($listener);
}

if (!$listener instanceof CallbackHandler) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: expected a ListenerAggregate or CallbackHandler; received "%s"',
'%s: expected a ListenerAggregateInterface or CallbackHandler; received "%s"',
__METHOD__,
(is_object($listener) ? get_class($listener) : gettype($listener))
));
Expand All @@ -356,13 +356,13 @@ public function detach($listener)
/**
* Detach a listener aggregate
*
* Listener aggregates accept an EventCollection instance, and call detach()
* Listener aggregates accept an EventManagerInterface instance, and call detach()
* of all previously attached listeners.
*
* @param ListenerAggregate $aggregate
* @return mixed return value of {@link ListenerAggregate::detach()}
* @param ListenerAggregateInterface $aggregate
* @return mixed return value of {@link ListenerAggregateInterface::detach()}
*/
public function detachAggregate(ListenerAggregate $aggregate)
public function detachAggregate(ListenerAggregateInterface $aggregate)
{
return $aggregate->detach($this);
}
Expand Down Expand Up @@ -426,11 +426,11 @@ public function prepareArgs(array $args)
* delegate.
*
* @param string $event Event name
* @param EventDescription $e
* @param EventInterface $e
* @param null|callback $callback
* @return ResponseCollection
*/
protected function triggerListeners($event, EventDescription $e, $callback = null)
protected function triggerListeners($event, EventInterface $e, $callback = null)
{
$responses = new ResponseCollection;
$listeners = $this->getListeners($event);
Expand Down Expand Up @@ -480,23 +480,23 @@ protected function triggerListeners($event, EventDescription $e, $callback = nul
}

/**
* Get list of all listeners attached to the shared collection for
* Get list of all listeners attached to the shared event manager for
* identifiers registered by this instance
*
* @param string $event
* @return array
*/
protected function getSharedListeners($event)
{
if (!$sharedCollections = $this->getSharedCollections()) {
if (!$sharedManager = $this->getSharedManager()) {
return array();
}

$identifiers = $this->getIdentifiers();
$sharedListeners = array();

foreach ($identifiers as $id) {
if (!$listeners = $sharedCollections->getListeners($id, $event)) {
if (!$listeners = $sharedManager->getListeners($id, $event)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface EventManagerAware
interface EventManagerAwareInterface
{
/**
* Inject an EventManager instance
*
* @param EventCollection $eventManager
* @param EventManagerInterface $eventManager
* @return void
*/
public function setEventManager(EventCollection $eventManager);
public function setEventManager(EventManagerInterface $eventManager);
}
58 changes: 54 additions & 4 deletions src/EventCollection.php → src/EventManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

namespace Zend\EventManager;

use Zend\Stdlib\CallbackHandler;
use Zend\Stdlib\CallbackHandler,
Traversable,
ArrayObject;

/**
* Interface for messengers
Expand All @@ -30,7 +32,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface EventCollection
interface EventManagerInterface extends SharedEventManagerAwareInterface
{
/**
* Trigger an event
Expand Down Expand Up @@ -76,12 +78,12 @@ public function triggerUntil($event, $target, $argv = null, $callback = null);
* @param int $priority Priority at which to register listener
* @return CallbackHandler
*/
public function attach($event, $callback, $priority = 1);
public function attach($event, $callback = null, $priority = 1);

/**
* Detach an event listener
*
* @param CallbackHandler|ListenerAggregate $listener
* @param CallbackHandler|ListenerAggregateInterface $listener
* @return void
*/
public function detach($listener);
Expand All @@ -108,4 +110,52 @@ public function getListeners($event);
* @return void
*/
public function clearListeners($event);

/**
* Set the event class to utilize
*
* @param string $class
* @return EventCollection
*/
public function setEventClass($class);

/**
* Get the identifier(s) for this EventManager
*
* @return array
*/
public function getIdentifiers();

/**
* Set the identifiers (overrides any currently set identifiers)
*
* @param string|int|array|Traversable $identifiers
* @return EventCollection
*/
public function setIdentifiers($identifiers);

/**
* Add some identifier(s) (appends to any currently set identifiers)
*
* @param string|int|array|Traversable $identifiers
* @return EventCollection
*/
public function addIdentifiers($identifiers);

/**
* Attach a listener aggregate
*
* @param ListenerAggregateInterface $aggregate
* @param int $priority If provided, a suggested priority for the aggregate to use
* @return mixed return value of {@link ListenerAggregateInterface::attach()}
*/
public function attachAggregate(ListenerAggregateInterface $aggregate, $priority = 1);

/**
* Detach a listener aggregate
*
* @param ListenerAggregateInterface $aggregate
* @return mixed return value of {@link ListenerAggregateInterface::detach()}
*/
public function detachAggregate(ListenerAggregateInterface $aggregate);
}
Loading

0 comments on commit 3f70aa8

Please sign in to comment.