Bitrix-D7 22.2
Загрузка...
Поиск...
Не найдено
event.php
См. документацию.
1<?php
2namespace Bitrix\Main;
3
4class Event
5{
6 protected $moduleId;
7 protected $type;
8 protected $parameters = array();
10 protected $parametersLoader = null;
11 protected $filter = null;
12 protected $sender = null;
13
14 protected $debugMode = false;
15 protected $debugInfo = array();
16
18 protected $results = array();
19
21 protected $exceptions = array();
22
29 public function __construct($moduleId, $type, $parameters = array(), $filter = null)
30 {
31 $this->moduleId = $moduleId;
32 $this->type = $type;
34 $this->setFilter($filter);
35
36 $this->debugMode = false;
37 }
38
39 public function getModuleId()
40 {
41 return $this->moduleId;
42 }
43
44 public function getEventType()
45 {
46 return $this->type;
47 }
48
49 public function setParameters($parameters)
50 {
51 if (is_array($parameters))
52 {
53 $this->parameters = $parameters;
54 }
55 elseif ($parameters instanceof \Closure)
56 {
57 $this->parameters = null;
58 $this->parametersLoader = $parameters;
59 }
60 else
61 {
62 throw new ArgumentTypeException("parameter", "array or closure, which returns array");
63 }
64 }
65
66 public function getParameters()
67 {
68 $this->loadParameters();
69
70 return $this->parameters;
71 }
72
73 public function setParameter($key, $value)
74 {
75 $this->loadParameters();
76
77 $this->parameters[$key] = $value;
78 }
79
80 public function getParameter($key)
81 {
82 $this->loadParameters();
83
84 if (isset($this->parameters[$key]))
85 return $this->parameters[$key];
86
87 return null;
88 }
89
90 protected function loadParameters()
91 {
92 if (!$this->parametersLoader)
93 {
94 return false;
95 }
96
97 $this->setParameters(call_user_func_array($this->parametersLoader, array()));
98 $this->parametersLoader = null;
99
100 return true;
101 }
102
103 public function setFilter($filter)
104 {
105 if (!is_array($filter))
106 {
107 if (empty($filter))
108 $filter = null;
109 else
110 $filter = array($filter);
111 }
112
113 $this->filter = $filter;
114 }
115
116 public function getFilter()
117 {
118 return $this->filter;
119 }
120
124 public function getResults()
125 {
126 return $this->results;
127 }
128
129 public function addResult(EventResult $result)
130 {
131 $this->results[] = $result;
132 }
133
134 public function getSender()
135 {
136 return $this->sender;
137 }
138
139 public function send($sender = null)
140 {
141 $this->sender = $sender;
142 EventManager::getInstance()->send($this);
143 }
144
145 public function addException(\Exception $exception)
146 {
147 $this->exceptions[] = $exception;
148 }
149
150 public function getExceptions()
151 {
152 return $this->exceptions;
153 }
154
155 public function turnDebugOn()
156 {
157 $this->debugMode = true;
158 }
159
160 public function isDebugOn()
161 {
162 return $this->debugMode;
163 }
164
165 public function addDebugInfo($ar)
166 {
167 if (!$this->debugMode)
168 return;
169
170 $this->debugInfo[] = $ar;
171 }
172
173 public function getDebugInfo()
174 {
175 return $this->debugInfo;
176 }
177}
setParameters($parameters)
Definition: event.php:49
setParameter($key, $value)
Definition: event.php:73
setFilter($filter)
Definition: event.php:103
addException(\Exception $exception)
Definition: event.php:145
send($sender=null)
Definition: event.php:139
__construct($moduleId, $type, $parameters=array(), $filter=null)
Definition: event.php:29
addResult(EventResult $result)
Definition: event.php:129
getParameter($key)
Definition: event.php:80
addDebugInfo($ar)
Definition: event.php:165