Download the PHP package solventt/event-dispatcher without Composer

On this page you can find all versions of the php package solventt/event-dispatcher. 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 event-dispatcher

Table of Contents

  1. Installing
  2. Container Listener Provider
  3. Classic Listener Provider
  4. Reflection Listener Provider
  5. Deferred events
  6. Listeners constraints according to PSR-14
  7. Stopped Propagation Events
  8. Iterators instead of arrays
  9. Creating listener providers

It's the PSR-14 compatible Event Dispatcher which provides several ways of determining "Event-Listeners" definitions.

NOTE: All the examples below, which include the DI container, are written using the php-di library. But you can utilize any DI container in your code.

Installing

Note: if you are going to use Container Listener Provider you must install any PSR-11 compatible DI Container.

Container Listener Provider

This provider supports only string definitions of listeners. And listeners must implement the method. It allows "lazy" creation of callable listeners while dispatching an event.

Remember:

The "Event-Listeners" definition for the DI container,

The first format:

The second format without specifying events (listeners events will be automatically resolved):

The third mixed format (arrays and strings):

The Event Dispatcher definition for the DI container:

Somewhere in the code:

Classic Listener Provider

This provider supports only callable definitions of listeners. You can assign listeners to events using:

Using:

If you use the DI Container your definition might look like:

Also, you can specify the listener execution order (an integer parameter). The higher the value, the earlier it will be called:

The "Event-Listeners" definition using the method somewhere in the code:

And with the priority:

To unbind a listener from an event use the method:

Reflection Listener Provider

This provider admits only callable definitions of listeners but without specifying events (it will be automatically resolved).

You can assign listeners to events using:

Using:

With the listener execution order:

The "Event-Listeners" definition using the method somewhere in the code:

And with the priority:

To unbind a listener from an event use the method:

Deferred events

In some cases you may need to use deferred events.

Listeners constraints according to PSR-14

Quotes from the PSR-14: 1) "A Listener MUST have one and only one parameter, which is the Event to which it responds"; 2) "A Listener SHOULD have a void return, and SHOULD type hint that return explicitly".

You can say that SHOULD not equal MUST. But I can't imagine what use-cases might require returning values from listeners and then use them. Anyway this dispatcher does not implement it.

So in this package you can't specify:

You must provide a type hint of the listener argument - it can be an existent class or the type. Other type-hints are not accepted.

In these cases an exception will be thrown:

But you can switch off these listener constraints. It is necessary to pass as the argument in the constructor of some listener provider:

However, the listeners provided without corresponding events ignores this setting because it requires a type-hinted argument for resolving an event:

Also, does not support switching off the listener constraints.

Stopped Propagation Events

Your events can implement (from PSR-14) to have more control over the listeners execution. For example, we have the following event class:

And there are three listeners:

The listeners definition:

The third listener will not be executed because the method of the returns after the second listener is being executed.

Iterators instead of arrays

Providers also receive iterators in their constructor. But an iterator must implement the interface.

Example 1:

Example 2:

Somewhere in the code:

Creating listener providers

You need to implement the PSR-14 . And if you want your provider to support the methods you also have to implement .


All versions of event-dispatcher with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
psr/event-dispatcher Version ^1.0.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 solventt/event-dispatcher contains the following files

Loading the files please wait ....