Uploaded From CV. Swandhana Server
This commit is contained in:
19
vendor/league/event/LICENSE
vendored
Normal file
19
vendor/league/event/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2014 Frank de Jonge
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
37
vendor/league/event/composer.json
vendored
Normal file
37
vendor/league/event/composer.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "league/event",
|
||||
"description": "Event package",
|
||||
"keywords": ["event", "emitter", "listener"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Frank de Jonge",
|
||||
"email": "info@frenky.net"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"henrikbjorn/phpspec-code-coverage": "~1.0.1",
|
||||
"phpspec/phpspec": "^2.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\Event\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"League\\Event\\Stub\\": "stubs/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.2-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
64
vendor/league/event/src/AbstractEvent.php
vendored
Normal file
64
vendor/league/event/src/AbstractEvent.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
abstract class AbstractEvent implements EventInterface
|
||||
{
|
||||
/**
|
||||
* Has propagation stopped?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $propagationStopped = false;
|
||||
|
||||
/**
|
||||
* The emitter instance.
|
||||
*
|
||||
* @var EmitterInterface|null
|
||||
*/
|
||||
protected $emitter;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setEmitter(EmitterInterface $emitter)
|
||||
{
|
||||
$this->emitter = $emitter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getEmitter()
|
||||
{
|
||||
return $this->emitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function stopPropagation()
|
||||
{
|
||||
$this->propagationStopped = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isPropagationStopped()
|
||||
{
|
||||
return $this->propagationStopped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return get_class($this);
|
||||
}
|
||||
}
|
||||
14
vendor/league/event/src/AbstractListener.php
vendored
Normal file
14
vendor/league/event/src/AbstractListener.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
abstract class AbstractListener implements ListenerInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isListener($listener)
|
||||
{
|
||||
return $this === $listener;
|
||||
}
|
||||
}
|
||||
49
vendor/league/event/src/BufferedEmitter.php
vendored
Normal file
49
vendor/league/event/src/BufferedEmitter.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
class BufferedEmitter extends Emitter
|
||||
{
|
||||
/**
|
||||
* @var EventInterface[]
|
||||
*/
|
||||
protected $bufferedEvents = [];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function emit($event)
|
||||
{
|
||||
$this->bufferedEvents[] = $event;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function emitBatch(array $events)
|
||||
{
|
||||
foreach ($events as $event) {
|
||||
$this->bufferedEvents[] = $event;
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the buffered events.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emitBufferedEvents()
|
||||
{
|
||||
$result = [];
|
||||
|
||||
while ($event = array_shift($this->bufferedEvents)) {
|
||||
$result[] = parent::emit($event);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
65
vendor/league/event/src/CallbackListener.php
vendored
Normal file
65
vendor/league/event/src/CallbackListener.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
class CallbackListener implements ListenerInterface
|
||||
{
|
||||
/**
|
||||
* The callback.
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* Create a new callback listener instance.
|
||||
*
|
||||
* @param callable $callback
|
||||
*/
|
||||
public function __construct(callable $callback)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the callback.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function handle(EventInterface $event)
|
||||
{
|
||||
call_user_func_array($this->callback, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isListener($listener)
|
||||
{
|
||||
if ($listener instanceof CallbackListener) {
|
||||
$listener = $listener->getCallback();
|
||||
}
|
||||
|
||||
return $this->callback === $listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Named constructor
|
||||
*
|
||||
* @param callable $callable
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromCallable(callable $callable)
|
||||
{
|
||||
return new static($callable);
|
||||
}
|
||||
}
|
||||
268
vendor/league/event/src/Emitter.php
vendored
Normal file
268
vendor/league/event/src/Emitter.php
vendored
Normal file
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class Emitter implements EmitterInterface
|
||||
{
|
||||
/**
|
||||
* The registered listeners.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listeners = [];
|
||||
|
||||
/**
|
||||
* The sorted listeners
|
||||
*
|
||||
* Listeners will get sorted and stored for re-use.
|
||||
*
|
||||
* @var ListenerInterface[]
|
||||
*/
|
||||
protected $sortedListeners = [];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addListener($event, $listener, $priority = self::P_NORMAL)
|
||||
{
|
||||
$listener = $this->ensureListener($listener);
|
||||
$this->listeners[$event][$priority][] = $listener;
|
||||
$this->clearSortedListeners($event);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addOneTimeListener($event, $listener, $priority = self::P_NORMAL)
|
||||
{
|
||||
$listener = $this->ensureListener($listener);
|
||||
$listener = new OneTimeListener($listener);
|
||||
|
||||
return $this->addListener($event, $listener, $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function useListenerProvider(ListenerProviderInterface $provider)
|
||||
{
|
||||
$acceptor = new ListenerAcceptor($this);
|
||||
$provider->provideListeners($acceptor);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function removeListener($event, $listener)
|
||||
{
|
||||
$this->clearSortedListeners($event);
|
||||
$listeners = $this->hasListeners($event)
|
||||
? $this->listeners[$event]
|
||||
: [];
|
||||
|
||||
$filter = function ($registered) use ($listener) {
|
||||
return ! $registered->isListener($listener);
|
||||
};
|
||||
|
||||
foreach ($listeners as $priority => $collection) {
|
||||
$listeners[$priority] = array_filter($collection, $filter);
|
||||
}
|
||||
|
||||
$this->listeners[$event] = $listeners;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function removeAllListeners($event)
|
||||
{
|
||||
$this->clearSortedListeners($event);
|
||||
|
||||
if ($this->hasListeners($event)) {
|
||||
unset($this->listeners[$event]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the input is a listener.
|
||||
*
|
||||
* @param ListenerInterface|callable $listener
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*
|
||||
* @return ListenerInterface
|
||||
*/
|
||||
protected function ensureListener($listener)
|
||||
{
|
||||
if ($listener instanceof ListenerInterface) {
|
||||
return $listener;
|
||||
}
|
||||
|
||||
if (is_callable($listener)) {
|
||||
return CallbackListener::fromCallable($listener);
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('Listeners should be ListenerInterface, Closure or callable. Received type: '.gettype($listener));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function hasListeners($event)
|
||||
{
|
||||
if (! isset($this->listeners[$event]) || count($this->listeners[$event]) === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getListeners($event)
|
||||
{
|
||||
if (array_key_exists($event, $this->sortedListeners)) {
|
||||
return $this->sortedListeners[$event];
|
||||
}
|
||||
|
||||
return $this->sortedListeners[$event] = $this->getSortedListeners($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the listeners sorted by priority for a given event.
|
||||
*
|
||||
* @param string $event
|
||||
*
|
||||
* @return ListenerInterface[]
|
||||
*/
|
||||
protected function getSortedListeners($event)
|
||||
{
|
||||
if (! $this->hasListeners($event)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$listeners = $this->listeners[$event];
|
||||
krsort($listeners);
|
||||
|
||||
return call_user_func_array('array_merge', $listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function emit($event)
|
||||
{
|
||||
list($name, $event) = $this->prepareEvent($event);
|
||||
$arguments = [$event] + func_get_args();
|
||||
$this->invokeListeners($name, $event, $arguments);
|
||||
$this->invokeListeners('*', $event, $arguments);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function emitBatch(array $events)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($events as $event) {
|
||||
$results[] = $this->emit($event);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function emitGeneratedEvents(GeneratorInterface $generator)
|
||||
{
|
||||
$events = $generator->releaseEvents();
|
||||
|
||||
return $this->emitBatch($events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the listeners for an event.
|
||||
*
|
||||
* @param string $name
|
||||
* @param EventInterface $event
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function invokeListeners($name, EventInterface $event, array $arguments)
|
||||
{
|
||||
$listeners = $this->getListeners($name);
|
||||
|
||||
foreach ($listeners as $listener) {
|
||||
if ($event->isPropagationStopped()) {
|
||||
break;
|
||||
}
|
||||
|
||||
call_user_func_array([$listener, 'handle'], $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an event for emitting.
|
||||
*
|
||||
* @param string|EventInterface $event
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareEvent($event)
|
||||
{
|
||||
$event = $this->ensureEvent($event);
|
||||
$name = $event->getName();
|
||||
$event->setEmitter($this);
|
||||
|
||||
return [$name, $event];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure event input is of type EventInterface or convert it.
|
||||
*
|
||||
* @param string|EventInterface $event
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*
|
||||
* @return EventInterface
|
||||
*/
|
||||
protected function ensureEvent($event)
|
||||
{
|
||||
if (is_string($event)) {
|
||||
return Event::named($event);
|
||||
}
|
||||
|
||||
if (! $event instanceof EventInterface) {
|
||||
throw new InvalidArgumentException('Events should be provides as Event instances or string, received type: '.gettype($event));
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the sorted listeners for an event
|
||||
*
|
||||
* @param $event
|
||||
*/
|
||||
protected function clearSortedListeners($event)
|
||||
{
|
||||
unset($this->sortedListeners[$event]);
|
||||
}
|
||||
}
|
||||
22
vendor/league/event/src/EmitterAwareInterface.php
vendored
Normal file
22
vendor/league/event/src/EmitterAwareInterface.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
interface EmitterAwareInterface
|
||||
{
|
||||
/**
|
||||
* Set the Emitter.
|
||||
*
|
||||
* @param EmitterInterface $emitter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmitter(EmitterInterface $emitter = null);
|
||||
|
||||
/**
|
||||
* Get the Emitter.
|
||||
*
|
||||
* @return EmitterInterface
|
||||
*/
|
||||
public function getEmitter();
|
||||
}
|
||||
41
vendor/league/event/src/EmitterAwareTrait.php
vendored
Normal file
41
vendor/league/event/src/EmitterAwareTrait.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
trait EmitterAwareTrait
|
||||
{
|
||||
/**
|
||||
* The emitter instance.
|
||||
*
|
||||
* @var EmitterInterface|null
|
||||
*/
|
||||
protected $emitter;
|
||||
|
||||
/**
|
||||
* Set the Emitter.
|
||||
*
|
||||
* @param EmitterInterface|null $emitter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmitter(EmitterInterface $emitter = null)
|
||||
{
|
||||
$this->emitter = $emitter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Emitter.
|
||||
*
|
||||
* @return EmitterInterface
|
||||
*/
|
||||
public function getEmitter()
|
||||
{
|
||||
if (! $this->emitter) {
|
||||
$this->emitter = new Emitter();
|
||||
}
|
||||
|
||||
return $this->emitter;
|
||||
}
|
||||
}
|
||||
92
vendor/league/event/src/EmitterInterface.php
vendored
Normal file
92
vendor/league/event/src/EmitterInterface.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
interface EmitterInterface extends ListenerAcceptorInterface
|
||||
{
|
||||
/**
|
||||
* Remove a specific listener for an event.
|
||||
*
|
||||
* The first parameter should be the event name, and the second should be
|
||||
* the event listener. It may implement the League\Event\ListenerInterface
|
||||
* or simply be "callable".
|
||||
*
|
||||
* @param string $event
|
||||
* @param ListenerInterface|callable $listener
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeListener($event, $listener);
|
||||
|
||||
/**
|
||||
* Use a provider to add listeners.
|
||||
*
|
||||
* @param ListenerProviderInterface $provider
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function useListenerProvider(ListenerProviderInterface $provider);
|
||||
|
||||
/**
|
||||
* Remove all listeners for an event.
|
||||
*
|
||||
* The first parameter should be the event name. All event listeners will
|
||||
* be removed.
|
||||
*
|
||||
* @param string $event
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeAllListeners($event);
|
||||
|
||||
/**
|
||||
* Check whether an event has listeners.
|
||||
*
|
||||
* The first parameter should be the event name. We'll return true if the
|
||||
* event has one or more registered even listeners, and false otherwise.
|
||||
*
|
||||
* @param string $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasListeners($event);
|
||||
|
||||
/**
|
||||
* Get all the listeners for an event.
|
||||
*
|
||||
* The first parameter should be the event name. We'll return an array of
|
||||
* all the registered even listeners, or an empty array if there are none.
|
||||
*
|
||||
* @param string $event
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getListeners($event);
|
||||
|
||||
/**
|
||||
* Emit an event.
|
||||
*
|
||||
* @param string|EventInterface $event
|
||||
*
|
||||
* @return EventInterface
|
||||
*/
|
||||
public function emit($event);
|
||||
|
||||
/**
|
||||
* Emit a batch of events.
|
||||
*
|
||||
* @param array $events
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emitBatch(array $events);
|
||||
|
||||
/**
|
||||
* Release all events stored in a generator
|
||||
*
|
||||
* @param GeneratorInterface $generator
|
||||
*
|
||||
* @return EventInterface[]
|
||||
*/
|
||||
public function emitGeneratedEvents(GeneratorInterface $generator);
|
||||
}
|
||||
113
vendor/league/event/src/EmitterTrait.php
vendored
Normal file
113
vendor/league/event/src/EmitterTrait.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
trait EmitterTrait
|
||||
{
|
||||
use EmitterAwareTrait;
|
||||
|
||||
/**
|
||||
* Add a listener for an event.
|
||||
*
|
||||
* The first parameter should be the event name, and the second should be
|
||||
* the event listener. It may implement the League\Event\ListenerInterface
|
||||
* or simply be "callable".
|
||||
*
|
||||
* @param string $event
|
||||
* @param ListenerInterface|callable $listener
|
||||
* @param int $priority
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addListener($event, $listener, $priority = ListenerAcceptorInterface::P_NORMAL)
|
||||
{
|
||||
$this->getEmitter()->addListener($event, $listener, $priority);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a one time listener for an event.
|
||||
*
|
||||
* The first parameter should be the event name, and the second should be
|
||||
* the event listener. It may implement the League\Event\ListenerInterface
|
||||
* or simply be "callable".
|
||||
*
|
||||
* @param string $event
|
||||
* @param ListenerInterface|callable $listener
|
||||
* @param int $priority
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addOneTimeListener($event, $listener, $priority = ListenerAcceptorInterface::P_NORMAL)
|
||||
{
|
||||
$this->getEmitter()->addOneTimeListener($event, $listener, $priority);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specific listener for an event.
|
||||
*
|
||||
* The first parameter should be the event name, and the second should be
|
||||
* the event listener. It may implement the League\Event\ListenerInterface
|
||||
* or simply be "callable".
|
||||
*
|
||||
* @param string $event
|
||||
* @param ListenerInterface|callable $listener
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeListener($event, $listener)
|
||||
{
|
||||
$this->getEmitter()->removeListener($event, $listener);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all listeners for an event.
|
||||
*
|
||||
* The first parameter should be the event name. All event listeners will
|
||||
* be removed.
|
||||
*
|
||||
* @param string $event
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeAllListeners($event)
|
||||
{
|
||||
$this->getEmitter()->removeAllListeners($event);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add listeners from a provider.
|
||||
*
|
||||
* @param ListenerProviderInterface $provider
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function useListenerProvider(ListenerProviderInterface $provider)
|
||||
{
|
||||
$this->getEmitter()->useListenerProvider($provider);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit an event.
|
||||
*
|
||||
* @param string|EventInterface $event
|
||||
*
|
||||
* @return EventInterface
|
||||
*/
|
||||
public function emit($event)
|
||||
{
|
||||
$emitter = $this->getEmitter();
|
||||
$arguments = [$event] + func_get_args();
|
||||
|
||||
return call_user_func_array([$emitter, 'emit'], $arguments);
|
||||
}
|
||||
}
|
||||
43
vendor/league/event/src/Event.php
vendored
Normal file
43
vendor/league/event/src/Event.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
class Event extends AbstractEvent
|
||||
{
|
||||
/**
|
||||
* The event name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function named($name)
|
||||
{
|
||||
return new static($name);
|
||||
}
|
||||
}
|
||||
43
vendor/league/event/src/EventInterface.php
vendored
Normal file
43
vendor/league/event/src/EventInterface.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
interface EventInterface
|
||||
{
|
||||
/**
|
||||
* Set the Emitter.
|
||||
*
|
||||
* @param EmitterInterface $emitter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmitter(EmitterInterface $emitter);
|
||||
|
||||
/**
|
||||
* Get the Emitter.
|
||||
*
|
||||
* @return EmitterInterface
|
||||
*/
|
||||
public function getEmitter();
|
||||
|
||||
/**
|
||||
* Stop event propagation.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function stopPropagation();
|
||||
|
||||
/**
|
||||
* Check whether propagation was stopped.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPropagationStopped();
|
||||
|
||||
/**
|
||||
* Get the event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
}
|
||||
10
vendor/league/event/src/Generator.php
vendored
Normal file
10
vendor/league/event/src/Generator.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
class Generator implements GeneratorInterface
|
||||
{
|
||||
use GeneratorTrait {
|
||||
addEvent as public;
|
||||
}
|
||||
}
|
||||
13
vendor/league/event/src/GeneratorInterface.php
vendored
Normal file
13
vendor/league/event/src/GeneratorInterface.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
interface GeneratorInterface
|
||||
{
|
||||
/**
|
||||
* Release all the added events.
|
||||
*
|
||||
* @return EventInterface[]
|
||||
*/
|
||||
public function releaseEvents();
|
||||
}
|
||||
40
vendor/league/event/src/GeneratorTrait.php
vendored
Normal file
40
vendor/league/event/src/GeneratorTrait.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
trait GeneratorTrait
|
||||
{
|
||||
/**
|
||||
* The registered events.
|
||||
*
|
||||
* @var EventInterface[]
|
||||
*/
|
||||
protected $events = [];
|
||||
|
||||
/**
|
||||
* Add an event.
|
||||
*
|
||||
* @param EventInterface $event
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function addEvent(EventInterface $event)
|
||||
{
|
||||
$this->events[] = $event;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release all the added events.
|
||||
*
|
||||
* @return EventInterface[]
|
||||
*/
|
||||
public function releaseEvents()
|
||||
{
|
||||
$events = $this->events;
|
||||
$this->events = [];
|
||||
|
||||
return $events;
|
||||
}
|
||||
}
|
||||
43
vendor/league/event/src/ListenerAcceptor.php
vendored
Normal file
43
vendor/league/event/src/ListenerAcceptor.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
class ListenerAcceptor implements ListenerAcceptorInterface
|
||||
{
|
||||
/**
|
||||
* The emitter instance.
|
||||
*
|
||||
* @var EmitterInterface|null
|
||||
*/
|
||||
protected $emitter;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param EmitterInterface $emitter
|
||||
*/
|
||||
public function __construct(EmitterInterface $emitter)
|
||||
{
|
||||
$this->emitter = $emitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addListener($event, $listener, $priority = self::P_NORMAL)
|
||||
{
|
||||
$this->emitter->addListener($event, $listener, $priority);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addOneTimeListener($event, $listener, $priority = self::P_NORMAL)
|
||||
{
|
||||
$this->emitter->addOneTimeListener($event, $listener, $priority);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
59
vendor/league/event/src/ListenerAcceptorInterface.php
vendored
Normal file
59
vendor/league/event/src/ListenerAcceptorInterface.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
interface ListenerAcceptorInterface
|
||||
{
|
||||
/**
|
||||
* High priority.
|
||||
*
|
||||
* @const int
|
||||
*/
|
||||
const P_HIGH = 100;
|
||||
|
||||
/**
|
||||
* Normal priority.
|
||||
*
|
||||
* @const int
|
||||
*/
|
||||
const P_NORMAL = 0;
|
||||
|
||||
/**
|
||||
* Low priority.
|
||||
*
|
||||
* @const int
|
||||
*/
|
||||
const P_LOW = -100;
|
||||
|
||||
/**
|
||||
* Add a listener for an event.
|
||||
*
|
||||
* The first parameter should be the event name, and the second should be
|
||||
* the event listener. It may implement the League\Event\ListenerInterface
|
||||
* or simply be "callable". In this case, the priority emitter also accepts
|
||||
* an optional third parameter specifying the priority as an integer. You
|
||||
* may use one of our predefined constants here if you want.
|
||||
*
|
||||
* @param string $event
|
||||
* @param ListenerInterface|callable $listener
|
||||
* @param int $priority
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addListener($event, $listener, $priority = self::P_NORMAL);
|
||||
|
||||
/**
|
||||
* Add a one time listener for an event.
|
||||
*
|
||||
* The first parameter should be the event name, and the second should be
|
||||
* the event listener. It may implement the League\Event\ListenerInterface
|
||||
* or simply be "callable".
|
||||
*
|
||||
* @param string $event
|
||||
* @param ListenerInterface|callable $listener
|
||||
* @param int $priority
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addOneTimeListener($event, $listener, $priority = self::P_NORMAL);
|
||||
}
|
||||
24
vendor/league/event/src/ListenerInterface.php
vendored
Normal file
24
vendor/league/event/src/ListenerInterface.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
interface ListenerInterface
|
||||
{
|
||||
/**
|
||||
* Handle an event.
|
||||
*
|
||||
* @param EventInterface $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(EventInterface $event);
|
||||
|
||||
/**
|
||||
* Check whether the listener is the given parameter.
|
||||
*
|
||||
* @param mixed $listener
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isListener($listener);
|
||||
}
|
||||
15
vendor/league/event/src/ListenerProviderInterface.php
vendored
Normal file
15
vendor/league/event/src/ListenerProviderInterface.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
interface ListenerProviderInterface
|
||||
{
|
||||
/**
|
||||
* Provide event
|
||||
*
|
||||
* @param ListenerAcceptorInterface $listenerAcceptor
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function provideListeners(ListenerAcceptorInterface $listenerAcceptor);
|
||||
}
|
||||
57
vendor/league/event/src/OneTimeListener.php
vendored
Normal file
57
vendor/league/event/src/OneTimeListener.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace League\Event;
|
||||
|
||||
class OneTimeListener implements ListenerInterface
|
||||
{
|
||||
/**
|
||||
* The listener instance.
|
||||
*
|
||||
* @var ListenerInterface
|
||||
*/
|
||||
protected $listener;
|
||||
|
||||
/**
|
||||
* Create a new one time listener instance.
|
||||
*
|
||||
* @param ListenerInterface $listener
|
||||
*/
|
||||
public function __construct(ListenerInterface $listener)
|
||||
{
|
||||
$this->listener = $listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wrapped listener.
|
||||
*
|
||||
* @return ListenerInterface
|
||||
*/
|
||||
public function getWrappedListener()
|
||||
{
|
||||
return $this->listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function handle(EventInterface $event)
|
||||
{
|
||||
$name = $event->getName();
|
||||
$emitter = $event->getEmitter();
|
||||
$emitter->removeListener($name, $this->listener);
|
||||
|
||||
return call_user_func_array([$this->listener, 'handle'], func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isListener($listener)
|
||||
{
|
||||
if ($listener instanceof OneTimeListener) {
|
||||
$listener = $listener->getWrappedListener();
|
||||
}
|
||||
|
||||
return $this->listener->isListener($listener);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user