1mod _type;
4mod bailout_guard;
5pub mod ce;
6mod class;
7#[cfg(feature = "observer")]
8pub(crate) mod error_observer;
9mod ex;
10#[cfg(feature = "observer")]
11pub(crate) mod exception_observer;
12mod function;
13mod globals;
14mod handlers;
15mod ini_entry_def;
16mod linked_list;
17mod module;
18pub(crate) mod module_globals;
19#[cfg(feature = "observer")]
20pub(crate) mod observer;
21mod streams;
22mod try_catch;
23
24use crate::{
25 error::Result,
26 ffi::{php_output_write, php_printf, sapi_module},
27};
28use std::ffi::CString;
29use std::os::raw::c_char;
30
31pub use _type::ZendType;
32pub use bailout_guard::BailoutGuard;
33pub use bailout_guard::run_bailout_cleanups;
34pub use class::ClassEntry;
35#[cfg(feature = "observer")]
36pub use error_observer::{BacktraceFrame, ErrorInfo, ErrorObserver, ErrorType};
37pub use ex::ExecuteData;
38#[cfg(feature = "observer")]
39pub use exception_observer::{ExceptionInfo, ExceptionObserver};
40pub use function::Function;
41pub use function::FunctionEntry;
42pub use globals::ExecutorGlobals;
43pub use globals::FileGlobals;
44pub use globals::ProcessGlobals;
45pub use globals::SapiGlobals;
46pub use globals::SapiHeader;
47pub use globals::SapiHeaders;
48pub use globals::SapiModule;
49pub use handlers::ZendObjectHandlers;
50pub use ini_entry_def::IniEntryDef;
51pub use linked_list::ZendLinkedList;
52pub use module::{ModuleEntry, StaticModuleEntry, cleanup_module_allocations};
53pub use module_globals::{ModuleGlobal, ModuleGlobals};
54#[cfg(feature = "observer")]
55pub use observer::{FcallInfo, FcallObserver};
56pub use streams::*;
57#[cfg(feature = "embed")]
58pub(crate) use try_catch::panic_wrapper;
59pub use try_catch::{CatchError, bailout, try_catch, try_catch_first};
60
61const FORMAT_STR: &[u8] = b"%s\0";
63
64pub fn printf(message: &str) -> Result<()> {
76 let message = CString::new(message)?;
77 unsafe {
78 php_printf(FORMAT_STR.as_ptr().cast(), message.as_ptr());
79 };
80 Ok(())
81}
82
83pub fn write(data: &[u8]) -> Result<usize> {
114 unsafe {
115 if let Some(ub_write) = sapi_module.ub_write {
116 Ok(ub_write(data.as_ptr().cast::<c_char>(), data.len()))
117 } else {
118 Err(crate::error::Error::SapiWriteUnavailable)
119 }
120 }
121}
122
123#[inline]
155#[must_use]
156pub fn output_write(data: &[u8]) -> usize {
157 unsafe { php_output_write(data.as_ptr().cast::<c_char>(), data.len()) }
158}
159
160pub fn php_sapi_name() -> String {
168 let c_str = unsafe { std::ffi::CStr::from_ptr(sapi_module.name) };
169 c_str.to_str().expect("Unable to parse CStr").to_string()
170}