Essai au propre
This commit is contained in:
@@ -1,141 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\EventManager;
|
||||
|
||||
use Zend\Stdlib\CallbackHandler;
|
||||
use Zend\Stdlib\PriorityQueue;
|
||||
|
||||
/**
|
||||
* Event manager: notification system
|
||||
*
|
||||
* Use the EventManager when you want to create a per-instance notification
|
||||
* system for your objects.
|
||||
*/
|
||||
class GlobalEventManager
|
||||
{
|
||||
/**
|
||||
* @var EventManagerInterface
|
||||
*/
|
||||
protected static $events;
|
||||
|
||||
/**
|
||||
* Set the event collection on which this will operate
|
||||
*
|
||||
* @param null|EventManagerInterface $events
|
||||
* @return void
|
||||
*/
|
||||
public static function setEventCollection(EventManagerInterface $events = null)
|
||||
{
|
||||
static::$events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event collection on which this operates
|
||||
*
|
||||
* @return EventManagerInterface
|
||||
*/
|
||||
public static function getEventCollection()
|
||||
{
|
||||
if (null === static::$events) {
|
||||
static::setEventCollection(new EventManager());
|
||||
}
|
||||
return static::$events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger an event
|
||||
*
|
||||
* @param string $event
|
||||
* @param object|string $context
|
||||
* @param array|object $argv
|
||||
* @param null|callable $callback
|
||||
* @return ResponseCollection
|
||||
*/
|
||||
public static function trigger($event, $context, $argv = array(), $callback = null)
|
||||
{
|
||||
return static::getEventCollection()->trigger($event, $context, $argv, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger listeners until return value of one causes a callback to evaluate
|
||||
* to true.
|
||||
*
|
||||
* @param string $event
|
||||
* @param string|object $context
|
||||
* @param array|object $argv
|
||||
* @param callable $callback
|
||||
* @return ResponseCollection
|
||||
* @deprecated Please use trigger()
|
||||
*/
|
||||
public static function triggerUntil($event, $context, $argv, $callback)
|
||||
{
|
||||
trigger_error(
|
||||
'This method is deprecated and will be removed in the future. Please use trigger() instead.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
return static::trigger($event, $context, $argv, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a listener to an event
|
||||
*
|
||||
* @param string $event
|
||||
* @param callable $callback
|
||||
* @param int $priority
|
||||
* @return CallbackHandler
|
||||
*/
|
||||
public static function attach($event, $callback, $priority = 1)
|
||||
{
|
||||
return static::getEventCollection()->attach($event, $callback, $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach a callback from a listener
|
||||
*
|
||||
* @param CallbackHandler $listener
|
||||
* @return bool
|
||||
*/
|
||||
public static function detach(CallbackHandler $listener)
|
||||
{
|
||||
return static::getEventCollection()->detach($listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve list of events this object manages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getEvents()
|
||||
{
|
||||
return static::getEventCollection()->getEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all listeners for a given event
|
||||
*
|
||||
* @param string $event
|
||||
* @return PriorityQueue|array
|
||||
*/
|
||||
public static function getListeners($event)
|
||||
{
|
||||
return static::getEventCollection()->getListeners($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all listeners for a given event
|
||||
*
|
||||
* @param string $event
|
||||
* @return void
|
||||
*/
|
||||
public static function clearListeners($event)
|
||||
{
|
||||
static::getEventCollection()->clearListeners($event);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\EventManager;
|
||||
|
||||
trigger_error('Zend\EventManager\ProvidesEvents has been deprecated in favor of Zend\EventManager\EventManagerAwareTrait; please update your code', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
use EventManagerAwareTrait;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\EventManager;
|
||||
|
||||
/**
|
||||
* Interface for allowing attachment of shared aggregate listeners.
|
||||
*/
|
||||
interface SharedEventAggregateAwareInterface
|
||||
{
|
||||
/**
|
||||
* Attach a listener aggregate
|
||||
*
|
||||
* @param SharedListenerAggregateInterface $aggregate
|
||||
* @param int $priority If provided, a suggested priority for the aggregate to use
|
||||
* @return mixed return value of {@link SharedListenerAggregateInterface::attachShared()}
|
||||
*/
|
||||
public function attachAggregate(SharedListenerAggregateInterface $aggregate, $priority = 1);
|
||||
|
||||
/**
|
||||
* Detach a listener aggregate
|
||||
*
|
||||
* @param SharedListenerAggregateInterface $aggregate
|
||||
* @return mixed return value of {@link SharedListenerAggregateInterface::detachShared()}
|
||||
*/
|
||||
public function detachAggregate(SharedListenerAggregateInterface $aggregate);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\EventManager;
|
||||
|
||||
/**
|
||||
* Interface to automate setter injection for a SharedEventManagerInterface instance
|
||||
*/
|
||||
interface SharedEventManagerAwareInterface
|
||||
{
|
||||
/**
|
||||
* Inject a SharedEventManager instance
|
||||
*
|
||||
* @param SharedEventManagerInterface $sharedEventManager
|
||||
* @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();
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\EventManager;
|
||||
|
||||
/**
|
||||
* Interface for self-registering event listeners.
|
||||
*
|
||||
* Classes implementing this interface may be registered by name or instance
|
||||
* 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.
|
||||
*/
|
||||
interface SharedListenerAggregateInterface
|
||||
{
|
||||
/**
|
||||
* Attach one or more listeners
|
||||
*
|
||||
* Implementors may add an optional $priority argument; the SharedEventManager
|
||||
* implementation will pass this to the aggregate.
|
||||
*
|
||||
* @param SharedEventManagerInterface $events
|
||||
*/
|
||||
public function attachShared(SharedEventManagerInterface $events);
|
||||
|
||||
/**
|
||||
* Detach all previously attached listeners
|
||||
*
|
||||
* @param SharedEventManagerInterface $events
|
||||
*/
|
||||
public function detachShared(SharedEventManagerInterface $events);
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\EventManager;
|
||||
|
||||
/**
|
||||
* Static version of EventManager
|
||||
*/
|
||||
class StaticEventManager extends SharedEventManager
|
||||
{
|
||||
/**
|
||||
* @var SharedEventManagerInterface
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve instance
|
||||
*
|
||||
* @return StaticEventManager
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (null === static::$instance) {
|
||||
static::setInstance(new static());
|
||||
}
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the singleton to a specific SharedEventManagerInterface instance
|
||||
*
|
||||
* @param SharedEventManagerInterface $instance
|
||||
* @return void
|
||||
*/
|
||||
public static function setInstance(SharedEventManagerInterface $instance)
|
||||
{
|
||||
static::$instance = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a singleton instance defined?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasInstance()
|
||||
{
|
||||
return (static::$instance instanceof SharedEventManagerInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the singleton instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function resetInstance()
|
||||
{
|
||||
static::$instance = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user