pub struct ModuleBuilder { /* 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 {
    ModuleBuilder::new("ext-name", "ext-version")
        .info_function(php_module_info)
        .build()
        .unwrap()
        .into_raw()
}

Implementations§

source§

impl ModuleBuilder

source

pub fn new<T: Into<String>, U: Into<String>>(name: T, version: U) -> 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.
source

pub fn startup_function( self, func: 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.
source

pub fn shutdown_function( self, func: 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.
source

pub fn request_startup_function( self, func: 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.
source

pub fn request_shutdown_function( self, func: 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.
source

pub fn post_deactivate_function(self, func: 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.
source

pub fn info_function( self, func: 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.
source

pub fn function(self, func: FunctionEntry) -> Self

Adds a function to the extension.

§Arguments
  • func - The function to be added to the extension.
source

pub fn build(self) -> Result<ModuleEntry>

Builds the extension and returns a ModuleEntry.

Returns a result containing the module entry if successful.

Trait Implementations§

source§

impl Clone for ModuleBuilder

source§

fn clone(&self) -> ModuleBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ModuleBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.