|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VoidEngine; |
|
4
|
|
|
|
|
5
|
|
|
class VoidEngine |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* * Создание объекта |
|
9
|
|
|
* |
|
10
|
|
|
* @param mixed $objectName - полное название объекта |
|
11
|
|
|
* [@param mixed $objectGroup = null] - полное пространство имён объекта |
|
12
|
|
|
* [@param mixed ...$args = []] - список аргументов создания |
|
13
|
|
|
* |
|
14
|
|
|
* @return int - возвращает указатель на созданный объект |
|
15
|
|
|
* |
|
16
|
|
|
* VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
public static function createObject ($objectName, $objectGroup = null, ...$args): int |
|
21
|
|
|
{ |
|
22
|
|
|
return \VoidCore::createObject ($objectName, $objectGroup, ...$args); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* * Удаление объектов |
|
27
|
|
|
* |
|
28
|
|
|
* @param int ...$selectors - список указателей для удаления |
|
29
|
|
|
* |
|
30
|
|
|
* $button_1 = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
31
|
|
|
* $button_2 = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
32
|
|
|
* |
|
33
|
|
|
* VoidEngine::removeObjects ($button_1, $button_2); |
|
34
|
|
|
* |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
public static function removeObjects (int ...$selectors): void |
|
38
|
|
|
{ |
|
39
|
|
|
\VoidCore::removeObjects (...$selectors); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* * Деструктор объекта |
|
44
|
|
|
* Удаляет указанный объект, если он больше не используеся в коде |
|
45
|
|
|
* |
|
46
|
|
|
* @param int $selector - указатель на объект для удаления |
|
47
|
|
|
* |
|
48
|
|
|
* $button = VoidEngine::createObject ('System.Windows.Forms.Button'); |
|
49
|
|
|
* |
|
50
|
|
|
* VoidEngine::destructObject ($button); |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
|
|
54
|
|
|
public static function destructObject (int $selector): bool |
|
55
|
|
|
{ |
|
56
|
|
|
return \VoidCore::destructObject ($selector); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* * Получение указателя на статичный класс |
|
61
|
|
|
* |
|
62
|
|
|
* @param mixed $className - полное название класса |
|
63
|
|
|
* [@param mixed $classGroup = null] - полное пространство имён класса |
|
64
|
|
|
* |
|
65
|
|
|
* @return int - возвращает указатель на созданный класс |
|
66
|
|
|
* |
|
67
|
|
|
* VoidEngine::createClass ('System.Windows.Forms.MessageBox'); |
|
68
|
|
|
* |
|
69
|
|
|
*/ |
|
70
|
|
|
|
|
71
|
|
|
public static function createClass ($className, $classGroup = null): int |
|
72
|
|
|
{ |
|
73
|
|
|
return \VoidCore::getClass ($className, $classGroup); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* * Создание делегата |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $type - полный тип делегата |
|
80
|
|
|
* @param string $code - исполняемый PHP код |
|
81
|
|
|
* |
|
82
|
|
|
* @return int - возвращает указатель на созданный делегат |
|
83
|
|
|
* |
|
84
|
|
|
*/ |
|
85
|
|
|
|
|
86
|
|
|
public static function createDelegate (string $type, string $code): int |
|
87
|
|
|
{ |
|
88
|
|
|
return \VoidCore::createDelegate ($type, $code); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* * Проверка объекта на существование |
|
93
|
|
|
* |
|
94
|
|
|
* @param int $selector - указатель на проверяемый объект |
|
95
|
|
|
* |
|
96
|
|
|
* @return bool - возвращает true, если объект существует, и false в противном случае |
|
97
|
|
|
* |
|
98
|
|
|
* $button = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
99
|
|
|
* VoidEngine::removeObjects ($button); |
|
100
|
|
|
* |
|
101
|
|
|
* var_dump (VoidEngine::objectExists ($button)); // false |
|
102
|
|
|
* |
|
103
|
|
|
*/ |
|
104
|
|
|
|
|
105
|
|
|
public static function objectExists (int $selector): bool |
|
106
|
|
|
{ |
|
107
|
|
|
return \VoidCore::objectExists ($selector); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* * Создание экземпляра типа объекта |
|
112
|
|
|
* |
|
113
|
|
|
* @param mixed $objectName - полное название объекта |
|
114
|
|
|
* [@param mixed $objectGroup = null] - полное пространство имён объекта |
|
115
|
|
|
* |
|
116
|
|
|
* @return mixed - возвращает указатель на объект типа объекта или false в случае ошибки |
|
117
|
|
|
* |
|
118
|
|
|
*/ |
|
119
|
|
|
|
|
120
|
|
|
public static function objectType ($objectName, $objectGroup = null) |
|
121
|
|
|
{ |
|
122
|
|
|
return \VoidCore::typeof ($objectName, $objectGroup); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* * Получение свойства объекта |
|
127
|
|
|
* |
|
128
|
|
|
* @param int $selector - указатель на объект |
|
129
|
|
|
* @param mixed $propertyName - название свойства |
|
130
|
|
|
* |
|
131
|
|
|
* @param mixed $propertyName может быть передан с указанием на тип возвращаемого значения через структуру вида |
|
132
|
|
|
* [название свойства, возвращаемый им тип] |
|
133
|
|
|
* |
|
134
|
|
|
* @return mixed - возвращает свойство объекта |
|
135
|
|
|
* |
|
136
|
|
|
* $selector = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
137
|
|
|
* |
|
138
|
|
|
* pre (VoidEngine::getProperty ($selector, 'Text')); |
|
139
|
|
|
* pre (VoidEngine::getProperty ($selector, ['Text', 'string'])); |
|
140
|
|
|
* |
|
141
|
|
|
*/ |
|
142
|
|
|
|
|
143
|
|
|
public static function getProperty (int $selector, $propertyName) |
|
144
|
|
|
{ |
|
145
|
|
|
return \VoidCore::getProp ($selector, $propertyName); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* * Установка свойства объекта |
|
150
|
|
|
* |
|
151
|
|
|
* @param int $selector - указатель на объект |
|
152
|
|
|
* @param string $propertyName - название свойства |
|
153
|
|
|
* @param mixed $value - значение свойства |
|
154
|
|
|
* |
|
155
|
|
|
* @param mixed $value может быть передан в качестве определённого типа через структуру вида |
|
156
|
|
|
* [значение, тип] |
|
157
|
|
|
* |
|
158
|
|
|
* $selector = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
159
|
|
|
* |
|
160
|
|
|
* VoidEngine::setProperty ($selector, 'Text', 'Hello!'); |
|
161
|
|
|
* VoidEngine::setProperty ($selector, 'Text', ['Hello!', 'string']); |
|
162
|
|
|
* |
|
163
|
|
|
*/ |
|
164
|
|
|
|
|
165
|
|
|
public static function setProperty (int $selector, string $propertyName, $value): void |
|
166
|
|
|
{ |
|
167
|
|
|
\VoidCore::setProp ($selector, $propertyName, $value); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* * Получение поля объекта |
|
172
|
|
|
* |
|
173
|
|
|
* @param int $selector - указатель на объект |
|
174
|
|
|
* @param mixed $fieldName - название поля |
|
175
|
|
|
* |
|
176
|
|
|
* @param mixed $fieldName может быть передан с указанием на тип возвращаемого значения через структуру вида |
|
177
|
|
|
* [название свойства, возвращаемый им тип] |
|
178
|
|
|
* |
|
179
|
|
|
* @return mixed - возвращает поле объекта |
|
180
|
|
|
* |
|
181
|
|
|
* $selector = VoidEngine::createObject ('System.Net.IPAddress', 'System.Net'); |
|
182
|
|
|
* |
|
183
|
|
|
* pre (VoidEngine::getField ($selector, 'Any')); |
|
184
|
|
|
* |
|
185
|
|
|
*/ |
|
186
|
|
|
|
|
187
|
|
|
public static function getField (int $selector, $fieldName) |
|
188
|
|
|
{ |
|
189
|
|
|
return \VoidCore::getField ($selector, $fieldName); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* * Установка поля объекта |
|
194
|
|
|
* |
|
195
|
|
|
* @param int $selector - указатель на объект |
|
196
|
|
|
* @param string $fieldName - название поля |
|
197
|
|
|
* @param mixed $value - значение поля |
|
198
|
|
|
* |
|
199
|
|
|
* @param mixed $value может быть передан в качестве определённого типа через структуру вида |
|
200
|
|
|
* [значение, тип] |
|
201
|
|
|
* |
|
202
|
|
|
*/ |
|
203
|
|
|
|
|
204
|
|
|
public static function setField (int $selector, string $fieldName, $value): void |
|
205
|
|
|
{ |
|
206
|
|
|
\VoidCore::setField ($selector, $fieldName, $value); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* * Вызов метода объекта |
|
211
|
|
|
* |
|
212
|
|
|
* @param int $selector - указатель на объект |
|
213
|
|
|
* @param mixed $methodName - название метода |
|
214
|
|
|
* [@param mixed ...$args = []] - аргументы вызова метода |
|
215
|
|
|
* |
|
216
|
|
|
* @param mixed methodName так же может быть передан с указанием на тип возвращаемого методом значения через структуру вида |
|
217
|
|
|
* [название метода, возвращаемый им тип] |
|
218
|
|
|
* |
|
219
|
|
|
* @return mixed - возвращает результат выполнения метода |
|
220
|
|
|
* |
|
221
|
|
|
* $selector = VoidEngine::createClass ('System.Windows.Forms.MessageBox', 'System.Windows.Forms'); |
|
222
|
|
|
* |
|
223
|
|
|
* VoidEngine::callMethod ($selector, 'Show', 'Hello, World!', 'Test Box'); |
|
224
|
|
|
* VoidEngine::callMethod ($selector, 'Show', ['Hello, World!', 'string'], ['Test Box', 'string']); |
|
225
|
|
|
* |
|
226
|
|
|
* $result = VoidEngine::callMethod ($selector, ['Show', 'int'], ['Hello, World!', 'string'], ['Test Box', 'string']); |
|
227
|
|
|
* |
|
228
|
|
|
*/ |
|
229
|
|
|
|
|
230
|
|
|
public static function callMethod (int $selector, $methodName, ...$args) |
|
231
|
|
|
{ |
|
232
|
|
|
return \VoidCore::callMethod ($selector, $methodName, ...$args); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* * Получение значения массива |
|
237
|
|
|
* |
|
238
|
|
|
* @param int $selector - указатель на объект массива |
|
239
|
|
|
* @param mixed $index - индекс массива |
|
240
|
|
|
* |
|
241
|
|
|
* @param mixed $index так же может быть передан с указанием на тип возвращаемого значения через структуру вида |
|
242
|
|
|
* [индекс, возвращаемый тип] |
|
243
|
|
|
* |
|
244
|
|
|
* @return mixed - возвращает значение массива |
|
245
|
|
|
* |
|
246
|
|
|
*/ |
|
247
|
|
|
|
|
248
|
|
|
public static function getArrayValue (int $selector, $index) |
|
249
|
|
|
{ |
|
250
|
|
|
return \VoidCore::getArrayValue ($selector, $index); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* * Установка значения массива |
|
255
|
|
|
* |
|
256
|
|
|
* @param int $selector - указатель на объект массива |
|
257
|
|
|
* @param mixed $index - индекс массива |
|
258
|
|
|
* @param mixed $value - значение для установки |
|
259
|
|
|
* |
|
260
|
|
|
* @param mixed $index может быть передан с указанием на его тип через структуру вида |
|
261
|
|
|
* [индекс, тип] |
|
262
|
|
|
* |
|
263
|
|
|
* @param mixed value так же может быть передан с указанием на тип значения через структуру вида |
|
264
|
|
|
* [значение, тип] |
|
265
|
|
|
* |
|
266
|
|
|
*/ |
|
267
|
|
|
|
|
268
|
|
|
public static function setArrayValue (int $selector, $index, $value): void |
|
269
|
|
|
{ |
|
270
|
|
|
\VoidCore::setArrayValue ($selector, $index, $value); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* * Установка события объекту |
|
275
|
|
|
* |
|
276
|
|
|
* @param int $selector - указатель на объект |
|
277
|
|
|
* @param string $eventName - название события |
|
278
|
|
|
* @param callable $event - PHP коллбэк |
|
279
|
|
|
* |
|
280
|
|
|
* $selector = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
281
|
|
|
* VoidEngine::setObjectEvent ($selector, 'Click', function () { pre (123); }); |
|
282
|
|
|
* |
|
283
|
|
|
*/ |
|
284
|
|
|
|
|
285
|
|
|
public static function setObjectEvent (int $selector, string $eventName, callable $event): void |
|
286
|
|
|
{ |
|
287
|
|
|
/*if (self::eventExists ($selector, $eventName)) |
|
288
|
|
|
self::removeObjectEvent ($selector, $eventName);*/ |
|
289
|
|
|
|
|
290
|
|
|
\VoidCore::setEvent ($selector, $eventName, $event); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* * Проверка события объекта на существование |
|
295
|
|
|
* |
|
296
|
|
|
* @param int $selector - указатель на объект |
|
297
|
|
|
* @param string $eventName - название события |
|
298
|
|
|
* |
|
299
|
|
|
* @return bool - возвращает true в случае существования события |
|
300
|
|
|
* |
|
301
|
|
|
* $selector = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
302
|
|
|
* VoidEngine::setObjectEvent ($selector, 'Click', function () { pre (123); }); |
|
303
|
|
|
* |
|
304
|
|
|
* var_dump (VoidEngine::eventExists ($selector, 'Click')); // true |
|
305
|
|
|
* |
|
306
|
|
|
*/ |
|
307
|
|
|
|
|
308
|
|
|
public static function eventExists (int $selector, string $eventName): bool |
|
309
|
|
|
{ |
|
310
|
|
|
return \VoidCore::eventExists ($selector, $eventName); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* * Удаление события объекта |
|
315
|
|
|
* |
|
316
|
|
|
* @param int $selector - указатель на объект |
|
317
|
|
|
* @param string $eventName - название события |
|
318
|
|
|
* |
|
319
|
|
|
* $selector = VoidEngine::createObject ('System.Windows.Forms.Button', 'System.Windows.Forms'); |
|
320
|
|
|
* VoidEngine::setObjectEvent ($selector, 'Click', function () { pre (123); }); |
|
321
|
|
|
* VoidEngine::removeObjectEvent ($selector, 'Click'); |
|
322
|
|
|
* |
|
323
|
|
|
* var_dump (VoidEngine::eventExists ($selector, 'Click')); // false |
|
324
|
|
|
* |
|
325
|
|
|
*/ |
|
326
|
|
|
|
|
327
|
|
|
public static function removeObjectEvent (int $selector, string $eventName): void |
|
328
|
|
|
{ |
|
329
|
|
|
\VoidCore::removeEvent ($selector, $eventName); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* * Импортирование объекта в ядро |
|
334
|
|
|
* |
|
335
|
|
|
* @param string $data - сериализированные данные ядра |
|
336
|
|
|
* |
|
337
|
|
|
* @return int - возвращает указатель на импортированный объект |
|
338
|
|
|
* |
|
339
|
|
|
*/ |
|
340
|
|
|
|
|
341
|
|
|
public static function importObject (string $data): int |
|
342
|
|
|
{ |
|
343
|
|
|
return \VoidCore::importObject ($data); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* * Экспортирование объекта из ядра |
|
348
|
|
|
* |
|
349
|
|
|
* @param int $selector - указатель на объект |
|
350
|
|
|
* |
|
351
|
|
|
* @return string - возвращает сериализованные данные объекта |
|
352
|
|
|
* |
|
353
|
|
|
*/ |
|
354
|
|
|
|
|
355
|
|
|
public static function exportObject (int $selector): string |
|
356
|
|
|
{ |
|
357
|
|
|
return \VoidCore::exportObject ($selector); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* * Компиляция PHP кода |
|
362
|
|
|
* |
|
363
|
|
|
* TODO: дополнить описание |
|
364
|
|
|
* |
|
365
|
|
|
* @param string $savePath - путь для компиляции |
|
366
|
|
|
* @param string $iconPath - путь до иконки |
|
367
|
|
|
* @param string $phpCode - код для компиляции без тэгов |
|
368
|
|
|
* |
|
369
|
|
|
* [@param string $productDescription = null] - описание приложения |
|
370
|
|
|
* [@param string $productName = null] - название приложения |
|
371
|
|
|
* [@param string $productVersion = null] - версия приложения |
|
372
|
|
|
* [@param string $companyName = null] - компания-производителя |
|
373
|
|
|
* [@param string $copyright = null] - копирайт |
|
374
|
|
|
* [@param string $callSharpCode = ''] - чистый C# код |
|
375
|
|
|
* [@param string $declareSharpCode = ''] - C# код с объявлениями классов |
|
376
|
|
|
* |
|
377
|
|
|
* @return array - возвращает список ошибок компиляции |
|
378
|
|
|
* |
|
379
|
|
|
*/ |
|
380
|
|
|
|
|
381
|
|
|
public static function compile (string $savePath, string $iconPath, string $phpCode, string $productDescription = null, string $productName = null, string $productVersion = null, string $companyName = null, string $copyright = null, string $callSharpCode = '', string $declareSharpCode = '', WFObject $dictionary = null, WFObject $assemblies = null): array |
|
382
|
|
|
{ |
|
383
|
|
|
if ($dictionary === null) |
|
384
|
|
|
$dictionary = new WFObject ('System.Collections.Generic.Dictionary`2[System.String,System.String]', null); |
|
385
|
|
|
|
|
386
|
|
|
if ($assemblies === null) |
|
387
|
|
|
$assemblies = getNetArray ('System.String', [ |
|
388
|
|
|
// CORE_DIR .'/CefSharp.dll', |
|
389
|
|
|
CORE_DIR .'/FastColoredTextBox.dll', |
|
390
|
|
|
CORE_DIR .'/ScintillaNET.dll' |
|
391
|
|
|
]); |
|
392
|
|
|
|
|
393
|
|
|
if ($productName === null) |
|
394
|
|
|
$productName = basenameNoExt ($savePath); |
|
395
|
|
|
|
|
396
|
|
|
if ($productDescription === null) |
|
397
|
|
|
$productDescription = $productName; |
|
398
|
|
|
|
|
399
|
|
|
if ($productVersion === null) |
|
400
|
|
|
$productVersion = '1.0'; |
|
401
|
|
|
|
|
402
|
|
|
if ($companyName === null) |
|
403
|
|
|
$companyName = 'Company N'; |
|
404
|
|
|
|
|
405
|
|
|
if ($copyright === null) |
|
406
|
|
|
$copyright = $companyName .' copyright (c) '. date ('Y'); |
|
407
|
|
|
|
|
408
|
|
|
return (new WFClass ('WinForms_PHP.WFCompiler', null))->compile ($savePath, $iconPath, $phpCode, $productDescription, $productName, $productVersion, $companyName, $copyright, $callSharpCode, $declareSharpCode, $dictionary, $assemblies)->names; |
|
409
|
|
|
} |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
class EngineAdditions |
|
413
|
|
|
{ |
|
414
|
|
|
public static function loadModule (string $path): bool |
|
415
|
|
|
{ |
|
416
|
|
|
try |
|
417
|
|
|
{ |
|
418
|
|
|
(new WFClass ('System.Reflection.Assembly', 'mscorlib'))->loadFrom ($path); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
catch (\Throwable $e) |
|
422
|
|
|
{ |
|
423
|
|
|
return false; |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
return true; |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
public static function getProperty (int $selector, string $name): array |
|
430
|
|
|
{ |
|
431
|
|
|
$property = VoidEngine::callMethod (VoidEngine::callMethod ($selector, 'GetType'), 'GetProperty', $name); |
|
432
|
|
|
|
|
433
|
|
|
if (!is_int ($property)) |
|
434
|
|
|
return false; |
|
435
|
|
|
|
|
436
|
|
|
try |
|
437
|
|
|
{ |
|
438
|
|
|
$propertyType = VoidEngine::getProperty ($property, ['PropertyType', 'string']); |
|
439
|
|
|
|
|
440
|
|
|
switch ($propertyType) |
|
441
|
|
|
{ |
|
442
|
|
|
case 'System.String': |
|
443
|
|
|
$property = 'string'; |
|
444
|
|
|
break; |
|
445
|
|
|
|
|
446
|
|
|
case 'System.Int32': |
|
447
|
|
|
case 'System.Int64': |
|
448
|
|
|
$property = 'int'; |
|
449
|
|
|
break; |
|
450
|
|
|
|
|
451
|
|
|
case 'System.Double': |
|
452
|
|
|
$property = 'double'; |
|
453
|
|
|
break; |
|
454
|
|
|
|
|
455
|
|
|
case 'System.Single': |
|
456
|
|
|
$property = 'float'; |
|
457
|
|
|
break; |
|
458
|
|
|
|
|
459
|
|
|
case 'System.Boolean': |
|
460
|
|
|
$property = 'bool'; |
|
461
|
|
|
break; |
|
462
|
|
|
|
|
463
|
|
|
case 'System.IntPtr': |
|
464
|
|
|
$property = 'handle'; |
|
465
|
|
|
break; |
|
466
|
|
|
|
|
467
|
|
|
case 'System.Drawing.Color': |
|
468
|
|
|
$property = 'color'; |
|
469
|
|
|
break; |
|
470
|
|
|
|
|
471
|
|
|
default: |
|
472
|
|
|
try |
|
473
|
|
|
{ |
|
474
|
|
|
VoidEngine::getProperty ($selector, [$name, 'int']); |
|
475
|
|
|
|
|
476
|
|
|
$property = 'int'; |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
catch (\Throwable $e) |
|
480
|
|
|
{ |
|
481
|
|
|
return [ |
|
482
|
|
|
'type' => 'vrsf', |
|
483
|
|
|
'value' => VoidEngine::exportObject (VoidEngine::getProperty ($selector, [$name, 'object'])) |
|
484
|
|
|
]; |
|
485
|
|
|
} |
|
486
|
|
|
break; |
|
487
|
|
|
} |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
catch (\Throwable $e) |
|
491
|
|
|
{ |
|
492
|
|
|
$property = 'object'; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
return [ |
|
496
|
|
|
'type' => $property, |
|
497
|
|
|
'value' => VoidEngine::getProperty ($selector, [$name, $property]) |
|
498
|
|
|
]; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
public static function getObjectEvents (int $object): array |
|
502
|
|
|
{ |
|
503
|
|
|
$events = []; |
|
504
|
|
|
|
|
505
|
|
|
$props = VoidEngine::callMethod (VoidEngine::callMethod ($object, 'GetType'), 'GetEvents'); |
|
506
|
|
|
$len = VoidEngine::getProperty ($props, 'Length'); |
|
507
|
|
|
|
|
508
|
|
|
for ($i = 0; $i < $len; ++$i) |
|
509
|
|
|
$events[] = VoidEngine::getProperty (VoidEngine::getArrayValue ($props, $i), 'Name'); |
|
510
|
|
|
|
|
511
|
|
|
return $events; |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
/** |
|
515
|
|
|
* При вызове coupleSelector от object->selector указатель может быть обработан в WFObject |
|
516
|
|
|
* Тогда получается бесконечный цикл вида object->selector->selector->selector->... |
|
517
|
|
|
* Чтобы этого избежать нужно добавить исключение - переменную $selfSelector |
|
518
|
|
|
*/ |
|
519
|
|
|
public static function coupleSelector ($value, int $selfSelector = null) |
|
520
|
|
|
{ |
|
521
|
|
|
return is_int ($value) && VoidEngine::objectExists ($value) && $value != $selfSelector ? |
|
522
|
|
|
new WFObject ($value) : $value; |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
public static function uncoupleSelector ($value) |
|
526
|
|
|
{ |
|
527
|
|
|
return $value instanceof WFObject ? |
|
528
|
|
|
$value->selector : $value; |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
class WFObject implements \ArrayAccess |
|
533
|
|
|
{ |
|
534
|
|
|
protected int $selector = 0; |
|
|
|
|
|
|
535
|
|
|
protected ?string $name; |
|
536
|
|
|
|
|
537
|
|
|
public function __construct ($object, ?string $classGroup = 'auto', ...$args) |
|
538
|
|
|
{ |
|
539
|
|
|
foreach ($args as $id => $arg) |
|
540
|
|
|
$args[$id] = EngineAdditions::uncoupleSelector ($arg); |
|
541
|
|
|
|
|
542
|
|
|
if (is_string ($object)) |
|
543
|
|
|
$this->selector = VoidEngine::createObject ($object, $classGroup == 'auto' ? |
|
544
|
|
|
substr ($object, 0, strrpos ($object, '.')) : $classGroup, ...$args); |
|
545
|
|
|
|
|
546
|
|
|
elseif (is_int ($object) && VoidEngine::objectExists ($object)) |
|
547
|
|
|
$this->selector = $object; |
|
548
|
|
|
|
|
549
|
|
|
else throw new \Exception ('$object parameter must be string or object selector'); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
public function __get ($name) |
|
553
|
|
|
{ |
|
554
|
|
|
if (method_exists ($this, $method = "get_$name")) |
|
555
|
|
|
$value = $this->$method (); |
|
556
|
|
|
|
|
557
|
|
|
elseif (substr ($name, -5) == 'Event') |
|
558
|
|
|
$value = Events::getObjectEvent ($this->selector, substr ($name, 0, -5)); |
|
559
|
|
|
|
|
560
|
|
|
elseif (property_exists ($this, $name)) |
|
561
|
|
|
$value = $this->$name; |
|
562
|
|
|
|
|
563
|
|
|
else switch (strtolower ($name)) |
|
564
|
|
|
{ |
|
565
|
|
|
case 'count': |
|
566
|
|
|
case 'length': |
|
567
|
|
|
try |
|
568
|
|
|
{ |
|
569
|
|
|
return $this->getProperty ('Count'); |
|
570
|
|
|
} |
|
571
|
|
|
|
|
572
|
|
|
catch (\Throwable $e) |
|
573
|
|
|
{ |
|
574
|
|
|
return $this->getProperty ('Length'); |
|
575
|
|
|
} |
|
576
|
|
|
break; |
|
577
|
|
|
|
|
578
|
|
|
case 'list': |
|
579
|
|
|
$size = $this->count; |
|
580
|
|
|
$list = []; |
|
581
|
|
|
|
|
582
|
|
|
for ($i = 0; $i < $size; ++$i) |
|
583
|
|
|
$list[] = EngineAdditions::coupleSelector (VoidEngine::getArrayValue ($this->selector, $i)); |
|
584
|
|
|
|
|
585
|
|
|
return $list; |
|
586
|
|
|
break; |
|
587
|
|
|
|
|
588
|
|
|
case 'names': |
|
589
|
|
|
$size = $this->count; |
|
590
|
|
|
$names = []; |
|
591
|
|
|
|
|
592
|
|
|
for ($i = 0; $i < $size; ++$i) |
|
593
|
|
|
try |
|
594
|
|
|
{ |
|
595
|
|
|
$names[] = VoidEngine::getProperty (VoidEngine::getArrayValue ($this->selector, [$i, 'object']), 'Text'); |
|
596
|
|
|
} |
|
597
|
|
|
|
|
598
|
|
|
catch (\Throwable $e) |
|
599
|
|
|
{ |
|
600
|
|
|
$names[] = VoidEngine::getArrayValue ($this->selector, [$i, 'string']); |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
return $names; |
|
604
|
|
|
break; |
|
605
|
|
|
|
|
606
|
|
|
default: |
|
607
|
|
|
$value = $this->getProperty ($name); |
|
608
|
|
|
break; |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
return EngineAdditions::coupleSelector ($value, $this->selector); |
|
612
|
|
|
} |
|
613
|
|
|
|
|
614
|
|
|
public function __set ($name, $value) |
|
615
|
|
|
{ |
|
616
|
|
|
if (method_exists ($this, $method = "set_$name")) |
|
617
|
|
|
try |
|
618
|
|
|
{ |
|
619
|
|
|
return $this->$method ($value); |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
# Метод "set_$name" может принимать в качестве параметра объект WFObject |
|
623
|
|
|
# т.к. наверняка мы не уверены, какой тип ему нужен, то тут требуется дополнительная проверка |
|
624
|
|
|
|
|
625
|
|
|
catch (\Throwable $e) |
|
626
|
|
|
{ |
|
627
|
|
|
return $value instanceof WFObject ? |
|
628
|
|
|
$this->$method ($value->selector) : null; |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
elseif (substr ($name, -5) == 'Event') |
|
632
|
|
|
Events::setObjectEvent ($this->selector, substr ($name, 0, -5), $value); |
|
633
|
|
|
|
|
634
|
|
|
else $this->setProperty ($name, EngineAdditions::uncoupleSelector ($value)); |
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
|
|
public function __call ($method, $args) |
|
638
|
|
|
{ |
|
639
|
|
|
$args = array_map (function ($arg) |
|
640
|
|
|
{ |
|
641
|
|
|
return EngineAdditions::uncoupleSelector ($arg); |
|
642
|
|
|
}, $args); |
|
643
|
|
|
|
|
644
|
|
|
return EngineAdditions::coupleSelector ($this->callMethod ($method, ...$args), $this->selector); |
|
645
|
|
|
} |
|
646
|
|
|
|
|
647
|
|
|
public function addRange (array $values, $assoc = false): void |
|
648
|
|
|
{ |
|
649
|
|
|
foreach ($values as $id => $value) |
|
650
|
|
|
$this->offsetSet ($assoc ? $id : null, $value); |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
public function offsetSet ($index, $value) |
|
654
|
|
|
{ |
|
655
|
|
|
try |
|
656
|
|
|
{ |
|
657
|
|
|
return $index === null ? |
|
658
|
|
|
$this->callMethod ('Add', EngineAdditions::uncoupleSelector ($value)) : |
|
659
|
|
|
$this->callMethod ('Insert', $index, EngineAdditions::uncoupleSelector ($value)); |
|
660
|
|
|
} |
|
661
|
|
|
|
|
662
|
|
|
catch (\Throwable $e) |
|
663
|
|
|
{ |
|
664
|
|
|
return $index === null ? |
|
665
|
|
|
VoidEngine::setArrayValue ($this->selector, $this->count, $value) : |
|
666
|
|
|
VoidEngine::setArrayValue ($this->selector, $index, $value); |
|
667
|
|
|
} |
|
668
|
|
|
} |
|
669
|
|
|
|
|
670
|
|
|
public function offsetGet ($index) |
|
671
|
|
|
{ |
|
672
|
|
|
return EngineAdditions::coupleSelector (VoidEngine::getArrayValue ($this->selector, $index), $this->selector); |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
public function offsetUnset ($index): void |
|
676
|
|
|
{ |
|
677
|
|
|
$this->callMethod ('RemoveAt', $index); |
|
678
|
|
|
} |
|
679
|
|
|
|
|
680
|
|
|
public function offsetExists ($index): bool |
|
681
|
|
|
{ |
|
682
|
|
|
try |
|
683
|
|
|
{ |
|
684
|
|
|
$this->offsetGet ($index); |
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
catch (\Exception $e) |
|
688
|
|
|
{ |
|
689
|
|
|
return false; |
|
690
|
|
|
} |
|
691
|
|
|
|
|
692
|
|
|
return true; |
|
693
|
|
|
} |
|
694
|
|
|
|
|
695
|
|
|
public function indexOf ($value): int |
|
696
|
|
|
{ |
|
697
|
|
|
return $this->callMethod ('IndexOf', EngineAdditions::uncoupleSelector ($value)); |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
public function lastIndexOf ($value): int |
|
701
|
|
|
{ |
|
702
|
|
|
return $this->callMethod ('LastIndexOf', EngineAdditions::uncoupleSelector ($value)); |
|
703
|
|
|
} |
|
704
|
|
|
|
|
705
|
|
|
public function contains ($value): bool |
|
706
|
|
|
{ |
|
707
|
|
|
return $this->callMethod ('Contains', EngineAdditions::uncoupleSelector ($value)); |
|
708
|
|
|
} |
|
709
|
|
|
|
|
710
|
|
|
public function foreach (callable $callback, string $type = null): void |
|
711
|
|
|
{ |
|
712
|
|
|
$size = $this->count; |
|
713
|
|
|
|
|
714
|
|
|
for ($i = 0; $i < $size; ++$i) |
|
715
|
|
|
$callback (EngineAdditions::coupleSelector (VoidEngine::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i); |
|
716
|
|
|
} |
|
717
|
|
|
|
|
718
|
|
|
public function where (callable $comparator, string $type = null): array |
|
719
|
|
|
{ |
|
720
|
|
|
$size = $this->count; |
|
721
|
|
|
$return = []; |
|
722
|
|
|
|
|
723
|
|
|
for ($i = 0; $i < $size; ++$i) |
|
724
|
|
|
if ($comparator ($value = EngineAdditions::coupleSelector (VoidEngine::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i)) |
|
725
|
|
|
$return[] = $value; |
|
726
|
|
|
|
|
727
|
|
|
return $return; |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
protected function getProperty ($name) |
|
731
|
|
|
{ |
|
732
|
|
|
try |
|
733
|
|
|
{ |
|
734
|
|
|
return VoidEngine::getProperty ($this->selector, $name); |
|
735
|
|
|
} |
|
736
|
|
|
|
|
737
|
|
|
catch (\Throwable $e) |
|
738
|
|
|
{ |
|
739
|
|
|
return VoidEngine::getField ($this->selector, $name); |
|
740
|
|
|
} |
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
|
protected function setProperty ($name, $value) |
|
744
|
|
|
{ |
|
745
|
|
|
try |
|
746
|
|
|
{ |
|
747
|
|
|
VoidEngine::setProperty ($this->selector, $name, $value); |
|
748
|
|
|
} |
|
749
|
|
|
|
|
750
|
|
|
catch (\Throwable $e) |
|
751
|
|
|
{ |
|
752
|
|
|
VoidEngine::setField ($this->selector, $name, $value); |
|
753
|
|
|
} |
|
754
|
|
|
} |
|
755
|
|
|
|
|
756
|
|
|
protected function callMethod ($method, ...$args) |
|
757
|
|
|
{ |
|
758
|
|
|
return VoidEngine::callMethod ($this->selector, $method, ...$args); |
|
759
|
|
|
} |
|
760
|
|
|
|
|
761
|
|
|
protected function getArrayProperty ($name, string $type = null) |
|
762
|
|
|
{ |
|
763
|
|
|
$array = $this->getProperty ($name); |
|
764
|
|
|
$size = VoidEngine::getProperty ($array, 'Length'); |
|
765
|
|
|
$return = []; |
|
766
|
|
|
|
|
767
|
|
|
for ($i = 0; $i < $size; ++$i) |
|
768
|
|
|
$return[] = VoidEngine::getArrayValue ($array, $type === null ? $i : [$i, $type]); |
|
769
|
|
|
|
|
770
|
|
|
VoidEngine::removeObjects ($array); |
|
771
|
|
|
|
|
772
|
|
|
return $return; |
|
773
|
|
|
} |
|
774
|
|
|
|
|
775
|
|
|
public function get_name () |
|
776
|
|
|
{ |
|
777
|
|
|
try |
|
778
|
|
|
{ |
|
779
|
|
|
return $this->getProperty ('Name'); |
|
780
|
|
|
} |
|
781
|
|
|
|
|
782
|
|
|
catch (\Throwable $e) |
|
783
|
|
|
{ |
|
784
|
|
|
return $this->name; |
|
785
|
|
|
} |
|
786
|
|
|
} |
|
787
|
|
|
|
|
788
|
|
|
public function set_name (string $name) |
|
789
|
|
|
{ |
|
790
|
|
|
try |
|
791
|
|
|
{ |
|
792
|
|
|
$this->setProperty ('Name', $name); |
|
793
|
|
|
} |
|
794
|
|
|
|
|
795
|
|
|
catch (\Throwable $e) |
|
796
|
|
|
{ |
|
797
|
|
|
$this->name = $name; |
|
798
|
|
|
} |
|
799
|
|
|
} |
|
800
|
|
|
|
|
801
|
|
|
public function __toString (): string |
|
802
|
|
|
{ |
|
803
|
|
|
return $this->callMethod ('ToString'); |
|
804
|
|
|
} |
|
805
|
|
|
} |
|
806
|
|
|
|
|
807
|
|
|
class WFClass extends WFObject |
|
808
|
|
|
{ |
|
809
|
|
|
public function __construct ($class, ?string $classGroup = 'auto') |
|
810
|
|
|
{ |
|
811
|
|
|
if (is_string ($class)) |
|
812
|
|
|
$this->selector = VoidEngine::createClass ($class, $classGroup == 'auto' ? |
|
813
|
|
|
substr ($class, 0, strrpos ($class, '.')) : $classGroup |
|
814
|
|
|
); |
|
815
|
|
|
|
|
816
|
|
|
elseif (is_int ($class) && VoidEngine::objectExists ($class)) |
|
817
|
|
|
$this->selector = $class; |
|
818
|
|
|
|
|
819
|
|
|
else throw new \Exception ('$class parameter must be string or class selector'); |
|
820
|
|
|
} |
|
821
|
|
|
} |
|
822
|
|
|
|