1. Go to this page and download the library: Download event-band/symfony-bundle 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/ */
event-band / symfony-bundle example snippets
namespace Acme\EventBundle\Event;
class EchoEventListener
{
public function onEchoEvent(EchoEvent $event)
{
// don't do such things on production
echo $event->getMessage();
echo "\n";
}
}
$dispatcher = $this->getContainer()->get('event_dispatcher');
$dispatcher->dispatch('event.echo', new EchoEvent('Hi, guys!'));
php
namespace Acme\EventBundle\Event;
use EventBand\Adapter\Symfony\SerializableSymfonyEvent;
class EchoEvent extends SerializableSymfonyEvent
{
/**
* @var string
**/
protected $message;
public function __construct($message)
{
$this->message = $message;
}
public funciton getMessage()
{
return $this->message;
}
protected function toSerializableArray()
{
$array = parent::toSerializableArray();
$array['message'] = $this->message;
return $array;
}
protected function fromUnserializedArray(array $data)
{
parent::fromUnserializedArray($data);
$this->message = $data['message'];
}
}
xml
<service id="acme.event_bundle.event.event_listener" class="Acme\EventBundle\EchoEventListener">
<tag name="kernel.event_listener" event="event.echo" method="onEchoEvent"/>
</service>