-
Notifications
You must be signed in to change notification settings - Fork 16
/
PHPCommon.pas
406 lines (347 loc) · 9.31 KB
/
PHPCommon.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
{*******************************************************}
{ PHP4Delphi }
{ PHP - Delphi interface }
{ }
{ Developers: }
{ Serhiy Perevoznyk }
{ serge_perevoznyk@hotmail.com }
{ Michael Maroszek }
{ maroszek@gmx.net }
{ }
{ http://users.chello.be/ws36637 }
{*******************************************************}
{$I PHP.INC}
{ $Id: phpcommon.pas,v 6.2 02/2006 delphi32 Exp $ }
unit PHPCommon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ZendTypes, ZendAPI, PHPTypes, PHPAPI;
type
EDelphiErrorEx = class(Exception);
EPHPErrorEx = class(Exception);
TPHPErrorType = (
etError, //0
etWarning, //1
etParse, //2
etNotice,
etCoreError,
etCoreWarning,
etCompileError,
etCompileWarning,
etUserError,
etUserWarning,
etUserNotice,
etUnknown);
TPHPExecuteMethod = (emServer, emGet);
TPHPAboutInfo = (abPHP4Delphi);
TPHPVariable = class(TCollectionItem)
private
FName : string;
FValue : string;
function GetAsBoolean: boolean;
function GetAsFloat: double;
function GetAsInteger: integer;
procedure SetAsBoolean(const Value: boolean);
procedure SetAsFloat(const Value: double);
procedure SetAsInteger(const Value: integer);
protected
function GetDisplayName : string; override;
public
property AsInteger : integer read GetAsInteger write SetAsInteger;
property AsBoolean : boolean read GetAsBoolean write SetAsBoolean;
property AsString : string read FValue write FValue;
property AsFloat : double read GetAsFloat write SetAsFloat;
published
property Name : string read FName write FName;
property Value : string read FValue write FValue;
end;
TPHPVariables = class(TCollection)
private
FOwner : TComponent;
procedure SetItem(Index: Integer; const Value: TPHPVariable);
function GetItem(Index: Integer): TPHPVariable;
protected
function GetOwner : TPersistent; override;
public
function Add: TPHPVariable;
constructor Create(AOwner: TComponent);
function GetVariables : string;
function IndexOf(AName : string) : integer;
procedure AddRawString(AString : string);
property Items[Index: Integer]: TPHPVariable read GetItem write SetItem; default;
function ByName(AName : string) : TPHPVariable;
end;
TPHPConstant = class(TCollectionItem)
private
FName : string;
FValue : string;
protected
function GetDisplayName : string; override;
published
property Name : string read FName write FName;
property Value : string read FValue write FValue;
end;
TPHPConstants = class(TCollection)
private
FOwner : TComponent;
procedure SetItem(Index: Integer; const Value: TPHPConstant);
function GetItem(Index: Integer): TPHPConstant;
protected
function GetOwner : TPersistent; override;
public
function Add: TPHPConstant;
constructor Create(AOwner: TComponent);
function IndexOf(AName : string) : integer;
property Items[Index: Integer]: TPHPConstant read GetItem write SetItem; default;
end;
TPHPHeader = class(TCollectionItem)
private
FHeader : String;
published
property Header : string read FHeader write FHeader;
end;
TPHPHeaders = class(TCollection)
private
FOwner : TComponent;
procedure SetItem(Index: Integer; const Value: TPHPHeader);
function GetItem(Index: Integer): TPHPHeader;
protected
function GetOwner : TPersistent; override;
public
function Add: TPHPHeader;
constructor Create(AOwner: TComponent);
function GetHeaders : string;
property Items[Index: Integer]: TPHPHeader read GetItem write SetItem; default;
end;
TPHPComponent = class(TComponent)
private
FAbout : TPHPAboutInfo;
protected
public
published
property About : TPHPAboutInfo read FAbout write FAbout stored False;
end;
implementation
{ TPHPVariables }
function TPHPVariables.Add: TPHPVariable;
begin
result := TPHPVariable(inherited Add);
end;
constructor TPHPVariables.Create(AOwner: TComponent);
begin
inherited create(TPHPVariable);
FOwner := AOwner;
end;
function TPHPVariables.GetItem(Index: Integer): TPHPVariable;
begin
Result := TPHPVariable(inherited GetItem(Index));
end;
procedure TPHPVariables.SetItem(Index: Integer; const Value: TPHPVariable);
begin
inherited SetItem(Index, Value)
end;
function TPHPVariables.GetOwner : TPersistent;
begin
Result := FOwner;
end;
function TPHPVariables.GetVariables: string;
var i : integer;
begin
for i := 0 to Count - 1 do
begin
Result := Result + Items[i].FName + '=' + Items[i].FValue;
if i < Count - 1 then
Result := Result + '&';
end;
end;
function TPHPVariables.IndexOf(AName: string): integer;
var
i : integer;
begin
Result := -1;
for i := 0 to Count - 1 do
begin
if SameText(Items[i].Name, AName) then
begin
Result := i;
break;
end;
end;
end;
procedure TPHPVariables.AddRawString(AString : string);
var
SL : TStringList;
i : integer;
j : integer;
V : TPHPVariable;
begin
if AString[Length(AString)] = ';' then
SetLength(AString, Length(AString)-1);
SL := TStringList.Create;
ExtractStrings([';'], [], PChar(AString), SL);
for i := 0 to SL.Count - 1 do
begin
j := IndexOf(SL.Names[i]);
if j= -1 then
begin
V := Add;
V.Name := SL.Names[i];
V.Value := Copy(SL[I], Length(SL.Names[i]) + 2, MaxInt);
end
else
begin
Items[j].Value := Copy(SL[I], Length(SL.Names[i]) + 2, MaxInt);
end;
end;
SL.Free;
end;
function TPHPVariables.ByName(AName: string): TPHPVariable;
var
i : integer;
begin
Result := nil;
for i := 0 to Count - 1 do
begin
if SameText(Items[i].Name, AName) then
begin
Result := Items[i];
break;
end;
end;
end;
{ TPHPVariable }
function TPHPVariable.GetAsBoolean: boolean;
begin
if FValue = '' then
begin
Result := false;
Exit;
end;
if SameText(FValue, 'True') then
Result := true
else
Result := false;
end;
function TPHPVariable.GetAsFloat: double;
begin
if FValue = '' then
begin
Result := 0;
Exit;
end;
Result := ValueToFloat(FValue);
end;
function TPHPVariable.GetAsInteger: integer;
var
c : char;
begin
c := DecimalSeparator;
DecimalSeparator := '.';
Result := Round(ValueToFloat(FValue));
DecimalSeparator := c;
end;
function TPHPVariable.GetDisplayName: string;
begin
if FName = '' then
result := inherited GetDisplayName
else
Result := FName;
end;
procedure TPHPVariable.SetAsBoolean(const Value: boolean);
begin
if Value then
FValue := 'True'
else
FValue := 'False';
end;
procedure TPHPVariable.SetAsFloat(const Value: double);
begin
FValue := FloatToValue(Value);
end;
procedure TPHPVariable.SetAsInteger(const Value: integer);
var
c : char;
begin
c := DecimalSeparator;
DecimalSeparator := '.';
FValue := IntToStr(Value);
DecimalSeparator := c;
end;
{ TPHPConstant }
function TPHPConstant.GetDisplayName: string;
begin
if FName = '' then
result := inherited GetDisplayName
else
Result := FName;
end;
{ TPHPConstants }
function TPHPConstants.Add: TPHPConstant;
begin
result := TPHPConstant(inherited Add);
end;
constructor TPHPConstants.Create(AOwner: TComponent);
begin
inherited create(TPHPConstant);
FOwner := AOwner;
end;
function TPHPConstants.GetItem(Index: Integer): TPHPConstant;
begin
Result := TPHPConstant(inherited GetItem(Index));
end;
function TPHPConstants.GetOwner: TPersistent;
begin
Result := FOwner;
end;
function TPHPConstants.IndexOf(AName: string): integer;
var
i : integer;
begin
Result := -1;
for i := 0 to Count - 1 do
begin
if SameText(Items[i].Name, AName) then
begin
Result := i;
break;
end;
end;
end;
procedure TPHPConstants.SetItem(Index: Integer; const Value: TPHPConstant);
begin
inherited SetItem(Index, Value)
end;
{ TPHPHeaders }
function TPHPHeaders.Add: TPHPHeader;
begin
result := TPHPHeader(inherited Add);
end;
constructor TPHPHeaders.Create(AOwner: TComponent);
begin
inherited create(TPHPHeader);
FOwner := AOwner;
end;
function TPHPHeaders.GetItem(Index: Integer): TPHPHeader;
begin
Result := TPHPHeader(inherited GetItem(Index));
end;
procedure TPHPHeaders.SetItem(Index: Integer; const Value: TPHPHeader);
begin
inherited SetItem(Index, Value)
end;
function TPHPHeaders.GetOwner : TPersistent;
begin
Result := FOwner;
end;
function TPHPHeaders.GetHeaders: string;
var i : integer;
begin
for i := 0 to Count - 1 do
begin
Result := Result + Items[i].FHeader;
if i < Count - 1 then
Result := Result + #13#10;
end;
end;
end.