Skip to content

Commit 618d3b6

Browse files
author
Andrew Zenin
committed
Added custom embedded extensions support
1 parent 4c7cc09 commit 618d3b6

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed

Source/PHPAPI.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ procedure variant2zval(value : variant; var z : pzval);
218218

219219
php_raw_url_encode: function (s : zend_pchar; len : Integer; new_length : PInteger) : zend_pchar; cdecl;
220220

221-
{$IFDEF PHP510}
222-
php_register_extensions: function (ptr : pointer; count: integer; TSRMLS_DC: pointer) : integer; cdecl;
221+
{$IFDEF PHP5}
222+
php_register_extensions: function (ptr : PPzend_module_entry; count: integer; TSRMLS_DC: pointer) : integer; cdecl;
223223
{$ELSE}
224224
php_startup_extensions: function (ptr: pointer; count : integer) : integer; cdecl;
225225
{$ENDIF}
@@ -802,7 +802,7 @@ function LoadPHP(const DllFileName: zend_ustr = PHPWin) : boolean;
802802

803803
php_raw_url_encode := GetProcAddress(PHPLib, 'php_raw_url_encode');
804804

805-
{$IFDEF PHP510}
805+
{$IFDEF PHP5}
806806
php_register_extensions := GetProcAddress(PHPLib, 'php_register_extensions');
807807
{$ELSE}
808808
php_startup_extensions := GetProcAddress(PHPLib, 'php_startup_extensions');
@@ -866,7 +866,7 @@ procedure CheckPHPErrors;
866866
if @php_url_encode = nil then raise EPHP4DelphiException.Create('php_url_encode');
867867
if @php_raw_url_encode = nil then raise EPHP4DelphiException.Create('php_raw_url_encode');
868868

869-
{$IFDEF PHP510}
869+
{$IFDEF PHP5}
870870
if @php_register_extensions = nil then raise EPHP4DelphiException.Create('php_register_extensions');
871871
{$ELSE}
872872
if @php_startup_extensions = nil then raise EPHP4DelphiException.Create('php_startup_extensions');

Source/ZENDAPI.pas

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,12 @@ procedure ZEND_PUTS(str: zend_pchar);
729729
var
730730
zend_register_internal_class : function(class_entry: pzend_class_entry; TSRMLS_DC: pointer): Pzend_class_entry; cdecl;
731731
zend_register_internal_class_ex : function(class_entry: pzend_class_entry; parent_ce: pzend_class_entry; parent_name: zend_pchar; TSRMLS_DC: pointer): Pzend_class_entry; cdecl;
732+
zend_startup_module : function(module_entry: Pzend_module_entry):integer; cdecl;
733+
zend_startup_module_ex : function(module_entry: Pzend_module_entry; TSRMLS_DC: pointer):integer; cdecl;
734+
zend_register_module_ex : function(module_entry: Pzend_module_entry; TSRMLS_DC: pointer): Pzend_module_entry;cdecl;
735+
zend_register_internal_module : function(module_entry: Pzend_module_entry; TSRMLS_DC: pointer): Pzend_module_entry;cdecl;
736+
zend_startup_modules : function(TSRMLS_DC:pointer):integer;
737+
zend_collect_module_handlers : function(TSRMLS_DC:pointer):integer;
732738
function ZvalInt(z:zval):Integer;
733739
function ZvalDouble(z:zval):Double;
734740
function ZvalBool(z:zval):Boolean;
@@ -2922,12 +2928,30 @@ function LoadZEND(const DllFilename: zend_ustr = PHPWin) : boolean;
29222928
// -- _object_and_properties_init
29232929
_object_and_properties_init := GetProcAddress(PHPLib, '_object_and_properties_init');
29242930

2925-
// -- zend_register_internal_class
2931+
// -- zend_register_internal_class
29262932
zend_register_internal_class := GetProcAddress(PHPLib, 'zend_register_internal_class');
29272933

29282934
// -- zend_register_internal_class_ex
29292935
zend_register_internal_class_ex := GetProcAddress(PHPLib, 'zend_register_internal_class_ex');
29302936

2937+
// -- zend_startup_module
2938+
zend_startup_module := GetProcAddress(PHPLib, 'zend_startup_module');
2939+
2940+
// -- zend_startup_module_ex
2941+
zend_startup_module_ex := GetProcAddress(PHPLib, 'zend_startup_module_ex');
2942+
2943+
// -- zend_register_module_ex
2944+
zend_register_module_ex := GetProcAddress(PHPLib, 'zend_register_module_ex');
2945+
2946+
// -- zend_register_internal_module
2947+
zend_register_internal_module := GetProcAddress(PHPLib, 'zend_register_internal_module');
2948+
2949+
// -- zend_startup_modules
2950+
zend_startup_modules := GetProcAddress(PHPLib, 'zend_startup_modules');
2951+
2952+
// -- zend_collect_module_handlers
2953+
zend_collect_module_handlers := GetProcAddress(PHPLib, 'zend_collect_module_handlers');
2954+
29312955
// -- get_zend_version
29322956
get_zend_version := GetProcAddress(PHPLib, 'get_zend_version');
29332957

@@ -3431,6 +3455,13 @@ procedure CheckZendErrors;
34313455
if @_object_and_properties_init = nil then raise EPHP4DelphiException.Create('_object_and_properties_init');
34323456
if @zend_register_internal_class = nil then raise EPHP4DelphiException.Create('zend_register_internal_class');
34333457
if @zend_register_internal_class_ex = nil then raise EPHP4DelphiException.Create('zend_register_internal_class_ex');
3458+
if @zend_startup_module = nil then raise EPHP4DelphiException.Create('zend_startup_module');
3459+
if @zend_startup_module_ex = nil then raise EPHP4DelphiException.Create('zend_startup_module_ex');
3460+
if @zend_register_module_ex = nil then raise EPHP4DelphiException.Create('zend_register_module_ex');
3461+
if @zend_register_internal_module = nil then raise EPHP4DelphiException.Create('zend_register_internal_module');
3462+
if @zend_startup_modules = nil then raise EPHP4DelphiException.Create('zend_startup_modules');
3463+
if @zend_collect_module_handlers = nil then raise EPHP4DelphiException.Create('zend_collect_module_handlers');
3464+
34343465
if @get_zend_version = nil then raise EPHP4DelphiException.Create('get_zend_version');
34353466
if @zend_make_printable_zval = nil then raise EPHP4DelphiException.Create('zend_make_printable_zval');
34363467
if @zend_print_zval = nil then raise EPHP4DelphiException.Create('zend_print_zval');

Source/ZendTypes.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ _zend_function_entry = record
12041204
end;
12051205
{$ENDIF}
12061206
Pzend_module_entry = ^Tzend_module_entry;
1207+
PPzend_module_entry = ^Pzend_module_entry;
12071208
p_zend_module_entry = ^_zend_module_entry;
12081209
_zend_module_entry = record
12091210
size : word;

Source/php4delphi.pas

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,12 @@ TCustomPHPLibrary = class(TPHPComponent)
194194
property Locked : boolean read FLocked write FLocked;
195195
end;
196196
{ TPHPEngine }
197-
197+
TPHPEngineInitEvent = procedure(Sender:TObject;TSRMLS_DC:Pointer) of object;
198198
TPHPEngine = class(TPHPComponent, IUnknown, IPHPEngine)
199199
private
200200
FINIPath : AnsiString;
201201
FOnEngineStartup : TNotifyEvent;
202+
FAddMods : TArray<Pzend_module_entry>;
202203
FOnEngineShutdown : TNotifyEvent;
203204
FEngineActive : boolean;
204205
FHandleErrors : boolean;
@@ -245,6 +246,7 @@ TPHPEngine = class(TPHPComponent, IUnknown, IPHPEngine)
245246
constructor Create(AOwner : TComponent); override;
246247
destructor Destroy; override;
247248
procedure AddFunction(FN: zend_ustr; Func: Pointer);
249+
procedure AddModule(Module_entry: Pzend_module_entry);
248250
procedure StartupEngine; virtual;
249251
procedure ShutdownEngine; virtual;
250252
procedure LockEngine; virtual;
@@ -1285,7 +1287,6 @@ procedure TpsvCustomPHP.StartupRequest;
12851287
FOnReadPost(Self, FPostStream);
12861288

12871289
zend_alter_ini_entry('max_execution_time', 19, zend_pchar(TimeStr), Length(TimeStr), ZEND_INI_SYSTEM, ZEND_INI_STAGE_RUNTIME);
1288-
12891290
php_request_startup(TSRMLS_D);
12901291
if Assigned(FOnRequestStartup) then
12911292
FOnRequestStartup(Self);
@@ -1340,7 +1341,6 @@ procedure TpsvCustomPHP.ShutdownRequest;
13401341

13411342
end;
13421343

1343-
13441344
procedure TpsvCustomPHP.PrepareVariables;
13451345
var
13461346
ht : {$IFDEF PHP7}Pzend_array{$ELSE}PHashTable{$ENDIF};
@@ -1904,6 +1904,7 @@ procedure TPHPEngine.RefreshLibrary;
19041904
procedure TPHPEngine.StartupEngine;
19051905
var
19061906
i : integer;
1907+
x: Pzend_module_entry;
19071908
begin
19081909
if PHPEngine <> Self then
19091910
begin
@@ -1943,8 +1944,14 @@ procedure TPHPEngine.StartupEngine;
19431944

19441945
php_module_startup(@delphi_sapi_module, @FLibraryModule, 1);
19451946

1946-
19471947
TSRMLS_D := ts_resource_ex(0, nil);
1948+
if Length(FAddMods) > 0 then
1949+
for x in FAddMods do
1950+
begin
1951+
zend_register_module_ex(x, TSRMLS_D);
1952+
zend_startup_module_ex(x, TSRMLS_D);
1953+
end;
1954+
19481955

19491956
PrepareIniEntry;
19501957
RegisterConstants;
@@ -2059,8 +2066,18 @@ procedure TPHPEngine.UnlockLibraries;
20592066
end;
20602067

20612068
procedure TPHPEngine.RemoveRequest;
2069+
var
2070+
x: Pzend_module_entry;
2071+
xp: function(_type : integer; module_number : integer; TSRMLS_DC : pointer):integer;cdecl;
20622072
begin
20632073
InterlockedDecrement(FRequestCount);
2074+
if Length(FAddMods) > 0 then
2075+
for x in FAddMods do
2076+
begin
2077+
xp := x^.request_shutdown_func;
2078+
if(Assigned(xp)) then
2079+
xp(x^._type, x^.module_number, TSRMLS_D);
2080+
end;
20642081
end;
20652082

20662083
procedure TPHPEngine.AddFunction(FN: zend_ustr; Func: Pointer);
@@ -2069,9 +2086,25 @@ procedure TPHPEngine.AddFunction(FN: zend_ustr; Func: Pointer);
20692086
MyFuncs.AddObject(FN, TObject(Func));
20702087
end;
20712088

2089+
procedure TPHPEngine.AddModule(Module_entry: Pzend_module_entry);
2090+
begin
2091+
SetLength(FAddMods, Length(FAddMods)+1);
2092+
FAddMods[High(FAddMods)] := Module_entry;
2093+
end;
2094+
20722095
procedure TPHPEngine.AddRequest;
2096+
var
2097+
x: Pzend_module_entry;
2098+
xp: function(_type : integer; module_number : integer; TSRMLS_DC : pointer):integer;cdecl;
20732099
begin
20742100
InterlockedIncrement(FRequestCount);
2101+
if Length(FAddMods) > 0 then
2102+
for x in FAddMods do
2103+
begin
2104+
xp := x^.request_startup_func;
2105+
if(Assigned(xp)) then
2106+
xp(x^._type, x^.module_number, TSRMLS_D);
2107+
end;
20752108
end;
20762109

20772110
initialization

0 commit comments

Comments
 (0)