-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathManager.php
71 lines (64 loc) · 1.86 KB
/
Manager.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Event manager
* Used to dispatch global events
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Event;
class Manager implements ManagerInterface
{
/**
* Events cache
*
* @var array
*/
protected $_events = [];
/**
* Event invoker
*
* @var InvokerInterface
*/
protected $_invoker;
/**
* Event config
*
* @var ConfigInterface
*/
protected $_eventConfig;
/**
* @param InvokerInterface $invoker
* @param ConfigInterface $eventConfig
*/
public function __construct(InvokerInterface $invoker, ConfigInterface $eventConfig)
{
$this->_invoker = $invoker;
$this->_eventConfig = $eventConfig;
}
/**
* Dispatch event
*
* Calls all observer callbacks registered for this event
* and multiple observers matching event name pattern
*
* @param string $eventName
* @param array $data
* @return void
*/
public function dispatch($eventName, array $data = [])
{
$eventName = mb_strtolower($eventName);
\Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
$event = new \Magento\Framework\Event($data);
$event->setName($eventName);
$wrapper = new Observer();
$wrapper->setData(array_merge(['event' => $event], $data));
\Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
$this->_invoker->dispatch($observerConfig, $wrapper);
\Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
}
\Magento\Framework\Profiler::stop('EVENT:' . $eventName);
}
}