Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'vendor/autoload.php';
- use Symfony\Component\Stopwatch\Stopwatch;
- use Symfony\Component\Stopwatch\Section;
- use Symfony\Component\EventDispatcher\EventDispatcher;
- use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
- use Symfony\Component\EventDispatcher\GenericEvent;
- use Symfony\Component\EventDispatcher\Event;
- class EventSubscriber implements EventSubscriberInterface
- {
- public static function getSubscribedEvents() {
- return array('data.emit' => [['hello', 20],['world', 5],['eventful', 10]]);
- }
- public function __call($name, $args)
- {
- $ev = $args[0];
- $s = $ev->getSubject();
- unset($s[$name]);
- $ev = new GenericEvent($s);
- print_r(array('name' => $name, 'data' => $ev->getSubject()));
- return $ev;
- }
- }
- $ev = new GenericEvent(array('hello' => 1, 'world' => 2, 'eventful' => 3));
- $s = new Stopwatch();
- $b = new EventDispatcher;
- $dispatcher = new TraceableEventDispatcher($b, $s);
- $es = new EventSubscriber();
- $dispatcher->addSubscriber($es);
- //var_dump($ev);
- $dispatcher->dispatch('data.emit', $ev);
- print_r($dispatcher->getCalledListeners());
- print_r($dispatcher->getNotCalledListeners());
- foreach ($s->getSections() as $section) {
- print_r("section id: ". $section->getId() . "\n");
- foreach ($section->getEvents() as $event) {
- print_r("\tevent category: ". $event->getCategory() . "\n");
- print_r("\tevent memory: ". $event->getMemory() . "\n");
- foreach ($event->getPeriods() as $period) {
- print_r("\t\tperiod time: ". $period->getDuration() . "\n");
- print_r("\t\tperiod memory: ". $period->getMemory() . "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement