Skip to content

Commit 80e448c

Browse files
authored
Merge pull request #259 from davidcole1340/function-helper
Add function type helper function
2 parents 3f50e7e + 10d5f3a commit 80e448c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/zend/ex.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{
66
types::{ZendClassObject, ZendObject, Zval},
77
};
88

9+
use super::function::Function;
10+
911
/// Execute data passed when a function is called from PHP.
1012
///
1113
/// This generally contains things related to the call, including but not
@@ -194,6 +196,16 @@ impl ExecuteData {
194196
self.This.object_mut()
195197
}
196198

199+
/// Attempt to retrieve the function that is being called.
200+
pub fn function(&self) -> Option<&Function> {
201+
unsafe { self.func.as_ref() }
202+
}
203+
204+
/// Attempt to retrieve the previous execute data on the call stack.
205+
pub fn previous(&self) -> Option<&Self> {
206+
unsafe { self.prev_execute_data.as_ref() }
207+
}
208+
197209
/// Translation of macro `ZEND_CALL_ARG(call, n)`
198210
/// zend_compile.h:578
199211
///

src/zend/function.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
zend_call_known_function, zend_fetch_function_str, zend_function, zend_function_entry,
1010
zend_hash_str_find_ptr_lc,
1111
},
12+
flags::FunctionType,
1213
types::Zval,
1314
};
1415

@@ -50,6 +51,10 @@ impl FunctionEntry {
5051
pub type Function = zend_function;
5152

5253
impl Function {
54+
pub fn function_type(&self) -> FunctionType {
55+
FunctionType::from(unsafe { self.type_ })
56+
}
57+
5358
pub fn try_from_function(name: &str) -> Option<Self> {
5459
unsafe {
5560
let res = zend_fetch_function_str(name.as_ptr() as *const c_char, name.len());

0 commit comments

Comments
 (0)