Skip to content

Commit 24d703d

Browse files
Add some standard zend interfaces (#164)
* Add some standard zend interfaces The zend API also has some standard interfaces it exposes: https://github.com/php/php-src/blob/c8c09b4aaee7ac447828564c6267e62eb304135b/Zend/zend_interfaces.h#L27-L33 ``` extern ZEND_API zend_class_entry *zend_ce_traversable; extern ZEND_API zend_class_entry *zend_ce_aggregate; extern ZEND_API zend_class_entry *zend_ce_iterator; extern ZEND_API zend_class_entry *zend_ce_arrayaccess; extern ZEND_API zend_class_entry *zend_ce_serializable; extern ZEND_API zend_class_entry *zend_ce_countable; extern ZEND_API zend_class_entry *zend_ce_stringable; ``` This surfaced in #163 and should make it possible to implement these interfaces. * Add some links to the php documentation * update docs.rs bindings Co-authored-by: David Cole <[email protected]>
1 parent 6a598de commit 24d703d

File tree

3 files changed

+81
-16
lines changed

3 files changed

+81
-16
lines changed

allowed_bindings.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ bind! {
4949
zend_ce_type_error,
5050
zend_ce_unhandled_match_error,
5151
zend_ce_value_error,
52+
zend_ce_traversable,
53+
zend_ce_aggregate,
54+
zend_ce_iterator,
55+
zend_ce_arrayaccess,
56+
zend_ce_serializable,
57+
zend_ce_countable,
58+
zend_ce_stringable,
5259
zend_class_entry,
5360
zend_declare_class_constant,
5461
zend_declare_property,

docsrs_bindings.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,3 +1405,24 @@ extern "C" {
14051405
extern "C" {
14061406
pub fn zend_do_implement_interface(ce: *mut zend_class_entry, iface: *mut zend_class_entry);
14071407
}
1408+
extern "C" {
1409+
pub static mut zend_ce_traversable: *mut zend_class_entry;
1410+
}
1411+
extern "C" {
1412+
pub static mut zend_ce_aggregate: *mut zend_class_entry;
1413+
}
1414+
extern "C" {
1415+
pub static mut zend_ce_iterator: *mut zend_class_entry;
1416+
}
1417+
extern "C" {
1418+
pub static mut zend_ce_arrayaccess: *mut zend_class_entry;
1419+
}
1420+
extern "C" {
1421+
pub static mut zend_ce_serializable: *mut zend_class_entry;
1422+
}
1423+
extern "C" {
1424+
pub static mut zend_ce_countable: *mut zend_class_entry;
1425+
}
1426+
extern "C" {
1427+
pub static mut zend_ce_stringable: *mut zend_class_entry;
1428+
}

src/zend/ce.rs

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,107 @@
33
#![allow(clippy::unwrap_used)]
44

55
use crate::ffi::{
6-
zend_ce_argument_count_error, zend_ce_arithmetic_error, zend_ce_compile_error,
7-
zend_ce_division_by_zero_error, zend_ce_error_exception, zend_ce_exception,
8-
zend_ce_parse_error, zend_ce_throwable, zend_ce_type_error, zend_ce_unhandled_match_error,
9-
zend_ce_value_error, zend_standard_class_def,
6+
zend_ce_aggregate, zend_ce_argument_count_error, zend_ce_arithmetic_error, zend_ce_arrayaccess,
7+
zend_ce_compile_error, zend_ce_countable, zend_ce_division_by_zero_error,
8+
zend_ce_error_exception, zend_ce_exception, zend_ce_iterator, zend_ce_parse_error,
9+
zend_ce_serializable, zend_ce_stringable, zend_ce_throwable, zend_ce_traversable,
10+
zend_ce_type_error, zend_ce_unhandled_match_error, zend_ce_value_error,
11+
zend_standard_class_def,
1012
};
1113

1214
use super::ClassEntry;
1315

14-
/// Returns the base `stdClass` class.
16+
/// Returns the base [`stdClass`](https://www.php.net/manual/en/class.stdclass.php) class.
1517
pub fn stdclass() -> &'static ClassEntry {
1618
unsafe { zend_standard_class_def.as_ref() }.unwrap()
1719
}
1820

19-
/// Returns the base `Throwable` class.
21+
/// Returns the base [`Throwable`](https://www.php.net/manual/en/class.throwable.php) class.
2022
pub fn throwable() -> &'static ClassEntry {
2123
unsafe { zend_ce_throwable.as_ref() }.unwrap()
2224
}
2325

24-
/// Returns the base `Exception` class.
26+
/// Returns the base [`Exception`](https://www.php.net/manual/en/class.exception.php) class.
2527
pub fn exception() -> &'static ClassEntry {
2628
unsafe { zend_ce_exception.as_ref() }.unwrap()
2729
}
2830

29-
/// Returns the base `ErrorException` class.
31+
/// Returns the base [`ErrorException`](https://www.php.net/manual/en/class.errorexception.php) class.
3032
pub fn error_exception() -> &'static ClassEntry {
3133
unsafe { zend_ce_error_exception.as_ref() }.unwrap()
3234
}
3335

34-
/// Returns the base `CompileError` class.
36+
/// Returns the base [`CompileError`](https://www.php.net/manual/en/class.compileerror.php) class.
3537
pub fn compile_error() -> &'static ClassEntry {
3638
unsafe { zend_ce_compile_error.as_ref() }.unwrap()
3739
}
3840

39-
/// Returns the base `ParseError` class.
41+
/// Returns the base [`ParseError`](https://www.php.net/manual/en/class.parseerror.php) class.
4042
pub fn parse_error() -> &'static ClassEntry {
4143
unsafe { zend_ce_parse_error.as_ref() }.unwrap()
4244
}
4345

44-
/// Returns the base `TypeError` class.
46+
/// Returns the base [`TypeError`](https://www.php.net/manual/en/class.typeerror.php) class.
4547
pub fn type_error() -> &'static ClassEntry {
4648
unsafe { zend_ce_type_error.as_ref() }.unwrap()
4749
}
4850

49-
/// Returns the base `ArgumentCountError` class.
51+
/// Returns the base [`ArgumentCountError`](https://www.php.net/manual/en/class.argumentcounterror.php) class.
5052
pub fn argument_count_error() -> &'static ClassEntry {
5153
unsafe { zend_ce_argument_count_error.as_ref() }.unwrap()
5254
}
5355

54-
/// Returns the base `ValueError` class.
56+
/// Returns the base [`ValueError`](https://www.php.net/manual/en/class.valueerror.php) class.
5557
pub fn value_error() -> &'static ClassEntry {
5658
unsafe { zend_ce_value_error.as_ref() }.unwrap()
5759
}
5860

59-
/// Returns the base `ArithmeticError` class.
61+
/// Returns the base [`ArithmeticError`](https://www.php.net/manual/en/class.arithmeticerror.php) class.
6062
pub fn arithmetic_error() -> &'static ClassEntry {
6163
unsafe { zend_ce_arithmetic_error.as_ref() }.unwrap()
6264
}
6365

64-
/// Returns the base `DivisionByZeroError` class.
66+
/// Returns the base [`DivisionByZeroError`](https://www.php.net/manual/en/class.divisionbyzeroerror.php) class.
6567
pub fn division_by_zero_error() -> &'static ClassEntry {
6668
unsafe { zend_ce_division_by_zero_error.as_ref() }.unwrap()
6769
}
6870

69-
/// Returns the base `UnhandledMatchError` class.
71+
/// Returns the base [`UnhandledMatchError`](https://www.php.net/manual/en/class.unhandledmatcherror.php) class.
7072
pub fn unhandled_match_error() -> &'static ClassEntry {
7173
unsafe { zend_ce_unhandled_match_error.as_ref() }.unwrap()
7274
}
75+
76+
/// Returns the [`Traversable`](https://www.php.net/manual/en/class.traversable.php) interface.
77+
pub fn traversable() -> &'static ClassEntry {
78+
unsafe { zend_ce_traversable.as_ref() }.unwrap()
79+
}
80+
81+
/// Returns the [`IteratorAggregate`](https://www.php.net/manual/en/class.iteratoraggregate.php) interface.
82+
pub fn aggregate() -> &'static ClassEntry {
83+
unsafe { zend_ce_aggregate.as_ref() }.unwrap()
84+
}
85+
86+
/// Returns the [`Iterator`](https://www.php.net/manual/en/class.iterator.php) interface.
87+
pub fn iterator() -> &'static ClassEntry {
88+
unsafe { zend_ce_iterator.as_ref() }.unwrap()
89+
}
90+
91+
/// Returns the [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php) interface.
92+
pub fn arrayaccess() -> &'static ClassEntry {
93+
unsafe { zend_ce_arrayaccess.as_ref() }.unwrap()
94+
}
95+
96+
/// Returns the [`Serializable`](https://www.php.net/manual/en/class.serializable.php) interface.
97+
pub fn serializable() -> &'static ClassEntry {
98+
unsafe { zend_ce_serializable.as_ref() }.unwrap()
99+
}
100+
101+
/// Returns the [`Countable`](https://www.php.net/manual/en/class.countable.php) interface.
102+
pub fn countable() -> &'static ClassEntry {
103+
unsafe { zend_ce_countable.as_ref() }.unwrap()
104+
}
105+
106+
/// Returns the [`Stringable`](https://www.php.net/manual/en/class.stringable.php) interface.
107+
pub fn stringable() -> &'static ClassEntry {
108+
unsafe { zend_ce_stringable.as_ref() }.unwrap()
109+
}

0 commit comments

Comments
 (0)