|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Process main class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package App |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright YetiForce Sp. z o.o |
|
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
10
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace App; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Process class. |
|
17
|
|
|
*/ |
|
18
|
|
|
class Process |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Request start time. |
|
22
|
|
|
* |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
public static $startTime; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Request mode. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
public static $requestMode; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* CRM root directory. |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
public static $rootDirectory; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Request process type. |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
public static $processType; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Request process name. |
|
50
|
|
|
* |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
public static $processName; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* List of events. |
|
57
|
|
|
* |
|
58
|
|
|
* @var array |
|
59
|
|
|
*/ |
|
60
|
|
|
private static $events = []; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Initialization of events. |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function init(): void |
|
68
|
|
|
{ |
|
69
|
|
|
self::$events = Session::get('processEvents', []); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Add event. |
|
74
|
|
|
* |
|
75
|
|
|
* App\Process::addEvent([ |
|
76
|
|
|
* 'name' => 'notify test', |
|
77
|
|
|
* 'execution' => 'once', |
|
78
|
|
|
* 'type' => 'notify', |
|
79
|
|
|
* 'notify' => [ |
|
80
|
|
|
* 'text' => 'test', |
|
81
|
|
|
* 'type' => 'info' // alert, notice, info, success, error |
|
82
|
|
|
* ] |
|
83
|
|
|
* ]); |
|
84
|
|
|
* alert, notice, info, success, error |
|
85
|
|
|
* |
|
86
|
|
|
* @param array $event |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
public static function addEvent(array $event): void |
|
91
|
|
|
{ |
|
92
|
|
|
if (empty($event['name']) || empty($event['type'])) { |
|
93
|
|
|
throw new Exceptions\AppException('Incorrect data'); |
|
94
|
|
|
} |
|
95
|
|
|
if (empty($event['priority'])) { |
|
96
|
|
|
$event['priority'] = 5; |
|
97
|
|
|
} |
|
98
|
|
|
if (empty($event['execution'])) { |
|
99
|
|
|
$event['execution'] = 'constant'; |
|
100
|
|
|
} |
|
101
|
|
|
self::$events[$event['name']] = $event; |
|
102
|
|
|
self::writeSession(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Remove event. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $name |
|
109
|
|
|
* |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
public static function removeEvent(string $name): void |
|
113
|
|
|
{ |
|
114
|
|
|
if (isset(self::$events[$name])) { |
|
115
|
|
|
unset(self::$events[$name]); |
|
116
|
|
|
self::writeSession(); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Has event. |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $name |
|
124
|
|
|
* |
|
125
|
|
|
* @return bool |
|
126
|
|
|
*/ |
|
127
|
|
|
public static function hasEvent(string $name): bool |
|
128
|
|
|
{ |
|
129
|
|
|
return isset(self::$events[$name]); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Get events. |
|
134
|
|
|
* |
|
135
|
|
|
* @return array |
|
136
|
|
|
*/ |
|
137
|
|
|
public static function getEvents(): array |
|
138
|
|
|
{ |
|
139
|
|
|
$events = []; |
|
140
|
|
|
$writeSession = false; |
|
141
|
|
|
foreach (self::$events as $name => $row) { |
|
142
|
|
|
$events[] = $row; |
|
143
|
|
|
if ('once' === $row['execution']) { |
|
144
|
|
|
unset(self::$events[$name]); |
|
145
|
|
|
$writeSession = true; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
if ($writeSession) { |
|
149
|
|
|
self::writeSession(); |
|
150
|
|
|
} |
|
151
|
|
|
$priority = array_column($events, 'priority'); |
|
152
|
|
|
array_multisort($priority, SORT_DESC, $events); |
|
153
|
|
|
return $events; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Write session data. |
|
158
|
|
|
* |
|
159
|
|
|
* @return void |
|
160
|
|
|
*/ |
|
161
|
|
|
private static function writeSession(): void |
|
162
|
|
|
{ |
|
163
|
|
|
Session::set('processEvents', self::$events); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.