zendframework/zend-eventmanager
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The zendframework/zend-eventmanager is a composer package designed to handle events within a PHP application. It majorly fulfils three use cases - implementing simple subject/observer patterns, aspect-oriented designs, and event-driven architectures. This architecture allows you to attach and detach listeners to named events, both on a per-instance basis as well as via shared collections, trigger events, and interrupt the execution of event listeners.
To use the zendframework/zend-eventmanager, you need to first install it via composer. Here is a simple code example showing how to use this package:
use Zend\EventManager\EventManager;
$eventManager = new EventManager();
$eventManager->attach('do', function ($e) {
$event = $e->getName();
$params = $e->getParams();
printf(
'Handled event "%s", with parameters %s',
$event,
json_encode($params)
);
});
$params = ['foo' => 'bar', 'baz' => 'bat'];
$eventManager->trigger('do', null, $params);
In the example, we first import the EventManager from zendframework. We then create a new instance and attach an event 'do' to it. We also define an event handler function to handle this event. Then we trigger the event 'do' with some parameters.
The in-depth documentation of zendframework/zend-eventmanager can be found directly on the official Zend Framework site at https://zendframework.github.io/zend-eventmanager/. This comprehensive guide will take you through from basic usage to advanced features of the package, with clear examples and descriptions. Make sure to read them if you're planning to use this package in your project. Additionally, you can find specific information about migrating from version 2 to version 3 in the migration documentation section.