diff --git a/phper-doc/doc/_06_module/_07_register_interface/index.md b/phper-doc/doc/_06_module/_07_register_interface/index.md index 53d8d1d6..ecb3a94c 100644 --- a/phper-doc/doc/_06_module/_07_register_interface/index.md +++ b/phper-doc/doc/_06_module/_07_register_interface/index.md @@ -58,7 +58,7 @@ interface Foo extends ArrayAccess, Iterator {} ## Add methods -Interface can add public abstract methods. +Interface can add public abstract methods, and public static abstract methods. ```rust,no_run use phper::classes::{InterfaceEntity, ClassEntry, Visibility}; @@ -68,6 +68,7 @@ use phper::values::ZVal; let mut foo = InterfaceEntity::new("Foo"); foo.add_method("doSomethings").argument(Argument::new("name")); +foo.add_static_method("test"); ``` Note that abstract has no method body, so you don't need to add the handler to the method. diff --git a/phper/src/classes.rs b/phper/src/classes.rs index dc5a103a..5ce729cc 100644 --- a/phper/src/classes.rs +++ b/phper/src/classes.rs @@ -837,6 +837,15 @@ impl InterfaceEntity { self.method_entities.last_mut().unwrap() } + /// Add static member method to interface. + pub fn add_static_method(&mut self, name: impl Into) -> &mut MethodEntity { + let mut entity = MethodEntity::new(name, None, Visibility::Public); + entity.set_vis_abstract(); + entity.set_vis_static(); + self.method_entities.push(entity); + self.method_entities.last_mut().unwrap() + } + /// Add constant to interface pub fn add_constant(&mut self, name: impl Into, value: impl Into) { let constant = ConstantEntity::new(name, value); diff --git a/tests/integration/src/classes.rs b/tests/integration/src/classes.rs index 1dd72246..1bcea295 100644 --- a/tests/integration/src/classes.rs +++ b/tests/integration/src/classes.rs @@ -181,6 +181,8 @@ fn integrate_i_bar(module: &mut Module) { .add_method("doSomethings") .argument(Argument::new("job_name")); + interface.add_static_method("myStaticMethod"); + module.add_interface(interface); } diff --git a/tests/integration/tests/php/classes.php b/tests/integration/tests/php/classes.php index 99c01071..e0ba75e7 100644 --- a/tests/integration/tests/php/classes.php +++ b/tests/integration/tests/php/classes.php @@ -65,6 +65,12 @@ $doSomethings = $interface->getMethod("doSomethings"); assert_true($doSomethings->isPublic()); assert_true($doSomethings->isAbstract()); +assert_false($doSomethings->isStatic()); + +$myStaticMethod = $interface->getMethod("myStaticMethod"); +assert_true($myStaticMethod->isPublic()); +assert_true($myStaticMethod->isAbstract()); +assert_true($myStaticMethod->isStatic()); // Test get or set static properties. assert_eq(IntegrationTest\PropsHolder::$foo, "bar");