pub struct ModuleBuilder<'a> { /* private fields */ }
Expand description
Builds a Zend module extension to be registered with PHP. Must be called
from within an external function called get_module
, returning a mutable
pointer to a ModuleEntry
.
use ext_php_rs::{
builders::ModuleBuilder,
zend::ModuleEntry,
info_table_start, info_table_end, info_table_row
};
#[no_mangle]
pub extern "C" fn php_module_info(_module: *mut ModuleEntry) {
info_table_start!();
info_table_row!("column 1", "column 2");
info_table_end!();
}
#[no_mangle]
pub extern "C" fn get_module() -> *mut ModuleEntry {
let (entry, _) = ModuleBuilder::new("ext-name", "ext-version")
.info_function(php_module_info)
.try_into()
.unwrap();
entry.into_raw()
}
Implementations§
Source§impl ModuleBuilder<'_>
impl ModuleBuilder<'_>
Sourcepub fn new(name: impl Into<String>, version: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self
Creates a new module builder with a given name and version.
§Arguments
name
- The name of the extension.version
- The current version of the extension.
Sourcepub fn startup_function(
self,
func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32,
) -> Self
pub fn startup_function( self, func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32, ) -> Self
Sets the startup function for the extension.
§Arguments
func
- The function to be called on startup.
Sourcepub fn shutdown_function(
self,
func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32,
) -> Self
pub fn shutdown_function( self, func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32, ) -> Self
Sets the shutdown function for the extension.
§Arguments
func
- The function to be called on shutdown.
Sourcepub fn request_startup_function(
self,
func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32,
) -> Self
pub fn request_startup_function( self, func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32, ) -> Self
Sets the request startup function for the extension.
§Arguments
func
- The function to be called when startup is requested.
Sourcepub fn request_shutdown_function(
self,
func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32,
) -> Self
pub fn request_shutdown_function( self, func: unsafe extern "C" fn(_type: i32, _module_number: i32) -> i32, ) -> Self
Sets the request shutdown function for the extension.
§Arguments
func
- The function to be called when shutdown is requested.
Sourcepub fn post_deactivate_function(
self,
func: unsafe extern "C" fn() -> i32,
) -> Self
pub fn post_deactivate_function( self, func: unsafe extern "C" fn() -> i32, ) -> Self
Sets the post request shutdown function for the extension.
This function can be useful if you need to do any final cleanup at the very end of a request, after all other resources have been released. For example, if your extension creates any persistent resources that last beyond a single request, you could use this function to clean those up.
§Arguments
func
- The function to be called when shutdown is requested.
Sourcepub fn info_function(
self,
func: unsafe extern "C" fn(zend_module: *mut ModuleEntry),
) -> Self
pub fn info_function( self, func: unsafe extern "C" fn(zend_module: *mut ModuleEntry), ) -> Self
Sets the extension information function for the extension.
§Arguments
func
- The function to be called to retrieve the information about the extension.
Sourcepub fn function(self, func: FunctionBuilder<'static>) -> Self
pub fn function(self, func: FunctionBuilder<'static>) -> Self
Sourcepub fn constant(
self,
const: (&str, impl IntoConst + Send + 'static, DocComments),
) -> Self
pub fn constant( self, const: (&str, impl IntoConst + Send + 'static, DocComments), ) -> Self
Adds a constant to the extension.
§Arguments
const
- Tuple containing the name, value and doc comments for the constant. This is a tuple to support thewrap_constant
macro.
Sourcepub fn class<T: RegisteredClass>(self) -> Self
pub fn class<T: RegisteredClass>(self) -> Self
Trait Implementations§
Source§impl<'a> Debug for ModuleBuilder<'a>
impl<'a> Debug for ModuleBuilder<'a>
Source§impl<'a> Default for ModuleBuilder<'a>
impl<'a> Default for ModuleBuilder<'a>
Source§fn default() -> ModuleBuilder<'a>
fn default() -> ModuleBuilder<'a>
Source§impl From<ModuleBuilder<'_>> for Module
Builds a Module
from a ModuleBuilder
.
This is used to generate the PHP stubs for the module.
impl From<ModuleBuilder<'_>> for Module
Builds a Module
from a ModuleBuilder
.
This is used to generate the PHP stubs for the module.
Source§fn from(builder: ModuleBuilder<'_>) -> Self
fn from(builder: ModuleBuilder<'_>) -> Self
Source§impl TryFrom<ModuleBuilder<'_>> for (ModuleEntry, ModuleStartup)
Builds a ModuleEntry
and ModuleStartup
from a ModuleBuilder
.
This is the entry point for the module to be registered with PHP.
impl TryFrom<ModuleBuilder<'_>> for (ModuleEntry, ModuleStartup)
Builds a ModuleEntry
and ModuleStartup
from a ModuleBuilder
.
This is the entry point for the module to be registered with PHP.