symfony/event-dispatcher-contracts
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
psr/event-dispatcher | 1.0.0 | 4.17 kB | MIT | prod |
The Symfony EventDispatcher Contracts package contains a set of abstractions extracted from the Symfony components. Essentially, it is used in dispatching events within a Symfony application, thereby promoting better organized, decoupled, and more manageable code. The advantage of using this package is that it's based on semantics proven useful by the Symfony components, guaranteeing reliability with battle-tested implementations.
The symfony/event-dispatcher-contracts is used in the context of a Symfony application, more commonly in complex applications with a need for an advanced system of communicating between different modular parts of the software. A typical usage might involve creating an Event object class, dispatching the event using the EventDispatcher, and having listeners or subscribers that perform actions when specific events occur. Here is a simple example of how you might use it:
use Symfony\Contracts\EventDispatcher\Event;
class OrderPlacedEvent extends Event
{
const NAME = 'order.placed';
// ...
}
$dispatcher = new EventDispatcher();
$listener = new OrderPlacedListener();
$dispatcher->addListener(OrderPlacedEvent::NAME, [$listener, 'onOrderPlaced']);
$event = new OrderPlacedEvent($order);
$dispatcher->dispatch($event, OrderPlacedEvent::NAME);
When the order is placed in this example, OrderPlacedEvent is dispatched and the OrderPlacedListener performs the tasks defined in its onOrderPlaced
method.
Documentation for the symfony/event-dispatcher-contracts is part of the Symfony framework documentation available online. More specifically, comprehensive information can be found on Symfony's Contracts Github page at this URL: https://github.com/symfony/contracts/blob/main/README.md. In addition to basic instructions, the docs provide valuable insight into how to maximize the utility of this package and generate practical implementations in Symfony applications.