Download the PHP package internetpixels/event-manager without Composer

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

Event manager for PHP

Handle events and triggers in your application with this PHP library. No hassle with the correct hooking time of listeners, simple set the priority.

This is a open-source library. Please consider a link to this repository when you're actively using it.

License Build Status Maintainability

Installation

Install this PHP event manager by using composer:

composer require internetpixels/event-manager

Basic examples

Register an event

Before you're able to use a new event, you'll need to register it. Find a logical place in your application, preferably in the start of the runtime.

The event needs to be registered before you can add any listeners to it, otherwise this library will throw an exception!

$eventManager = new EventManager();

$event = new EventEntity();
$event->setKey( 'test.event.after.post' );

$eventManager->registerEvent( $event );

Register a listener

After the event is added, you can "hook" new listeners to the event. This means, when the event is triggered, it will call all triggers with their given priority.

Priority 1 is the most important and the default priority is 50. The event manager sorts the listeners automatically, so it doesn't matter in what order you add the listeners to the event manager.

A listener can only have 1, required, callback method. This method will be called once the event is executed.

$listener = new EventListenerEntity();
$listener->setEventKey( 'test.event.after.post' );
$listener->setPriority( 20 );
$listener->setCallback( [ $this, 'eventCallback' ] );

$eventManager->registerListener( $listener );

Callback example

Each listener has a callback method, a basic callback method may look like this in your application. You should receive the $params array, and return them as an array for further usage.

public function eventCallback( $params = null ) {
    // TODO: Do something with the parameters
    var_dump($params);

    return $params;
}

Execute the event

When your setup is completed with the event and at least one listener, you can execute the event in your application. This will trigger all listener(s) with their given priority.

$eventManager->executeEvent( 'test.event.after.post' )

Using the events as filters

You can use the events as filters. The registration process is nearly the same as a normal event, you only have to enable parameters on the event registration and add them in the executeEvent method.

The executeEvent method will return the parameters.

$event = new EventEntity();
$event->setParams( true );
$event->setKey( 'test.event.after.post' );

$eventManager->registerEvent( $event );

$executed = $eventManager->executeEvent( 'test.event.after.post', [
    'first parameter value',
] );

var_dump( $executed );

The parameters are now available in the event callback $params array.

Multiple params in execution

It is very easy to add more parameters in your execution. Just add new array values in the execute method.

$executed = $eventManager->executeEvent( 'test.event.after.post', [
    'first parameter value',
    'second parameter value',
    'third parameter value',
] );

All versions of event-manager with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
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 internetpixels/event-manager contains the following files

Loading the files please wait ....