PHPER Framework首頁、文檔和下載- 用純Rust 開發PHP 擴展- 程式开发

這是一個支持用純Rust 開發PHP 擴展的框架,可以有效利用Rust生態,主要是對Zend API的封裝。

PHPER 的意思是PHP Enjoy Rust。

文檔

https://docs.rs/phper

教程

https://docs.rs/phper-doc/

示例


use phper::{echo, functions::Argument, modules::Module, php_get_module, values::ZVal};

/// The php function, receive arguments with type `ZVal`.
fn say_hello(arguments: &mut [ZVal]) -> phper::Result<()> {
    // Get the first argument, expect the type `ZStr`, and convert to Rust utf-8
    // str.
    let name = arguments[0].expect_z_str()?.to_str()?;

    // Macro which do php internal `echo`.
    echo!("Hello, {}!\n", name);

    Ok(())
}

/// This is the entry of php extension, the attribute macro `php_get_module`
/// will generate the `extern "C" fn`.
#[php_get_module]
pub fn get_module() -> Module {
    // New `Module` with extension info.
    let mut module = Module::new(
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_VERSION"),
        env!("CARGO_PKG_AUTHORS"),
    );

    // Register function `say_hello`, with one argument `name`.
    module.add_function("say_hello", say_hello).argument(Argument::by_val("name"));

    module
}

#PHPER #Framework首頁文檔和下載 #用純Rust #開發PHP #擴展 #程式开发

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *