Download the PHP package koriit/eventdispatcher without Composer

On this page you can find all versions of the php package koriit/eventdispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package eventdispatcher

EventDispatcher

Build Status Coverage Status Scrutinizer Code Quality StyleCI SensioLabsInsight

Latest Stable Version License

Simple event dispatcher based on PHP-DI.

This library does not aim to be general purpose library or to cover all possible use cases. What this library does aim to be is perfect choice for those who use PHP-DI and prefer to use PHP Definitions.

The goal is to create as decoupled code as possible. The code that uses the dispatcher may not know its listeners, and the other way around, the listeners may not even know that they are actually used as listeners!

Install

EventDispatcher is available via composer:

Versions

This library depends on PHP-DI and is thus affected by compatibility breaks coming from it.

v2

Tested with PHP-DI ^6.0.

v1

Tested with PHP-DI ^5.4.

Usage

You are encouraged to familiarize yourself with Koriit\EventDispatcher\EventDispatcherInterface and Koriit\EventDispatcher\EventContextInterface as those two interfaces are everything you need to work with this library.

Basic example:

Naturally since we are using PHP-DI then we would create a definition for Koriit\EventDispatcher\EventDispatcherInterface.

A listener may be anything that can be invoked by PHP-DI:

Even interfaces:

For above example to work you need to configure a definition for MyInterface, of course.

Warning:
Event dispatcher doesn't work well with listeners which implement fluent interface or allow for method chaining. For more information, read about stopping dispatchemnt chain below.

Adding listeners

There are 2 ways to subscribe a listener. In both cases you have to specify name of the event and calling priority. The higher the priority value the later the listener will be called. Listeners with the same priority will be called in the order they have been subscribed. You can entirely omit priority parameter as it defaults to 0.

addListener

First, by using addListener method on Koriit\EventDispatcher\EventDispatcher object.

addListeners

Second, by using addListeners method on Koriit\EventDispatcher\EventDispatcher object.

Listeners array is a simple structure of 3 levels:

Example:

Dispatchment

Dispatchment is a simple process of invoking all listeners subscribed to dispatched event.

Stopping dispatchment

If any listener in the dispatchment chain returns a value that can be evaluated as true, the dispachment is stopped and all the remaining listeners are skipped. You can also achieve this by calling stop on event context.

While this design simplifies the process and does not require wiring listeners with event dispatcher, it makes it problematic to work with listeners that return values which cannot be interpreted as success or failure. This especially holds true for methods which allow for method chaining or implement fluent interface. To work around this problem you can use stop and ignoreReturnValue methods on event context, though, that requires wiring your listener with event context. Everything is a trade-off, someone once said.

Context

Event context is simple data object holding information about the dispatchment process. See Koriit\EventDispatcher\EventContextInterface for more information.

Parameters

You can pass additional parameters to be used by invoker while injecting listener arguments by name.

eventName, eventContext, eventDispatcher

There are 3 parameters injected by event dispatcher itself:

  1. eventName - name of the event dispatched
  2. eventContext - reference to the context object of current dispatchment
  3. eventDispatcher - reference to the event dispatcher itself; this allows for nested dispatchments

You cannot override them as using those keys in parameters array causes exception.


All versions of eventdispatcher with dependencies

PHP Build Version
Package Version
Requires php-di/php-di Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package koriit/eventdispatcher contains the following files

Loading the files please wait ....