Skip to content

Commit

Permalink
add ability to define abstract methods (davidcole1340#171)
Browse files Browse the repository at this point in the history
* add ability to define abstract methods

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

* rustfmt
  • Loading branch information
davidcole1340 authored Nov 10, 2022
1 parent 5f33598 commit 4133a0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/builders/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 25 additions & 1 deletion src/builders/function.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
args::{Arg, ArgInfo},
error::{Error, Result},
flags::DataType,
flags::{DataType, MethodFlags},
types::Zval,
zend::{ExecuteData, FunctionEntry, ZendType},
};
Expand Down Expand Up @@ -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.
///
Expand Down

0 comments on commit 4133a0f

Please sign in to comment.