forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
phpUtils.pas
105 lines (83 loc) · 2.27 KB
/
phpUtils.pas
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
unit phpUtils;
interface
uses
SysUtils,
zendTypes,
ZENDAPI,
phpTypes,
PHPAPI,
Variants;
type
TArrayString = array of string;
var
tmpAR: TArrayVariant;
tmpAR2: TArrayString;
MT: TMethod;
var
prs: TArrayVariant;
function readPr(param: pzval_array; index: integer): variant;
procedure readPrs(param: pzval_array; ht: integer);
function checkPrs(ht, Count: integer; var TSRMLS_DC: pointer): boolean;
function checkPrs2(ht: integer; var Params: pzval_array;
var TSRMLS_DC: pointer): boolean;
procedure regConstL(Name: string; Value: integer);
procedure regConstD(Name: string; Value: double);
procedure regConstS(Name: string; Value: string);
procedure regConstList(Names: array of string; From: integer = 0);
procedure evalCode(Code: string);
implementation
procedure regConstList(Names: array of string; From: integer = 0);
var
i: integer;
begin
for i := 0 to high(Names) do
regConstL(Names[i], i + from);
end;
procedure regConstL(Name: string; Value: integer);
begin
REGISTER_MAIN_LONG_CONSTANT(zend_pchar(zend_ustr(Name)), Value, 0, ts_resource(0));
end;
procedure regConstD(Name: string; Value: double);
begin
REGISTER_MAIN_DOUBLE_CONSTANT(zend_pchar(zend_ustr(Name)), Value, 0, ts_resource(0));
end;
procedure regConstS(Name: string; Value: string);
begin
REGISTER_MAIN_STRING_CONSTANT(zend_pchar(zend_ustr(Name)), zend_pchar(zend_ustr(Value)), 0, ts_resource(0));
end;
procedure evalCode(Code: string);
begin
zend_eval_string(zend_pchar(zend_ustr(Code)), nil, 'eval code', ts_resource(0));
end;
function readPr(param: pzval_array; index: integer): variant;
begin
Result := ZendToVariant(param[index]^);
end;
procedure readPrs(param: pzval_array; ht: integer);
var
i: integer;
begin
SetLength(prs, 0);
SetLength(prs, ht);
for i := 0 to ht - 1 do
prs[i] := readPr(param, i);
end;
function checkPrs(ht, Count: integer; var TSRMLS_DC: pointer): boolean;
begin
Result := True;
if ht < Count then
begin
zend_wrong_param_count(TSRMLS_DC);
Result := False;
end;
end;
function checkPrs2(ht: integer; var Params: pzval_array; var TSRMLS_DC: pointer): boolean;
begin
Result := True;
if (not (zend_get_parameters_my(ht, Params, TSRMLS_DC) = SUCCESS)) then
begin
zend_wrong_param_count(TSRMLS_DC);
Result := False;
end;
end;
end.