Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Manager.php
Go to the documentation of this file.
1 <?php
10 
11 class Manager implements ManagerInterface
12 {
18  protected $_events = [];
19 
25  protected $_invoker;
26 
32  protected $_eventConfig;
33 
38  public function __construct(InvokerInterface $invoker, ConfigInterface $eventConfig)
39  {
40  $this->_invoker = $invoker;
41  $this->_eventConfig = $eventConfig;
42  }
43 
54  public function dispatch($eventName, array $data = [])
55  {
56  $eventName = mb_strtolower($eventName);
57  \Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
58  foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
59  $event = new \Magento\Framework\Event($data);
60  $event->setName($eventName);
61 
62  $wrapper = new Observer();
63  $wrapper->setData(array_merge(['event' => $event], $data));
64 
65  \Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
66  $this->_invoker->dispatch($observerConfig, $wrapper);
67  \Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
68  }
69  \Magento\Framework\Profiler::stop('EVENT:' . $eventName);
70  }
71 }
__construct(InvokerInterface $invoker, ConfigInterface $eventConfig)
Definition: Manager.php:38
dispatch($eventName, array $data=[])
Definition: Manager.php:54