1. Go to this page and download the library: Download mozart/event-dispatcher 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/ */
ozart\Library\Event\Event;
use Mozart\Library\Event\EventDispatcher;
use Mozart\Library\Event\ObjectEvent;
use Mozart\Library\Event\Listener\CustomListener;
/**
* Example Class ListenerOne { Array Argument }
*/
class ListenerOne extends CustomListener
{
public function emailSubscriber(Event $event)
{
$event->setEvent(CustomListener::EVENT_SUBSCRIBER);
echo $event->getEvent();
}
}
$dispatcher = new EventDispatcher();
/**
* Dispatch the event with Array Event Argument
*/
$listenerOne = new ListenerOne();
$dispatcher->addListener('event.email.subscriber', array($listenerOne, 'emailSubscriber'));
$dispatcher->dispatch('event.email.subscriber');
/**
* Example Class ListenerTwo
*/
class ListenerTwo extends CustomListener
{
public function newsEvent(Event $event)
{
$event->setEvent(CustomListener::EVENT_NEWS);
echo $event->getEvent();
}
}
/**
* Dispatch the event with Closure Event Argument
*/
$dispatcher->addListener('news.event', function() {
$listenerTwo = new ListenerTwo();
echo $listenerTwo->newsEvent(new Event());
});
$dispatcher->dispatch('news.event');
/**
* Email Subscriber Listener
*/
class EmailSubscriberListener
{
public function sendDelivery(ObjectEvent $event)
{
if (isset($event['name']) && $event['name'] === 'email.subscriber') {
return $event['name'];
}
$event['send'];
}
}
$objectEvent = new ObjectEvent(
$subject = null, array(
'name' => 'email.subsciber',
'send' => array(
'list' => array(
'[email protected]',
'[email protected]'
)
)
)
);
$dispatcher->dispatch('email.subscriber', $objectEvent);
foreach ($objectEvent['send'] as $emails => $email) {
foreach ($email as $listEmail) {
echo $listEmail;
}
}
use Mozart\Library\Event\InjectDispatcher;
$inject = new InjectDispatcher($dispatcher)
$ phpunit
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.