Download the PHP package ssnepenthe/wp-event-dispatcher without Composer

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

wp-event-dispatcher

A simple event dispatcher abstraction over WordPress hooks.

Warning

This package is currently in development and is subject to breaking changes without notice until v1.0 has been tagged.

It is one in a series of WordPress toys I have been working on with the intention of exploring ways to modernize the feel of working with WordPress.

As the label suggests, it should be treated as a toy.

Installation

Overview

Event dispatchers (WpEventDispatcher\EventDispatcherInterface) encourage the encapsulation of events into dedicated event classes and event listeners into dedicated subscriber classes.

Usage

The event dispatcher is intended to be used in place of direct calls to the various action and filter functions provided by WordPress.

Event dispatchers do away with the idea of actions and filters altogether. Events are wrapped up in standalone event classes. If you want to "filter" a value, do so using typed properties or setters and getters on the event class. Event listeners can be standalone callables, but should preferably be implemented via subscriber classes.

This is roughly modeled after the Symfony event dispatcher component, but uses WordPress hooks behind the scenes.

The primary methods you will use are dispatch, addListener, and addSubscriber.

By default dispatch uses the FQCN of the event class as the event name. If an event needs a dynamic name it should implement the WpEventDispatcher\NamedEventInterface interface.

Event dispatchers might require a bit extra boilerplate code as compared to standard WordPress hooks, but provide a degree of type-safety and autocompletion you wouldn't otherwise get.

Below is a simple example of how you might replace a WordPress action:

Before:

After:

And an example of how you might replace a filter:

Before:

After:

Event dispatchers also allow for event listeners to be grouped logically within a subscriber class.

Subscribers should implement the WpEventDispatcher\SubscriberInterface interface.

This interface has a single method - getSubscribedEvents. It should return an array in any of the following formats:

Array keys are hook tag names, values are method names on this subscriber instance to use as listeners.

Array keys are hook tag names, values are arrays with method names at index 0 and optional priority at index 1.

Array keys are hook tag names, values are arrays of array with method names at index 0 and optional priority at index 1.

For (a very contrived) example:

Initialize the subscriber with the addSubscriber method on the event dispatcher:


All versions of wp-event-dispatcher with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.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 ssnepenthe/wp-event-dispatcher contains the following files

Loading the files please wait ....