1. Go to this page and download the library: Download kuria/event library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kuria / event example snippets
use Kuria\Event\EventEmitter
use Kuria\Event\Observable
use Kuria\Event\EventEmitterPropInterface;
use Kuria\Event\ObservableInterface;
use Kuria\Event\ObservableTrait
$observable->on('some.event', function ($arg1, $arg2) {
// do something
})
$observable->off('some.event', $callback); // returns TRUE on success
Using an event listener
-----------------------
To register an event listener, use the ``addListener()`` method:
.. code:: php
use Kuria\Event\EventListener
$observable->removeListener($eventListener); // returns TRUE on success
Using an event subscriber
-------------------------
Event subscribers subscribe to a list of events. Each event is usually mapped
to one method of the subscriber.
The listeners can be created using the convenient ``listen()`` method
(as shown in the example below) or by manually creating ``EventListener``
instances.
- any callback or method can stop event propagation by returning ``FALSE``
- `listener priority`_ can be specified using 3rd argument of ``listen()``
or the ``EventListener`` constructor
.. code:: php
use Kuria\Event\EventSubscriber
$subscriber->subscribeTo($observable)
$subscriber->unsubscribeFrom($observable)
use Kuria\Event\EventListener;
use Kuria\Event\ObservableInterface
$observable->emit('foo')
$observable->emit('foo', 'hello', 123)
use Kuria\Event\Observable
$field = new Field('username');
$field->on(FieldEvents::CHANGE, function (Field $field, $oldValue, $newValue) {
echo "Field '{$field->getName()}' has been changed from '{$oldValue}' to '{$newValue}'\n";
});
$field->on(FieldEvents::CLEAR, function (Field $field) {
echo "Field '{$field->getName()}' has been cleared\n";
});
$field->setValue('john.smith');
$field->setValue('foo.bar123');
$field->clear()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.