Skip to content

Commit

Permalink
Add some standard zend interfaces (davidcole1340#164)
Browse files Browse the repository at this point in the history
* 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 davidcole1340#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]>
  • Loading branch information
nikeee and davidcole1340 authored Oct 16, 2022
1 parent 6a598de commit 24d703d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
7 changes: 7 additions & 0 deletions allowed_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ bind! {
zend_ce_type_error,
zend_ce_unhandled_match_error,
zend_ce_value_error,
zend_ce_traversable,
zend_ce_aggregate,
zend_ce_iterator,
zend_ce_arrayaccess,
zend_ce_serializable,
zend_ce_countable,
zend_ce_stringable,
zend_class_entry,
zend_declare_class_constant,
zend_declare_property,
Expand Down
21 changes: 21 additions & 0 deletions docsrs_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,3 +1405,24 @@ extern "C" {
extern "C" {
pub fn zend_do_implement_interface(ce: *mut zend_class_entry, iface: *mut zend_class_entry);
}
extern "C" {
pub static mut zend_ce_traversable: *mut zend_class_entry;
}
extern "C" {
pub static mut zend_ce_aggregate: *mut zend_class_entry;
}
extern "C" {
pub static mut zend_ce_iterator: *mut zend_class_entry;
}
extern "C" {
pub static mut zend_ce_arrayaccess: *mut zend_class_entry;
}
extern "C" {
pub static mut zend_ce_serializable: *mut zend_class_entry;
}
extern "C" {
pub static mut zend_ce_countable: *mut zend_class_entry;
}
extern "C" {
pub static mut zend_ce_stringable: *mut zend_class_entry;
}
69 changes: 53 additions & 16 deletions src/zend/ce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,107 @@
#![allow(clippy::unwrap_used)]

use crate::ffi::{
zend_ce_argument_count_error, zend_ce_arithmetic_error, zend_ce_compile_error,
zend_ce_division_by_zero_error, zend_ce_error_exception, zend_ce_exception,
zend_ce_parse_error, zend_ce_throwable, zend_ce_type_error, zend_ce_unhandled_match_error,
zend_ce_value_error, zend_standard_class_def,
zend_ce_aggregate, zend_ce_argument_count_error, zend_ce_arithmetic_error, zend_ce_arrayaccess,
zend_ce_compile_error, zend_ce_countable, zend_ce_division_by_zero_error,
zend_ce_error_exception, zend_ce_exception, zend_ce_iterator, zend_ce_parse_error,
zend_ce_serializable, zend_ce_stringable, zend_ce_throwable, zend_ce_traversable,
zend_ce_type_error, zend_ce_unhandled_match_error, zend_ce_value_error,
zend_standard_class_def,
};

use super::ClassEntry;

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

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

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

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

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

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

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

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

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

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

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

/// Returns the base `UnhandledMatchError` class.
/// Returns the base [`UnhandledMatchError`](https://www.php.net/manual/en/class.unhandledmatcherror.php) class.
pub fn unhandled_match_error() -> &'static ClassEntry {
unsafe { zend_ce_unhandled_match_error.as_ref() }.unwrap()
}

/// Returns the [`Traversable`](https://www.php.net/manual/en/class.traversable.php) interface.
pub fn traversable() -> &'static ClassEntry {
unsafe { zend_ce_traversable.as_ref() }.unwrap()
}

/// Returns the [`IteratorAggregate`](https://www.php.net/manual/en/class.iteratoraggregate.php) interface.
pub fn aggregate() -> &'static ClassEntry {
unsafe { zend_ce_aggregate.as_ref() }.unwrap()
}

/// Returns the [`Iterator`](https://www.php.net/manual/en/class.iterator.php) interface.
pub fn iterator() -> &'static ClassEntry {
unsafe { zend_ce_iterator.as_ref() }.unwrap()
}

/// Returns the [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php) interface.
pub fn arrayaccess() -> &'static ClassEntry {
unsafe { zend_ce_arrayaccess.as_ref() }.unwrap()
}

/// Returns the [`Serializable`](https://www.php.net/manual/en/class.serializable.php) interface.
pub fn serializable() -> &'static ClassEntry {
unsafe { zend_ce_serializable.as_ref() }.unwrap()
}

/// Returns the [`Countable`](https://www.php.net/manual/en/class.countable.php) interface.
pub fn countable() -> &'static ClassEntry {
unsafe { zend_ce_countable.as_ref() }.unwrap()
}

/// Returns the [`Stringable`](https://www.php.net/manual/en/class.stringable.php) interface.
pub fn stringable() -> &'static ClassEntry {
unsafe { zend_ce_stringable.as_ref() }.unwrap()
}

0 comments on commit 24d703d

Please sign in to comment.