-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathPHPProjectWizard.pas
583 lines (485 loc) · 14 KB
/
PHPProjectWizard.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
{*******************************************************}
{ PHP4Delphi }
{ PHP - Delphi interface }
{ }
{ Author: }
{ Serhiy Perevoznyk }
{ http://users.chello.be/ws36637 }
{*******************************************************}
{$I PHP.INC}
{ $Id: PHPProjectWizard.pas,v 6.2 02/2006 delphi32 Exp $ }
unit PHPProjectWizard;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ToolsAPI,
{$IFDEF VERSION6}
DesignIntf,
DesignEditors,
DMForm,
{$ELSE}
dsgnintf,
dmdesigner,
{$ENDIF}
PHPModules;
type
TPHPProjectWizard = class(TNotifierObject, IOTAWizard,
{$IFDEF VERSION10}IOTAREpositoryWizard, IOTARepositoryWizard60,
IOTARepositoryWizard80, {$ELSE}IOTARepositoryWizard, {$ENDIF} IOTAProjectWizard)
public
// IOTAWizard
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
// IOTARepositoryWizard
function GetAuthor: string;
function GetComment: string;
function GetPage: string;
{$IFDEF VERSION10}
function GetGalleryCategory: IOTAGalleryCategory;
function GetPersonality: string;
function GetDesigner: string;
{$ENDIF}
{$IFDEF VERSION6}
function GetGlyph : cardinal;
{$ELSE}
function GetGlyph: HICON;
{$ENDIF}
end;
TPHPProjectCreator = class(TInterfacedObject, IOTACreator, IOTAProjectCreator {$IFDEF VERSION9},IOTAProjectCreator80{$ENDIF})
public
// IOTACreator
function GetCreatorType: string;
function GetExisting: Boolean;
function GetFileSystem: string;
function GetOwner: IOTAModule;
function GetUnnamed: Boolean;
// IOTAProjectCreator
function GetFileName: string;
function GetOptionFileName: string;
function GetShowSource: Boolean;
procedure NewDefaultModule;
function NewOptionSource(const ProjectName: string): IOTAFile;
procedure NewProjectResource(const Project: IOTAProject);
function NewProjectSource(const ProjectName: string): IOTAFile;
{$IFDEF VERSION9}
function GetProjectPersonality: string;
procedure NewDefaultProjectModule(const Project: IOTAProject);
{$ENDIF}
end;
TPHPProjectSourceFile = class(TInterfacedObject, IOTAFile)
private
FSource: string;
FProjectName : string;
public
function GetSource: string;
function GetAge: TDateTime;
constructor Create(const Source: string);
constructor CreateNamedProject(AProjectName : string);
end;
TPHPModuleCreator = class(TInterfacedObject, IOTACreator, IOTAModuleCreator)
public
// IOTACreator
function GetCreatorType: string;
function GetExisting: Boolean;
function GetFileSystem: string;
function GetOwner: IOTAModule;
function GetUnnamed: Boolean;
// IOTAModuleCreator
function GetAncestorName: string;
function GetImplFileName: string;
function GetIntfFileName: string;
function GetFormName: string;
function GetMainForm: Boolean;
function GetShowForm: Boolean;
function GetShowSource: Boolean;
function NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
function NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
procedure FormCreated(const FormEditor: IOTAFormEditor);
end;
TPHPExtensionSourceFile = class(TInterfacedObject, IOTAFile)
private
FSource: string;
public
function GetSource: string;
function GetAge: TDateTime;
constructor Create(const Source: string);
end;
procedure Register;
implementation
{$R PHPProjectwizard.RES}
const
CRLF = #13#10;
procedure Register;
begin
RegisterPackageWizard(TPHPProjectWizard.Create);
end;
function GetActiveProjectGroup: IOTAProjectGroup;
var
ModuleServices: IOTAModuleServices;
i: Integer;
begin
Result := nil;
ModuleServices := BorlandIDEServices as IOTAModuleServices;
for i := 0 to ModuleServices.ModuleCount - 1 do
if Succeeded(ModuleServices.Modules[i].QueryInterface(IOTAProjectGroup, Result)) then
Break;
end;
{ TPHPProjectWizard }
{$IFDEF VERSION10}
function TPHPProjectWizard.GetGalleryCategory: IOTAGalleryCategory;
begin
Result := (BorlandIDEServices as IOTAGalleryCategoryManager).FindCategory(sCategoryDelphiNew);
end;
function TPHPProjectWizard.GetPersonality: string;
begin
Result := sDelphiPersonality;
end;
function TPHPProjectWizard.GetDesigner : string;
begin
Result := dVCL;
end;
{$ENDIF}
procedure TPHPProjectWizard.Execute;
begin
try
(BorlandIDEServices as IOTAModuleServices).CreateModule(TPHPProjectCreator.Create as {$IFDEF VERSION9}IOTAProjectCreator80{$ELSE}IOTAProjectCreator{$ENDIF});
(BorlandIDEServices as IOTAModuleServices).CreateModule(TPHPModuleCreator.Create as IOTAModuleCreator );
except
MessageDlg('PHP Project Wizard error while generate'+#13+#10+'project''s sources.', mtError, [mbOK], 0);
end;
end;
function TPHPProjectWizard.GetAuthor: string;
begin
Result := 'Perevoznyk';
end;
function TPHPProjectWizard.GetComment: string;
begin
Result := 'PHP Project Creator';
end;
{$IFDEF VERSION6}
function TPHPProjectWizard.GetGlyph: cardinal;
{$ELSE}
function TPHPProjectWizard.GetGlyph: HICON;
{$ENDIF}
begin
Result := LoadIcon(hInstance, 'PHPWIZARDICO');
end;
function TPHPProjectWizard.GetIDString: string;
begin
Result := '{74D480FC-0608-4D34-AEA6-643728BD3CB9}';
end;
function TPHPProjectWizard.GetName: string;
begin
Result := 'PHP Extension';
end;
function TPHPProjectWizard.GetPage: string;
begin
{$IFDEF VERSION10}
Result := 'Delphi Files';
{$ELSE}
Result := 'New';
{$ENDIF}
end;
function TPHPProjectWizard.GetState: TWizardState;
begin
Result := [wsEnabled];
end;
{ TPHPProjectCreator }
function TPHPProjectCreator.GetCreatorType: string;
begin
Result := sLibrary;
end;
function TPHPProjectCreator.GetExisting: Boolean;
begin
Result := False; // Create a new project
end;
function TPHPProjectCreator.GetFileName: string;
{$IFNDEF VERSION9}
var
i: Integer;
j: Integer;
ProjGroup: IOTAProjectGroup;
Found: Boolean;
TempFileName: string;
TempFileName2: string;
{$ENDIF}
begin
{$IFDEF VERSION9}
Result := '';
{$ELSE}
Result := GetCurrentDir + '\' + 'Project%d' + '.dpr'; { do not localize }
ProjGroup := GetActiveProjectGroup;
if ProjGroup <> nil then
begin
for j := 0 to ProjGroup.ProjectCount-1 do
begin
Found := False;
TempFileName2 := Format(Result, [j+1]);
for i := 0 to ProjGroup.ProjectCount-1 do
begin
try
TempFileName := ProjGroup.Projects[i].FileName;
if AnsiCompareFileName(ExtractFileName(TempFileName), ExtractFileName(TempFileName2)) = 0 then
begin
Found := True;
Break;
end;
except on E: Exception do
if not (E is EIntfCastError) then
raise;
end;
end;
if not Found then
begin
Result := TempFileName2;
Exit;
end;
end;
Result := Format(Result, [ProjGroup.ProjectCount+1]);
end
else
Result := Format(Result, [1]);
{$ENDIF}
end;
function TPHPProjectCreator.GetFileSystem: string;
begin
Result := ''; // Default
end;
function TPHPProjectCreator.GetOptionFileName: string;
begin
Result := ''; // Default
end;
function TPHPProjectCreator.GetOwner: IOTAModule;
begin
Result := GetActiveProjectGroup;
end;
{$IFDEF VERSION9}
function TPHPProjectCreator.GetProjectPersonality: string;
begin
Result := sDelphiPersonality;
end;
{$ENDIF}
function TPHPProjectCreator.GetShowSource: Boolean;
begin
Result := True; // Show the source in the editor
end;
function TPHPProjectCreator.GetUnnamed: Boolean;
begin
Result := True; // Project needs to be named/saved
end;
procedure TPHPProjectCreator.NewDefaultModule;
begin
end;
{$IFDEF VERSION9}
procedure TPHPProjectCreator.NewDefaultProjectModule(
const Project: IOTAProject);
begin
NewDefaultModule;
end;
{$ENDIF}
function TPHPProjectCreator.NewOptionSource(const ProjectName: string): IOTAFile;
begin
Result := nil; // For BCB only
end;
procedure TPHPProjectCreator.NewProjectResource(const Project: IOTAProject);
begin
// No resources needed
end;
function TPHPProjectCreator.NewProjectSource(const ProjectName: string): IOTAFile;
begin
Result := TPHPProjectSourceFile.CreateNamedProject(ProjectName) as IOTAFile;
end;
{ TPHPProjectSourceFile }
constructor TPHPProjectSourceFile.Create(const Source: string);
begin
FSource := Source;
end;
constructor TPHPProjectSourceFile.CreateNamedProject(AProjectName: string);
begin
inherited Create;
FProjectName := AProjectName;
end;
function TPHPProjectSourceFile.GetAge: TDateTime;
begin
Result := -1;
end;
function TPHPProjectSourceFile.GetSource: string;
var
ProjectSource : string;
begin
ProjectSource :=
'library '+FProjectName+';' + CRLF +
CRLF +
'uses' + CRLF +
' Windows,'+ CRLF +
' SysUtils,'+ CRLF +
' phpApp,' + CRLF +
' phpModules;'+ CRLF;
ProjectSource := ProjectSource +
CRLF+
'{$R *.RES}' + CRLF +
CRLF +
'begin' + CRLF +
' Application.Initialize;' + CRLF +
' Application.Run;' + CRLF +
'end.';
Result := ProjectSource;
end;
{ TPHPModuleCreator }
procedure TPHPModuleCreator.FormCreated(const FormEditor: IOTAFormEditor);
begin
// Nothing
end;
function TPHPModuleCreator.GetAncestorName: string;
begin
Result := 'PHPExtension';
end;
function TPHPModuleCreator.GetCreatorType: string;
begin
// Return sUnit or sText as appropriate
Result := sForm;
end;
function TPHPModuleCreator.GetExisting: Boolean;
begin
Result := False;
end;
function TPHPModuleCreator.GetFileSystem: string;
begin
Result := '';
end;
function TPHPModuleCreator.GetFormName: string;
begin
Result := '';
end;
function TPHPModuleCreator.GetImplFileName: string;
begin
Result := '';
end;
function TPHPModuleCreator.GetIntfFileName: string;
begin
Result := '';
end;
function TPHPModuleCreator.GetMainForm: Boolean;
begin
Result := False;
end;
function TPHPModuleCreator.GetOwner: IOTAModule;
{$IFNDEF VERSION9}
var
ModuleServices: IOTAModuleServices;
Module: IOTAModule;
NewModule: IOTAModule;
{$ENDIF}
begin
{$IFDEF VERSION9}
Result := nil;
{$ELSE}
// You may prefer to return the project group's ActiveProject instead
Result := nil;
ModuleServices := (BorlandIDEServices as IOTAModuleServices);
Module := ModuleServices.CurrentModule;
if Module <> nil then
begin
if Module.QueryInterface(IOTAProject, NewModule) = S_OK then
Result := NewModule
{$IFDEF VERSION5ONLY} // Delphi 5
else if Module.GetOwnerCount > 0 then
begin
NewModule := Module.GetOwner(0);
{$ELSE} // Delphi 6+
else if Module.OwnerModuleCount > 0 then
begin
NewModule := Module.OwnerModules[0];
{$ENDIF}
if NewModule <> nil then
if NewModule.QueryInterface(IOTAProject, Result) <> S_OK then
Result := nil;
end;
end;
{$ENDIF}
end;
function TPHPModuleCreator.GetShowForm: Boolean;
begin
Result := True;
end;
function TPHPModuleCreator.GetShowSource: Boolean;
begin
Result := True;
end;
function TPHPModuleCreator.GetUnnamed: Boolean;
begin
Result := True;
end;
function TPHPModuleCreator.NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
begin
Result := nil;
end;
function TPHPModuleCreator.NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
var
Form,
Ancestor : string;
st : string;
begin
Form := FormIdent;
Ancestor := AncestorIdent;
St:= 'unit ' + ModuleIdent + ';' + CRLF + CRLF +
'interface' + CRLF + CRLF +
'uses' + CRLF +
' Windows,' + CRLF +
' Messages,' + CRLF +
' SysUtils,' + CRLF +
' Classes,' + CRLF +
' Forms,' + CRLF +
' zendTypes,'+ CRLF +
' zendAPI,' + CRLF +
' phpTypes,' + CRLF +
' phpAPI,' + CRLF +
' phpFunctions,' + CRLF +
' PHPModules;' + CRLF + CRLF +
'type' + CRLF + CRLF +
' T' + Form + ' = class(T' + Ancestor + ')' + CRLF +
' private' + CRLF +
' { Private declarations }' + CRLF +
' public' + CRLF +
' { Public declarations }' + CRLF +
' end;' + CRLF + CRLF +
'var' + CRLF +
' ' +Form + ': T' + Form + ';'+ CRLF + CRLF +
'implementation' + CRLF + CRLF +
'{$R *.DFM}' + CRLF + CRLF +
'end.' ;
Result := TPHPExtensionSourceFile.Create(St);
end;
function TPHPModuleCreator.NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
begin
Result := nil;
end;
constructor TPHPExtensionSourceFile.Create(const Source: string);
begin
FSource := Source;
end;
function TPHPExtensionSourceFile.GetAge: TDateTime;
begin
Result := -1;
end;
function TPHPExtensionSourceFile.GetSource: string;
begin
Result := FSource;
end;
{ RegisterContainerModule }
procedure RegisterContainerModule;
begin
{$IFDEF VERSION5ONLY}
RegisterCustomModule(TPHPExtension, TDataModuleDesignerCustomModule);
{$ELSE}
RegisterCustomModule(TPHPExtension, TDataModuleCustomModule);
{$ENDIF}
end;
Initialization
RegisterContainerModule();
Finalization
end.