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

Commit

Permalink
Merge branch 'eventmanager-interface-improvement' of https://github.c…
Browse files Browse the repository at this point in the history
…om/prolic/zf2 into feature/eventmanager-interfaces

Conflicts:
	library/Zend/EventManager/EventManager.php
	library/Zend/EventManager/EventManagerInterface.php
	library/Zend/EventManager/SharedEventManagerAwareInterface.php
	tests/Zend/EventManager/TestAsset/StaticEventsMock.php
  • Loading branch information
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 12 deletions.
4 changes: 2 additions & 2 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 EventManagerInterface, SharedEventManagerAwareInterface
class EventManager implements EventManagerInterface
{
/**
* Subscribed events and their listeners
Expand Down Expand Up @@ -93,7 +93,7 @@ public function setEventClass($class)
* Set shared event manager
*
* @param SharedEventManagerInterface $connections
* @return void
* @return EventManager
*/
public function setSharedManager(SharedEventManagerInterface $sharedEventManager)
{
Expand Down
56 changes: 53 additions & 3 deletions 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 EventManagerInterface
interface EventManagerInterface extends SharedEventManagerAwareInterface
{
/**
* Trigger an event
Expand Down Expand Up @@ -76,7 +78,7 @@ 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
Expand Down Expand Up @@ -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);
}
5 changes: 3 additions & 2 deletions src/SharedEventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

namespace Zend\EventManager;

use Zend\Stdlib\CallbackHandler;
use Zend\Stdlib\CallbackHandler,
Zend\Stdlib\PriorityQueue;

/**
* Shared/contextual EventManager
Expand Down Expand Up @@ -116,7 +117,7 @@ public function getEvents($id)
*
* @param string|int $id
* @param string|int $event
* @return false|\Zend\Stdlib\PriorityQueue
* @return false|PriorityQueue
*/
public function getListeners($id, $event)
{
Expand Down
14 changes: 14 additions & 0 deletions src/SharedEventManagerAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,18 @@ interface SharedEventManagerAwareInterface
* @return SharedEventManagerAwareInterface
*/
public function setSharedManager(SharedEventManagerInterface $sharedEventManager);

/**
* Get shared collections container
*
* @return SharedEventManagerInterface
*/
public function getSharedManager();

/**
* Remove any shared collections
*
* @return void
*/
public function unsetSharedManager();
}
48 changes: 48 additions & 0 deletions src/SharedEventManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

namespace Zend\EventManager;

use Zend\Stdlib\CallbackHandler,
Zend\Stdlib\PriorityQueue;

/**
* Interface for shared event listener collections
*
Expand All @@ -30,5 +33,50 @@
*/
interface SharedEventManagerInterface
{
/**
* Retrieve all listeners for a given identifier and event
*
* @param string|int $id
* @param string|int $event
* @return false|PriorityQueue
*/
public function getListeners($id, $event);

/**
* Attach a listener to an event
*
* @param string|array $id Identifier(s) for event emitting component(s)
* @param string $event
* @param callback $callback PHP Callback
* @param int $priority Priority at which listener should execute
* @return void
*/
public function attach($id, $event, $callback, $priority = 1);

/**
* Detach a listener from an event offered by a given resource
*
* @param string|int $id
* @param CallbackHandler $listener
* @return bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
*/
public function detach($id, CallbackHandler $listener);

/**
* Retrieve all registered events for a given resource
*
* @param string|int $id
* @return array
*/
public function getEvents($id);

/**
* Clear all listeners for a given identifier, optionally for a specific event
*
* @param string|int $id
* @param null|string $event
* @return bool
*/
public function clearListeners($id, $event = null);

}
8 changes: 4 additions & 4 deletions src/StaticEventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ private function __clone()
*/
public static function getInstance()
{
if (null === self::$instance) {
self::$instance = new self();
if (null === static::$instance) {
static::$instance = new static();
}
return self::$instance;
return static::$instance;
}

/**
Expand All @@ -75,6 +75,6 @@ public static function getInstance()
*/
public static function resetInstance()
{
self::$instance = null;
static::$instance = null;
}
}
54 changes: 53 additions & 1 deletion test/TestAsset/StaticEventsMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

namespace ZendTest\EventManager\TestAsset;

use Zend\EventManager\SharedEventManagerInterface;
use Zend\EventManager\SharedEventManagerInterface,
Zend\Stdlib\CallbackHandler;

/**
* @category Zend
Expand All @@ -37,4 +38,55 @@ public function getListeners($id, $event)
{
return array();
}

/**
* Attach a listener to an event
*
* @param string|array $id Identifier(s) for event emitting component(s)
* @param string $event
* @param callback $callback PHP Callback
* @param int $priority Priority at which listener should execute
* @return void
*/
public function attach($id, $event, $callback, $priority = 1)
{

}

/**
* Detach a listener from an event offered by a given resource
*
* @param string|int $id
* @param CallbackHandler $listener
* @return bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
*/
public function detach($id, CallbackHandler $listener)
{
return true;
}

/**
* Retrieve all registered events for a given resource
*
* @param string|int $id
* @return array
*/
public function getEvents($id)
{
return array();
}

/**
* Clear all listeners for a given identifier, optionally for a specific event
*
* @param string|int $id
* @param null|string $event
* @return bool
*/
public function clearListeners($id, $event = null)
{
return true;
}


}

0 comments on commit e02bd81

Please sign in to comment.