-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathEvent.php
112 lines (102 loc) · 2.18 KB
/
Event.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Event object and dispatcher
*
* @author Magento Core Team <[email protected]>
*/
namespace Magento\Framework;
/**
* @api
* @since 100.0.2
*/
class Event extends \Magento\Framework\DataObject
{
/**
* Observers collection
*
* @var \Magento\Framework\Event\Observer\Collection
*/
protected $_observers;
/**
* Constructor
*
* Initializes observers collection
*
* @param array $data
*/
public function __construct(array $data = [])
{
$this->_observers = new \Magento\Framework\Event\Observer\Collection();
parent::__construct($data);
}
/**
* Returns all the registered observers for the event
*
* @return \Magento\Framework\Event\Observer\Collection
*/
public function getObservers()
{
return $this->_observers;
}
/**
* Register an observer for the event
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function addObserver(\Magento\Framework\Event\Observer $observer)
{
$this->getObservers()->addObserver($observer);
return $this;
}
/**
* Removes an observer by its name
*
* @param string $observerName
* @return $this
*/
public function removeObserverByName($observerName)
{
$this->getObservers()->removeObserverByName($observerName);
return $this;
}
/**
* Dispatches the event to registered observers
*
* @return $this
*/
public function dispatch()
{
$this->getObservers()->dispatch($this);
return $this;
}
/**
* Retrieve event name
*
* @return string
*/
public function getName()
{
return $this->_data['name'] ?? null;
}
/**
* @param string $data
* @return $this
*/
public function setName($data)
{
$this->_data['name'] = $data;
return $this;
}
/**
* @return mixed
*/
public function getBlock()
{
return $this->_getData('block');
}
}