Merge pull request #259 from davidcole1340/function-helper

Add function type helper function
This commit is contained in:
Daniil Gentili 2023-11-24 13:56:21 +01:00 committed by GitHub
commit 80e448c0a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -6,6 +6,8 @@ use crate::{
types::{ZendClassObject, ZendObject, Zval},
};
use super::function::Function;
/// Execute data passed when a function is called from PHP.
///
/// This generally contains things related to the call, including but not
@ -194,6 +196,16 @@ impl ExecuteData {
self.This.object_mut()
}
/// Attempt to retrieve the function that is being called.
pub fn function(&self) -> Option<&Function> {
unsafe { self.func.as_ref() }
}
/// Attempt to retrieve the previous execute data on the call stack.
pub fn previous(&self) -> Option<&Self> {
unsafe { self.prev_execute_data.as_ref() }
}
/// Translation of macro `ZEND_CALL_ARG(call, n)`
/// zend_compile.h:578
///

View File

@ -9,6 +9,7 @@ use crate::{
zend_call_known_function, zend_fetch_function_str, zend_function, zend_function_entry,
zend_hash_str_find_ptr_lc,
},
flags::FunctionType,
types::Zval,
};
@ -50,6 +51,10 @@ impl FunctionEntry {
pub type Function = zend_function;
impl Function {
pub fn function_type(&self) -> FunctionType {
FunctionType::from(unsafe { self.type_ })
}
pub fn try_from_function(name: &str) -> Option<Self> {
unsafe {
let res = zend_fetch_function_str(name.as_ptr() as *const c_char, name.len());