Struct ext_php_rs::ffi::_zend_class_entry
source · #[repr(C)]pub struct _zend_class_entry {Show 46 fields
pub type_: c_char,
pub name: *mut zend_string,
pub __bindgen_anon_1: _zend_class_entry__bindgen_ty_1,
pub refcount: c_int,
pub ce_flags: u32,
pub default_properties_count: c_int,
pub default_static_members_count: c_int,
pub default_properties_table: *mut zval,
pub default_static_members_table: *mut zval,
pub static_members_table__ptr: *mut zval,
pub function_table: HashTable,
pub properties_info: HashTable,
pub constants_table: HashTable,
pub mutable_data__ptr: *mut zend_class_mutable_data,
pub inheritance_cache: *mut zend_inheritance_cache_entry,
pub properties_info_table: *mut *mut _zend_property_info,
pub constructor: *mut zend_function,
pub destructor: *mut zend_function,
pub clone: *mut zend_function,
pub __get: *mut zend_function,
pub __set: *mut zend_function,
pub __unset: *mut zend_function,
pub __isset: *mut zend_function,
pub __call: *mut zend_function,
pub __callstatic: *mut zend_function,
pub __tostring: *mut zend_function,
pub __debugInfo: *mut zend_function,
pub __serialize: *mut zend_function,
pub __unserialize: *mut zend_function,
pub iterator_funcs_ptr: *mut zend_class_iterator_funcs,
pub arrayaccess_funcs_ptr: *mut zend_class_arrayaccess_funcs,
pub __bindgen_anon_2: _zend_class_entry__bindgen_ty_2,
pub get_iterator: Option<unsafe extern "C" fn(ce: *mut zend_class_entry, object: *mut zval, by_ref: c_int) -> *mut zend_object_iterator>,
pub get_static_method: Option<unsafe extern "C" fn(ce: *mut zend_class_entry, method: *mut zend_string) -> *mut zend_function>,
pub serialize: Option<unsafe extern "C" fn(object: *mut zval, buffer: *mut *mut c_uchar, buf_len: *mut usize, data: *mut zend_serialize_data) -> c_int>,
pub unserialize: Option<unsafe extern "C" fn(object: *mut zval, ce: *mut zend_class_entry, buf: *const c_uchar, buf_len: usize, data: *mut zend_unserialize_data) -> c_int>,
pub num_interfaces: u32,
pub num_traits: u32,
pub __bindgen_anon_3: _zend_class_entry__bindgen_ty_3,
pub trait_names: *mut zend_class_name,
pub trait_aliases: *mut *mut zend_trait_alias,
pub trait_precedences: *mut *mut zend_trait_precedence,
pub attributes: *mut HashTable,
pub enum_backing_type: u32,
pub backed_enum_table: *mut HashTable,
pub info: _zend_class_entry__bindgen_ty_4,
}
Fields§
§type_: c_char
§name: *mut zend_string
§__bindgen_anon_1: _zend_class_entry__bindgen_ty_1
§refcount: c_int
§ce_flags: u32
§default_properties_count: c_int
§default_static_members_count: c_int
§default_properties_table: *mut zval
§default_static_members_table: *mut zval
§static_members_table__ptr: *mut zval
§function_table: HashTable
§properties_info: HashTable
§constants_table: HashTable
§mutable_data__ptr: *mut zend_class_mutable_data
§inheritance_cache: *mut zend_inheritance_cache_entry
§properties_info_table: *mut *mut _zend_property_info
§constructor: *mut zend_function
§destructor: *mut zend_function
§clone: *mut zend_function
§__get: *mut zend_function
§__set: *mut zend_function
§__unset: *mut zend_function
§__isset: *mut zend_function
§__call: *mut zend_function
§__callstatic: *mut zend_function
§__tostring: *mut zend_function
§__debugInfo: *mut zend_function
§__serialize: *mut zend_function
§__unserialize: *mut zend_function
§iterator_funcs_ptr: *mut zend_class_iterator_funcs
§arrayaccess_funcs_ptr: *mut zend_class_arrayaccess_funcs
§__bindgen_anon_2: _zend_class_entry__bindgen_ty_2
§get_iterator: Option<unsafe extern "C" fn(ce: *mut zend_class_entry, object: *mut zval, by_ref: c_int) -> *mut zend_object_iterator>
§get_static_method: Option<unsafe extern "C" fn(ce: *mut zend_class_entry, method: *mut zend_string) -> *mut zend_function>
§serialize: Option<unsafe extern "C" fn(object: *mut zval, buffer: *mut *mut c_uchar, buf_len: *mut usize, data: *mut zend_serialize_data) -> c_int>
§unserialize: Option<unsafe extern "C" fn(object: *mut zval, ce: *mut zend_class_entry, buf: *const c_uchar, buf_len: usize, data: *mut zend_unserialize_data) -> c_int>
§num_interfaces: u32
§num_traits: u32
§__bindgen_anon_3: _zend_class_entry__bindgen_ty_3
§trait_names: *mut zend_class_name
§trait_aliases: *mut *mut zend_trait_alias
§trait_precedences: *mut *mut zend_trait_precedence
§attributes: *mut HashTable
§enum_backing_type: u32
§backed_enum_table: *mut HashTable
§info: _zend_class_entry__bindgen_ty_4
Implementations§
source§impl _zend_class_entry
impl _zend_class_entry
sourcepub fn try_find(name: &str) -> Option<&'static Self>
pub fn try_find(name: &str) -> Option<&'static Self>
Attempts to find a reference to a class in the global class table.
Returns a reference to the class if found, or None
if the class
could not be found or the class table has not been initialized.
sourcepub fn flags(&self) -> ClassFlags
pub fn flags(&self) -> ClassFlags
Returns the class flags.
Examples found in repository?
src/zend/class.rs (line 33)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
pub fn is_interface(&self) -> bool {
self.flags().contains(ClassFlags::Interface)
}
/// Checks if the class is an instance of another class or interface.
///
/// # Parameters
///
/// * `other` - The inherited class entry to check.
pub fn instance_of(&self, other: &ClassEntry) -> bool {
if self == other {
return true;
}
if other.is_interface() {
return self
.interfaces()
.map_or(false, |mut it| it.any(|ce| ce == other));
}
std::iter::successors(self.parent(), |p| p.parent()).any(|ce| ce == other)
}
/// Returns an iterator of all the interfaces that the class implements.
///
/// Returns [`None`] if the interfaces have not been resolved on the
/// class.
pub fn interfaces(&self) -> Option<impl Iterator<Item = &ClassEntry>> {
self.flags()
.contains(ClassFlags::ResolvedInterfaces)
.then(|| unsafe {
(0..self.num_interfaces)
.into_iter()
.map(move |i| *self.__bindgen_anon_3.interfaces.offset(i as _))
.filter_map(|ptr| ptr.as_ref())
})
}
/// Returns the parent of the class.
///
/// If the parent of the class has not been resolved, it attempts to find
/// the parent by name. Returns [`None`] if the parent was not resolved
/// and the parent was not able to be found by name.
pub fn parent(&self) -> Option<&Self> {
if self.flags().contains(ClassFlags::ResolvedParent) {
unsafe { self.__bindgen_anon_1.parent.as_ref() }
} else {
let name = unsafe { self.__bindgen_anon_1.parent_name.as_ref()? };
Self::try_find(name.as_str().ok()?)
}
}
}
impl PartialEq for ClassEntry {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(self, other)
}
}
impl Debug for ClassEntry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name: String = unsafe { self.name.as_ref() }
.and_then(|s| s.try_into().ok())
.ok_or(std::fmt::Error)?;
f.debug_struct("ClassEntry")
.field("name", &name)
.field("flags", &self.flags())
.field("is_interface", &self.is_interface())
.field(
"interfaces",
&self.interfaces().map(|iter| iter.collect::<Vec<_>>()),
)
.field("parent", &self.parent())
.finish()
}
More examples
src/exception.rs (line 130)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
pub fn throw_with_code(ex: &ClassEntry, code: i32, message: &str) -> Result<()> {
let flags = ex.flags();
// Can't throw an interface or abstract class.
if flags.contains(ClassFlags::Interface) || flags.contains(ClassFlags::Abstract) {
return Err(Error::InvalidException(flags));
}
// SAFETY: We are given a reference to a `ClassEntry` therefore when we cast it
// to a pointer it will be valid.
unsafe {
zend_throw_exception_ex(
(ex as *const _) as *mut _,
code as _,
CString::new("%s")?.as_ptr(),
CString::new(message)?.as_ptr(),
)
};
Ok(())
}
sourcepub fn is_interface(&self) -> bool
pub fn is_interface(&self) -> bool
Returns true
if the class entry is an interface, and false
otherwise.
Examples found in repository?
More examples
src/zend/class.rs (line 46)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
pub fn instance_of(&self, other: &ClassEntry) -> bool {
if self == other {
return true;
}
if other.is_interface() {
return self
.interfaces()
.map_or(false, |mut it| it.any(|ce| ce == other));
}
std::iter::successors(self.parent(), |p| p.parent()).any(|ce| ce == other)
}
/// Returns an iterator of all the interfaces that the class implements.
///
/// Returns [`None`] if the interfaces have not been resolved on the
/// class.
pub fn interfaces(&self) -> Option<impl Iterator<Item = &ClassEntry>> {
self.flags()
.contains(ClassFlags::ResolvedInterfaces)
.then(|| unsafe {
(0..self.num_interfaces)
.into_iter()
.map(move |i| *self.__bindgen_anon_3.interfaces.offset(i as _))
.filter_map(|ptr| ptr.as_ref())
})
}
/// Returns the parent of the class.
///
/// If the parent of the class has not been resolved, it attempts to find
/// the parent by name. Returns [`None`] if the parent was not resolved
/// and the parent was not able to be found by name.
pub fn parent(&self) -> Option<&Self> {
if self.flags().contains(ClassFlags::ResolvedParent) {
unsafe { self.__bindgen_anon_1.parent.as_ref() }
} else {
let name = unsafe { self.__bindgen_anon_1.parent_name.as_ref()? };
Self::try_find(name.as_str().ok()?)
}
}
}
impl PartialEq for ClassEntry {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(self, other)
}
}
impl Debug for ClassEntry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name: String = unsafe { self.name.as_ref() }
.and_then(|s| s.try_into().ok())
.ok_or(std::fmt::Error)?;
f.debug_struct("ClassEntry")
.field("name", &name)
.field("flags", &self.flags())
.field("is_interface", &self.is_interface())
.field(
"interfaces",
&self.interfaces().map(|iter| iter.collect::<Vec<_>>()),
)
.field("parent", &self.parent())
.finish()
}
sourcepub fn instance_of(&self, other: &ClassEntry) -> bool
pub fn instance_of(&self, other: &ClassEntry) -> bool
Checks if the class is an instance of another class or interface.
Parameters
other
- The inherited class entry to check.
sourcepub fn interfaces(&self) -> Option<impl Iterator<Item = &ClassEntry>>
pub fn interfaces(&self) -> Option<impl Iterator<Item = &ClassEntry>>
Returns an iterator of all the interfaces that the class implements.
Returns None
if the interfaces have not been resolved on the
class.
Examples found in repository?
src/zend/class.rs (line 48)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
pub fn instance_of(&self, other: &ClassEntry) -> bool {
if self == other {
return true;
}
if other.is_interface() {
return self
.interfaces()
.map_or(false, |mut it| it.any(|ce| ce == other));
}
std::iter::successors(self.parent(), |p| p.parent()).any(|ce| ce == other)
}
/// Returns an iterator of all the interfaces that the class implements.
///
/// Returns [`None`] if the interfaces have not been resolved on the
/// class.
pub fn interfaces(&self) -> Option<impl Iterator<Item = &ClassEntry>> {
self.flags()
.contains(ClassFlags::ResolvedInterfaces)
.then(|| unsafe {
(0..self.num_interfaces)
.into_iter()
.map(move |i| *self.__bindgen_anon_3.interfaces.offset(i as _))
.filter_map(|ptr| ptr.as_ref())
})
}
/// Returns the parent of the class.
///
/// If the parent of the class has not been resolved, it attempts to find
/// the parent by name. Returns [`None`] if the parent was not resolved
/// and the parent was not able to be found by name.
pub fn parent(&self) -> Option<&Self> {
if self.flags().contains(ClassFlags::ResolvedParent) {
unsafe { self.__bindgen_anon_1.parent.as_ref() }
} else {
let name = unsafe { self.__bindgen_anon_1.parent_name.as_ref()? };
Self::try_find(name.as_str().ok()?)
}
}
}
impl PartialEq for ClassEntry {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(self, other)
}
}
impl Debug for ClassEntry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name: String = unsafe { self.name.as_ref() }
.and_then(|s| s.try_into().ok())
.ok_or(std::fmt::Error)?;
f.debug_struct("ClassEntry")
.field("name", &name)
.field("flags", &self.flags())
.field("is_interface", &self.is_interface())
.field(
"interfaces",
&self.interfaces().map(|iter| iter.collect::<Vec<_>>()),
)
.field("parent", &self.parent())
.finish()
}
sourcepub fn parent(&self) -> Option<&Self>
pub fn parent(&self) -> Option<&Self>
Returns the parent of the class.
If the parent of the class has not been resolved, it attempts to find
the parent by name. Returns None
if the parent was not resolved
and the parent was not able to be found by name.
Examples found in repository?
src/zend/class.rs (line 52)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
pub fn instance_of(&self, other: &ClassEntry) -> bool {
if self == other {
return true;
}
if other.is_interface() {
return self
.interfaces()
.map_or(false, |mut it| it.any(|ce| ce == other));
}
std::iter::successors(self.parent(), |p| p.parent()).any(|ce| ce == other)
}
/// Returns an iterator of all the interfaces that the class implements.
///
/// Returns [`None`] if the interfaces have not been resolved on the
/// class.
pub fn interfaces(&self) -> Option<impl Iterator<Item = &ClassEntry>> {
self.flags()
.contains(ClassFlags::ResolvedInterfaces)
.then(|| unsafe {
(0..self.num_interfaces)
.into_iter()
.map(move |i| *self.__bindgen_anon_3.interfaces.offset(i as _))
.filter_map(|ptr| ptr.as_ref())
})
}
/// Returns the parent of the class.
///
/// If the parent of the class has not been resolved, it attempts to find
/// the parent by name. Returns [`None`] if the parent was not resolved
/// and the parent was not able to be found by name.
pub fn parent(&self) -> Option<&Self> {
if self.flags().contains(ClassFlags::ResolvedParent) {
unsafe { self.__bindgen_anon_1.parent.as_ref() }
} else {
let name = unsafe { self.__bindgen_anon_1.parent_name.as_ref()? };
Self::try_find(name.as_str().ok()?)
}
}
}
impl PartialEq for ClassEntry {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(self, other)
}
}
impl Debug for ClassEntry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name: String = unsafe { self.name.as_ref() }
.and_then(|s| s.try_into().ok())
.ok_or(std::fmt::Error)?;
f.debug_struct("ClassEntry")
.field("name", &name)
.field("flags", &self.flags())
.field("is_interface", &self.is_interface())
.field(
"interfaces",
&self.interfaces().map(|iter| iter.collect::<Vec<_>>()),
)
.field("parent", &self.parent())
.finish()
}