Skip to content

Take1 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
composer.lock
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# event-dispatcher
PSR Event Dispatcher
====================

This repository holds all interfaces/classes/traits related to
[PSR-14](http://www.php-fig.org/psr/psr-14/).

Note that this is not an Event Dispatcher implementation of its own. It is merely interfaces that describe the components of an Event Dispatcher. See the specification for more details.

Usage
-----

We'll certainly need some stuff in here.
15 changes: 15 additions & 0 deletions src/EventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Psr\Event\Dispatcher;

/**
* Marker interface indicating an event instance.
*
* Event instances may contain zero methods, or as many methods as they
* want. The interface MUST be implemented, however, to provide type-safety
* to both listeners as well as listener providers.
*/
interface EventInterface
{
}
17 changes: 17 additions & 0 deletions src/ListenerProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Psr\Event\Dispatcher;


interface ListenerProviderInterface
{
/**
* @param EventInterface $event
* An event for which to return the relevant listeners.
* @return iterable[callable]
* An iterable (array, iterator, or generator) of callables. Each
* callable MUST be type-compatible with $event.
*/
public function getListenersForEvent(EventInterface $event) : iterable;
}
21 changes: 21 additions & 0 deletions src/ModifyDispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);

namespace Psr\Event\Dispatcher;

/**
* Defines a dispatcher for modifiable events.
*/
interface ModifyDispatcherInterface
{
/**
* Provide all listeners with an event to modify.
*
* @param EventInterface $event
* The event to modify.
*
* @return EventInterface
* The event that was passed, now modified by callers.
*/
public function modify(EventInterface $event) : EventInterface;
}
22 changes: 22 additions & 0 deletions src/NotifyDispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);

namespace Psr\Event\Dispatcher;

/**
* Defines a notifying dispatcher.
*/
interface NotifyDispatcherInterface
{
/**
* Notify listeners of an event.
*
* This method MAY act asynchronously. Callers SHOULD NOT
* assume that any action has been taken when this method
* returns.
*
* @param EventInterface $event
* The event to notify listeners of.
*/
public function notify(EventInterface $event) : void;
}
20 changes: 20 additions & 0 deletions src/StoppableDispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);

namespace Psr\Event\Dispatcher;

/**
* Defines a dispatcher for stoppable events.
*/
interface StoppableDispatcherInterface
{
/**
* Provides all listeners an event to respond to.
*
* @param StoppableEventInterface $event
* The event to pass to listeners.
* @return StoppableEventInterface
* The event that was passed, now modified.
*/
public function intercept(StoppableEventInterface $event) : StoppableEventInterface;
}
36 changes: 36 additions & 0 deletions src/StoppableEventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);

namespace Psr\Event\Dispatcher;

/**
* Event that can stop propagation to undispatched listeners.
*
* A Stoppable Dispatcher implementation MUST check to determine if an Event
* is marked as stopped after each listener is called. If it is then it should
* return immediately without calling any further Listeners.
*/
interface StoppableEventInterface extends EventInterface
{
/**
* Stop event propagation.
*
* Once called, when handling returns to the dispatcher, the dispatcher MUST
* stop calling any remaining listeners and return handling back to the
* target object.
*
* @param bool $stop
* True (default) to flag the event as stopped. False to cancel the stoppage.
*
* @return self
*/
public function stopPropagation($stop = true) : self;

/**
* Is propagation stopped?
*
* This will typically only be used by the dispatcher to determine if the
* previous listener halted propagation.
*/
public function isStopped() : bool;
}