Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Symfony Event Dispatcher Minimal Proof-of-Concept

View output.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
use Symfony\Component\EventDispatcher\EventDispatcher,
Symfony\Component\EventDispatcher\Event;
class RandomEvent extends Event {
protected $data;
public function __construct($data) {
$this -> data = $data;
}
public function getData()
{
return $this -> data;
}
}
$dis = new EventDispatcher;
$dis -> addListener('foo.action', function (RandomEvent $e) {
// Change something about $e
$data = $e -> getData();
$data -> text = 'This text has been changed by the event listener';
});
$myData = new stdclass;
$myData -> text = 'This text as it was orignally';/**/
echo '<p>Before event dispatch: <code>' . print_r($myData, true) . '</code>';
echo '<p>Dispatching event…';
$event = new RandomEvent($myData);
$dis -> dispatch('foo.action', $event);
echo '<p>After event dispatch: <code>' . print_r($myData, true) . '</code>';
View output.html
1 2 3 4 5 6 7 8 9
<p>Before event dispatch: <code>stdClass Object
(
[text] => This text as it was orignally
)
</code><p>Dispatching event…<p>After event dispatch: <code>stdClass Object
(
[text] => This text has been changed by the event listener
)
</code>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.