evenement/evenement
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The evenement/evenement package is an incredibly straightforward event dispatching library for PHP, inspired by the EventEmitter API found in Node.js. Its primary aim is to empower users whilst maintaining simplicity and conciseness, mimicking the design goals of Silex and Pimple. It gives PHP developers the power to easily handle the propagation of events in their applications.
Let's delve into how to use the evenement/evenement library. Installation is simple using composer. Run this command in your terminal:
composer require evenement/evenement
Now, to create an Emitter:
<?php
$emitter = new Evenement\EventEmitter();
To add listeners to specific events, use the on
method:
<?php
$emitter->on('user.created', function (User $user) use ($logger) {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
To remove these listeners, the removeListener
function is used:
<?php
$emitter->removeListener('user.created', function (User $user) use ($logger) {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
Finally, to emit the events, you would use the emit
function as follows:
<?php
$emitter->emit('user.created', [$user]);
The documentation for the evenement/evenement library can be found directly within the README file on the GitHub page: [another note, unfortunately in this case, the readme only contains basic setup and usage, not further documentation]. However, the usage examples and brief explanation of the system's functionality provide an impressive and useful guide to getting started with the library.