Download the PHP package kuria/event without Composer

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

Event #####

Event library that implements variations of the mediator and observer patterns.

:depth: 2

Features

Requirements

Components

Event emitter

The EventEmitter class maintains a list of listeners and dispatches events to them.

It is intended to be used as a mediator.

$emitter = new EventEmitter();

EventEmitter implements ObservableInterface.

Observable

The abstract Observable class implements the ObservableInterface using an inner event emitter.

It is intended to be extended by child classes that will emit their own events:

class MyComponent extends Observable { function doSomething() { $this->emit('something'); } }

Alternatively, you can use the ObservableTrait to achieve the same result:

class MyComponent implements ObservableInterface, EventEmitterPropInterface { use ObservableTrait;

// ...

}

Usage

The following applies to both observable as they both implement the ObservableInterface.

Listening to events

Using a callback

To register a callback to be called when a specific event occurs, register it using the on() method. Any event arguments will be passed directly to it.

To unregister a callback, call the off() method with the same callback (in case of closures this means the same object):

$observable->addListener( new EventListener( 'some.event', function ($arg1, $arg2) {} ) );

To unregister a listener, call the removeListener() method with the same event listener object:

class MySubscriber extends EventSubscriber { protected function getListeners(): array { return [ $this->listen('foo.bar', 'onFooBar'), $this->listen('lorem.ipsum', 'onLoremIpsum', 10), $this->listen('dolor.sit', 'onDolorSitA'), $this->listen('dolor.sit', 'onDolorSitB', 5), ]; }

function onFooBar() { / do something / } function onLoremIpsum() { / do something / } function onDolorSitA() { / do something / } function onDolorSitB() { / do something / }

}

$subscriber = new MySubscriber();

Registering the event subscriber:

Unregistering the event subsriber:

Stopping event propagation

Any listener can stop further propagation of the current event by returning FALSE.

This prevents any other listeners from being invoked.

Listener priority

Listener priority determines the order in which the listeners are invoked:

Listening to all events

To listen to all events, use ObservableInterface::ANY_EVENT in place of the event name:

$observable->on( ObservableInterface::ANY_EVENT, function ($event, $arg1, $arg2) {} );

$observable->addListener( new EventListener( ObservableInterface::ANY_EVENT, function ($event, $arg1, $arg2) {} ) );

Emitting events

Events are emitted using the emit() method.

Any extra arguments will be passed to the listeners.

Documenting events

While the event library itself doesn't require this, it is a good idea to explicitly define possible event names and their arguments somewhere.

The example below defines a FieldEvents class for this purpose. Constants of this class are then used in place of event names and their annotations serve as documentation. This also allows for code-completion.

/ @see Field / abstract class FieldEvents { / Emitted when field value is about to be changed. @param Field $field @param mixed $oldValue @param mixed $newValue / const CHANGE = 'change';

/* Emitted when field value is about to be cleared. @param Field $field */ const CLEAR = 'clear';

}

/* @see FieldEvents */ class Field extends Observable { private $name; private $value;

function __construct(string $name, $value = null) { $this->name = $name; $this->value = $value; }

function getName(): string { return $this->name; }

function getValue() { return $this->value; }

function setValue($value): void { $this->emit(FieldEvents::CHANGE, $this, $this->value, $value);

$this->value = $value;

}

function clear() { $this->emit(FieldEvents::CLEAR, $this);

$this->value = null;

}

}

Usage example

Output:

Field 'username' has been changed from '' to 'john.smith'
Field 'username' has been changed from 'john.smith' to 'foo.bar123'
Field 'username' has been cleared

All versions of event 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 kuria/event contains the following files

Loading the files please wait ....