ext_php_rs/zend/
mod.rs

1//! Types used to interact with the Zend engine.
2
3mod _type;
4pub mod ce;
5mod class;
6mod ex;
7mod function;
8mod globals;
9mod handlers;
10mod ini_entry_def;
11mod linked_list;
12mod module;
13mod streams;
14mod try_catch;
15
16use crate::{
17    error::Result,
18    ffi::{php_printf, sapi_module},
19};
20use std::ffi::CString;
21
22pub use _type::ZendType;
23pub use class::ClassEntry;
24pub use ex::ExecuteData;
25pub use function::Function;
26pub use function::FunctionEntry;
27pub use globals::ExecutorGlobals;
28pub use globals::FileGlobals;
29pub use globals::ProcessGlobals;
30pub use globals::SapiGlobals;
31pub use globals::SapiModule;
32pub use handlers::ZendObjectHandlers;
33pub use ini_entry_def::IniEntryDef;
34pub use linked_list::ZendLinkedList;
35pub use module::ModuleEntry;
36pub use streams::*;
37#[cfg(feature = "embed")]
38pub(crate) use try_catch::panic_wrapper;
39pub use try_catch::{bailout, try_catch, try_catch_first};
40
41// Used as the format string for `php_printf`.
42const FORMAT_STR: &[u8] = b"%s\0";
43
44/// Prints to stdout using the `php_printf` function.
45///
46/// Also see the [`php_print`] and [`php_println`] macros.
47///
48/// # Arguments
49///
50/// * message - The message to print to stdout.
51///
52/// # Returns
53///
54/// Nothing on success, error if the message could not be converted to a
55/// [`CString`].
56pub fn printf(message: &str) -> Result<()> {
57    let message = CString::new(message)?;
58    unsafe {
59        php_printf(FORMAT_STR.as_ptr().cast(), message.as_ptr());
60    };
61    Ok(())
62}
63
64/// Get the name of the SAPI module.
65pub fn php_sapi_name() -> String {
66    let c_str = unsafe { std::ffi::CStr::from_ptr(sapi_module.name) };
67    c_str.to_str().expect("Unable to parse CStr").to_string()
68}