add ability to define abstract methods (#171)

* add ability to define abstract methods

`new_abstract` can be used for interface and abstract class methods.

* rustfmt
This commit is contained in:
David Cole 2022-11-10 13:51:20 +13:00 committed by GitHub
parent 5f33598fcf
commit 4133a0fe78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -85,7 +85,7 @@ impl ClassBuilder {
/// * `func` - The function entry to add to the class.
/// * `flags` - Flags relating to the function. See [`MethodFlags`].
pub fn method(mut self, mut func: FunctionEntry, flags: MethodFlags) -> Self {
func.flags = flags.bits();
func.flags |= flags.bits();
self.methods.push(func);
self
}

View File

@ -1,7 +1,7 @@
use crate::{
args::{Arg, ArgInfo},
error::{Error, Result},
flags::DataType,
flags::{DataType, MethodFlags},
types::Zval,
zend::{ExecuteData, FunctionEntry, ZendType},
};
@ -64,6 +64,30 @@ impl<'a> FunctionBuilder<'a> {
}
}
/// Create a new function builder for an abstract function that can be used
/// on an abstract class or an interface.
///
/// # Parameters
///
/// * `name` - The name of the function.
pub fn new_abstract<T: Into<String>>(name: T) -> Self {
Self {
name: name.into(),
function: FunctionEntry {
fname: ptr::null(),
handler: None,
arg_info: ptr::null(),
num_args: 0,
flags: MethodFlags::Abstract.bits(),
},
args: vec![],
n_req: None,
retval: None,
ret_as_ref: false,
ret_as_null: false,
}
}
/// Creates a constructor builder, used to build the constructor
/// for classes.
///