caridea / event
A shrimp of an event library
Requires
- php: >=7.1.0
Requires (Dev)
- phpunit/phpunit: ^6.0.0
This package is not auto-updated.
Last update: 2024-11-04 07:42:31 UTC
README
Caridea is a miniscule PHP application library. This shrimpy fellow is what you'd use when you just want some helping hands and not a full-blown framework.
This is its event library. It has interfaces for Publisher and Listener, and an abstract class for Event.
If you'd like a concrete implementation of Publisher
, try caridea-container.
Installation
You can install this library using Composer:
$ composer require caridea/event
- The master branch (version 3.x) of this project requires PHP 7.1 and has no dependencies.
- Version 2.x of this project requires PHP 7.0 and has no dependencies.
- Version 1.x of this project requires PHP 5.5 and has no dependencies.
Compliance
Releases of this library will conform to Semantic Versioning.
Our code is intended to comply with PSR-1, PSR-2, and PSR-4. If you find any issues related to standards compliance, please send a pull request!
Documentation
- Head over to Read the Docs
Examples
Just a few quick examples.
Let's say you have defined these classes
namespace Acme\Foo; class CustomEvent extends \Caridea\Event\Event { } class CustomEventListener implements \Caridea\Event\Listener { public function notify(\Caridea\Event\Event $event) { if ($event instanceof CustomEvent) { // do something here } } }
A publisher can be invoked like this:
// Here, we assume that $publisher implements a \Caridea\Event\Publisher and that // We have somehow registered an \Acme\Foo\CustomEventListener with it. $publisher->publish(new \Acme\Foo\CustomEvent()); // Our CustomEventListener has its ->notify method invoked.
There's a no-op implementation of Publisher
available as \Caridea\Event\NullPublisher
.
PublisherAware
For classes which need the event publisher, you can make use of the PublisherAware
interface, and optionally the PublisherSetter
trait.
class MyClass implements \Caridea\Event\PublisherAware { use \Caridea\Event\PublisherSetter; public function __construct() { $this->setPublisher(new \Caridea\Event\NullPublisher()); } }