Skip to content

Commit 4133a0f

Browse files
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
1 parent 5f33598 commit 4133a0f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/builders/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl ClassBuilder {
8585
/// * `func` - The function entry to add to the class.
8686
/// * `flags` - Flags relating to the function. See [`MethodFlags`].
8787
pub fn method(mut self, mut func: FunctionEntry, flags: MethodFlags) -> Self {
88-
func.flags = flags.bits();
88+
func.flags |= flags.bits();
8989
self.methods.push(func);
9090
self
9191
}

src/builders/function.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
args::{Arg, ArgInfo},
33
error::{Error, Result},
4-
flags::DataType,
4+
flags::{DataType, MethodFlags},
55
types::Zval,
66
zend::{ExecuteData, FunctionEntry, ZendType},
77
};
@@ -64,6 +64,30 @@ impl<'a> FunctionBuilder<'a> {
6464
}
6565
}
6666

67+
/// Create a new function builder for an abstract function that can be used
68+
/// on an abstract class or an interface.
69+
///
70+
/// # Parameters
71+
///
72+
/// * `name` - The name of the function.
73+
pub fn new_abstract<T: Into<String>>(name: T) -> Self {
74+
Self {
75+
name: name.into(),
76+
function: FunctionEntry {
77+
fname: ptr::null(),
78+
handler: None,
79+
arg_info: ptr::null(),
80+
num_args: 0,
81+
flags: MethodFlags::Abstract.bits(),
82+
},
83+
args: vec![],
84+
n_req: None,
85+
retval: None,
86+
ret_as_ref: false,
87+
ret_as_null: false,
88+
}
89+
}
90+
6791
/// Creates a constructor builder, used to build the constructor
6892
/// for classes.
6993
///

0 commit comments

Comments
 (0)