Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. require 'vendor/autoload.php';
  4. use Symfony\Component\Stopwatch\Stopwatch;
  5. use Symfony\Component\Stopwatch\Section;
  6. use Symfony\Component\EventDispatcher\EventDispatcher;
  7. use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
  8. use Symfony\Component\EventDispatcher\GenericEvent;
  9. use Symfony\Component\EventDispatcher\Event;
  10.  
  11. class EventSubscriber implements EventSubscriberInterface
  12. {
  13. public static function getSubscribedEvents() {
  14. return array('data.emit' => [['hello', 20],['world', 5],['eventful', 10]]);
  15. }
  16. public function __call($name, $args)
  17. {
  18. $ev = $args[0];
  19. $s = $ev->getSubject();
  20.  
  21. unset($s[$name]);
  22. $ev = new GenericEvent($s);
  23. print_r(array('name' => $name, 'data' => $ev->getSubject()));
  24. return $ev;
  25. }
  26. }
  27. $ev = new GenericEvent(array('hello' => 1, 'world' => 2, 'eventful' => 3));
  28. $s = new Stopwatch();
  29. $b = new EventDispatcher;
  30. $dispatcher = new TraceableEventDispatcher($b, $s);
  31. $es = new EventSubscriber();
  32. $dispatcher->addSubscriber($es);
  33. //var_dump($ev);
  34. $dispatcher->dispatch('data.emit', $ev);
  35. print_r($dispatcher->getCalledListeners());
  36. print_r($dispatcher->getNotCalledListeners());
  37.  
  38. foreach ($s->getSections() as $section) {
  39. print_r("section id: ". $section->getId() . "\n");
  40. foreach ($section->getEvents() as $event) {
  41. print_r("\tevent category: ". $event->getCategory() . "\n");
  42. print_r("\tevent memory: ". $event->getMemory() . "\n");
  43. foreach ($event->getPeriods() as $period) {
  44. print_r("\t\tperiod time: ". $period->getDuration() . "\n");
  45. print_r("\t\tperiod memory: ". $period->getMemory() . "\n");
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement