File tree Expand file tree Collapse file tree 4 files changed +19
-1
lines changed
phper-doc/doc/_06_module/_07_register_interface Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ interface Foo extends ArrayAccess, Iterator {}
58
58
59
59
## Add methods
60
60
61
- Interface can add public abstract methods.
61
+ Interface can add public abstract methods, and public static abstract methods .
62
62
63
63
``` rust,no_run
64
64
use phper::classes::{InterfaceEntity, ClassEntry, Visibility};
@@ -68,6 +68,7 @@ use phper::values::ZVal;
68
68
69
69
let mut foo = InterfaceEntity::new("Foo");
70
70
foo.add_method("doSomethings").argument(Argument::new("name"));
71
+ foo.add_static_method("test");
71
72
```
72
73
73
74
Note that abstract has no method body, so you don't need to add the handler to the method.
Original file line number Diff line number Diff line change @@ -837,6 +837,15 @@ impl InterfaceEntity {
837
837
self . method_entities . last_mut ( ) . unwrap ( )
838
838
}
839
839
840
+ /// Add static member method to interface.
841
+ pub fn add_static_method ( & mut self , name : impl Into < String > ) -> & mut MethodEntity {
842
+ let mut entity = MethodEntity :: new ( name, None , Visibility :: Public ) ;
843
+ entity. set_vis_abstract ( ) ;
844
+ entity. set_vis_static ( ) ;
845
+ self . method_entities . push ( entity) ;
846
+ self . method_entities . last_mut ( ) . unwrap ( )
847
+ }
848
+
840
849
/// Add constant to interface
841
850
pub fn add_constant ( & mut self , name : impl Into < String > , value : impl Into < Scalar > ) {
842
851
let constant = ConstantEntity :: new ( name, value) ;
Original file line number Diff line number Diff line change @@ -181,6 +181,8 @@ fn integrate_i_bar(module: &mut Module) {
181
181
. add_method ( "doSomethings" )
182
182
. argument ( Argument :: new ( "job_name" ) ) ;
183
183
184
+ interface. add_static_method ( "myStaticMethod" ) ;
185
+
184
186
module. add_interface ( interface) ;
185
187
}
186
188
Original file line number Diff line number Diff line change 65
65
$ doSomethings = $ interface ->getMethod ("doSomethings " );
66
66
assert_true ($ doSomethings ->isPublic ());
67
67
assert_true ($ doSomethings ->isAbstract ());
68
+ assert_false ($ doSomethings ->isStatic ());
69
+
70
+ $ myStaticMethod = $ interface ->getMethod ("myStaticMethod " );
71
+ assert_true ($ myStaticMethod ->isPublic ());
72
+ assert_true ($ myStaticMethod ->isAbstract ());
73
+ assert_true ($ myStaticMethod ->isStatic ());
68
74
69
75
// Test get or set static properties.
70
76
assert_eq (IntegrationTest \PropsHolder::$ foo , "bar " );
You can’t perform that action at this time.
0 commit comments