Download the PHP package mario-legenda/php-event-emitter without Composer

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

Introduction

This project is a light port of Nodes EventEmitter class. Although, it does not have all the features that Node EventEmitter has, it has all that you need to implement the Observer pattern right away in your classes with minimal code refactoring.

Installation

Supports PHP >7.0

composer require mario-legenda/php-event-emitter

Usage by extending the EventEmitter class

An alternative to calling EventEmitter::on() with a closure would be to create a class that implements the EventEmitter\CallableInterface that exposes a single method run(). The drawback is that in PHP, we cannot set a variable number of parameters for the run() method. Therefor, if you want to use this interface, you would have to nullify every one of the arguments that you expect to receive. For example...

Multiple event handlers

It is possible to chain multiple identical events

Usage within an object

As you can see, the two examples are almost identical. Creating the EventEmitter instance inside the Task class is not proper dependency injection but it enables us to use the EventEmitter seamlessly. The client code does not now that Task is using (or is) an EventEmitter.

Exception handling

EventEmitter can handle internal exceptions thrown by your code.

If you chain multiple events, every event after the one where an exception occurred will not be called.

API

EventEmitter::__construct($handleErrors = false)

EventEmitter constructor. If provided true as the first argument, exceptions will be handled by the EventEmitter. Else, exceptions will be propagated to client code

EventEmitter::emit(string $eventName, ...args): void

Registers an event to be called with EventEmitter::on(). Must be called before EventEmitter::on().

EventEmitter::on(string $eventName, $callback): EventEmitter

Executes an event. $callback has to be an instance of \Closure or a instance of EventEmitter\CallableInterface

EventEmitter::exception($callback)

Called only when $handleError argument is set to true in the constructor and an exception occurred in executing one of the events.

EventEmitter::removeEvent(string $eventName, bool $strictCheck = false): bool

Removes an event and returns true if successful or false on failure. If $strictCheck is true, an exception is throw if an event cannot be removed (if it doesn't exist for example).

EventEmitter::removeAllEvents()

Removes all events.

EventEmitter::getEventNames(): ?array

Returns an array of currently registered event names or null if there are none


All versions of php-event-emitter with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 mario-legenda/php-event-emitter contains the following files

Loading the files please wait ....