PHP code example of rundum / event-base
1. Go to this page and download the library: Download rundum/event-base 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/ */
rundum / event-base example snippets
class ExampleService {
private $dispatcher;
// Constructor with Dependency Injection
function __construct(
EventDispatcherInterface $dispatcher,
) {
$this->dispatcher = $dispatcher;
}
function saveEntity($entity) {
// -> INSERT ...
$this->dispatcher->dispatch(new EntityChangeIntendedEvent($entity, true), EntityChangeIntendedEvent::NAME);
}
function updateEntity($entity) {
// -> UPDATE ...
$this->dispatcher->dispatch(new EntityChangeIntendedEvent($entity), EntityChangeIntendedEvent::NAME);
}
function deleteEntity($entity) {
// -> DELETE FROM ...
$this->dispatcher->dispatch(new EntityRemovalIntendedEvent($entity), EntityRemovalIntendedEvent::NAME);
}
}