Skip to content

Commit 9191007

Browse files
author
Aleksandr Startsev
committed
feat: Register __construct for interfaces
For classes with interface flags, declare __construct as abstract method
1 parent 79c8c2f commit 9191007

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/builders/class.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,23 @@ impl ClassBuilder {
238238
"Class name in builder does not match class name in `impl RegisteredClass`."
239239
);
240240
self.object_override = Some(create_object::<T>);
241+
242+
let mut func = if T::FLAGS.contains(ClassFlags::Interface) {
243+
FunctionBuilder::new_abstract("__construct")
244+
} else {
245+
FunctionBuilder::new("__construct", constructor::<T>)
246+
};
247+
241248
self.method(
242249
{
243-
let mut func = FunctionBuilder::new("__construct", constructor::<T>);
244250
if let Some(ConstructorMeta { build_fn, .. }) = T::constructor() {
245251
func = build_fn(func);
246252
}
247253
func
248254
},
249255
MethodFlags::Public,
250256
)
257+
251258
}
252259

253260
/// Function to register the class with PHP. This function is called after

0 commit comments

Comments
 (0)