Skip to content

@barnabywalters /output.html secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Symfony Event Dispatcher Minimal Proof-of-Concept
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>';
<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.