@@ -13,7 +13,7 @@ use std::{
1313 ptr:: { null, null_mut} ,
1414} ;
1515
16- pub const fn create_zend_module_entry (
16+ pub struct ModuleEntryBuilder {
1717 name : * const c_char ,
1818 version : * const c_char ,
1919 functions : * const zend_function_entry ,
@@ -24,35 +24,125 @@ pub const fn create_zend_module_entry(
2424 info_func : Option < unsafe extern "C" fn ( * mut zend_module_entry ) > ,
2525 globals_ctor : Option < unsafe extern "C" fn ( global : * mut c_void ) > ,
2626 globals_dtor : Option < unsafe extern "C" fn ( global : * mut c_void ) > ,
27- ) -> zend_module_entry {
28- zend_module_entry {
29- size : size_of :: < zend_module_entry > ( ) as c_ushort ,
30- zend_api : ZEND_MODULE_API_NO as c_uint ,
31- zend_debug : ZEND_DEBUG as c_uchar ,
32- zts : USING_ZTS as c_uchar ,
33- ini_entry : null ( ) ,
34- deps : null ( ) ,
35- name,
36- functions,
37- module_startup_func,
38- module_shutdown_func,
39- request_startup_func,
40- request_shutdown_func,
41- info_func,
42- version,
43- globals_size : 0usize ,
44- #[ cfg( phper_zts) ]
45- globals_id_ptr : std:: ptr:: null_mut ( ) ,
46- #[ cfg( not( phper_zts) ) ]
47- globals_ptr : std:: ptr:: null_mut ( ) ,
48- globals_ctor,
49- globals_dtor,
50- post_deactivate_func : None ,
51- module_started : 0 ,
52- type_ : 0 ,
53- handle : null_mut ( ) ,
54- module_number : 0 ,
55- build_id : PHP_MODULE_BUILD_ID ,
27+ }
28+
29+ impl ModuleEntryBuilder {
30+ pub const fn new ( name : * const c_char , version : * const c_char ) -> Self {
31+ Self {
32+ name,
33+ version,
34+ functions : null ( ) ,
35+ module_startup_func : None ,
36+ module_shutdown_func : None ,
37+ request_startup_func : None ,
38+ request_shutdown_func : None ,
39+ info_func : None ,
40+ globals_ctor : None ,
41+ globals_dtor : None ,
42+ }
43+ }
44+
45+ pub const fn functions ( self , functions : * const zend_function_entry ) -> Self {
46+ Self { functions, ..self }
47+ }
48+
49+ pub const fn module_startup_func (
50+ self ,
51+ module_startup_func : unsafe extern "C" fn ( c_int , c_int ) -> c_int ,
52+ ) -> Self {
53+ Self {
54+ module_startup_func : Some ( module_startup_func) ,
55+ ..self
56+ }
57+ }
58+
59+ pub const fn module_shutdown_func (
60+ self ,
61+ module_shutdown_func : unsafe extern "C" fn ( c_int , c_int ) -> c_int ,
62+ ) -> Self {
63+ Self {
64+ module_shutdown_func : Some ( module_shutdown_func) ,
65+ ..self
66+ }
67+ }
68+
69+ pub const fn request_startup_func (
70+ self ,
71+ request_startup_func : unsafe extern "C" fn ( c_int , c_int ) -> c_int ,
72+ ) -> Self {
73+ Self {
74+ request_startup_func : Some ( request_startup_func) ,
75+ ..self
76+ }
77+ }
78+
79+ pub const fn request_shutdown_func (
80+ self ,
81+ request_shutdown_func : unsafe extern "C" fn ( c_int , c_int ) -> c_int ,
82+ ) -> Self {
83+ Self {
84+ request_shutdown_func : Some ( request_shutdown_func) ,
85+ ..self
86+ }
87+ }
88+
89+ pub const fn info_func ( self , info_func : unsafe extern "C" fn ( * mut zend_module_entry ) ) -> Self {
90+ Self {
91+ info_func : Some ( info_func) ,
92+ ..self
93+ }
94+ }
95+
96+ pub const fn globals_ctor (
97+ self ,
98+ globals_ctor : unsafe extern "C" fn ( global : * mut c_void ) ,
99+ ) -> Self {
100+ Self {
101+ globals_ctor : Some ( globals_ctor) ,
102+ ..self
103+ }
104+ }
105+
106+ pub const fn globals_dtor (
107+ self ,
108+ globals_dtor : unsafe extern "C" fn ( global : * mut c_void ) ,
109+ ) -> Self {
110+ Self {
111+ globals_dtor : Some ( globals_dtor) ,
112+ ..self
113+ }
114+ }
115+
116+ pub const fn build ( self ) -> ModuleEntry {
117+ ModuleEntry :: new ( zend_module_entry {
118+ size : size_of :: < zend_module_entry > ( ) as c_ushort ,
119+ zend_api : ZEND_MODULE_API_NO as c_uint ,
120+ zend_debug : ZEND_DEBUG as c_uchar ,
121+ zts : USING_ZTS as c_uchar ,
122+ ini_entry : null ( ) ,
123+ deps : null ( ) ,
124+ name : self . name ,
125+ functions : self . functions ,
126+ module_startup_func : self . module_startup_func ,
127+ module_shutdown_func : self . module_shutdown_func ,
128+ request_startup_func : self . request_startup_func ,
129+ request_shutdown_func : self . request_shutdown_func ,
130+ info_func : self . info_func ,
131+ version : self . version ,
132+ globals_size : 0usize ,
133+ #[ cfg( phper_zts) ]
134+ globals_id_ptr : std:: ptr:: null_mut ( ) ,
135+ #[ cfg( not( phper_zts) ) ]
136+ globals_ptr : std:: ptr:: null_mut ( ) ,
137+ globals_ctor : self . globals_ctor ,
138+ globals_dtor : self . globals_dtor ,
139+ post_deactivate_func : None ,
140+ module_started : 0 ,
141+ type_ : 0 ,
142+ handle : null_mut ( ) ,
143+ module_number : 0 ,
144+ build_id : PHP_MODULE_BUILD_ID ,
145+ } )
56146 }
57147}
58148
0 commit comments