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 {}
5858
5959## Add methods
6060
61- Interface can add public abstract methods.
61+ Interface can add public abstract methods, and public static abstract methods .
6262
6363``` rust,no_run
6464use phper::classes::{InterfaceEntity, ClassEntry, Visibility};
@@ -68,6 +68,7 @@ use phper::values::ZVal;
6868
6969let mut foo = InterfaceEntity::new("Foo");
7070foo.add_method("doSomethings").argument(Argument::new("name"));
71+ foo.add_static_method("test");
7172```
7273
7374Note 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 {
837837 self . method_entities . last_mut ( ) . unwrap ( )
838838 }
839839
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+
840849 /// Add constant to interface
841850 pub fn add_constant ( & mut self , name : impl Into < String > , value : impl Into < Scalar > ) {
842851 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) {
181181 . add_method ( "doSomethings" )
182182 . argument ( Argument :: new ( "job_name" ) ) ;
183183
184+ interface. add_static_method ( "myStaticMethod" ) ;
185+
184186 module. add_interface ( interface) ;
185187}
186188
Original file line number Diff line number Diff line change 6565$ doSomethings = $ interface ->getMethod ("doSomethings " );
6666assert_true ($ doSomethings ->isPublic ());
6767assert_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 ());
6874
6975// Test get or set static properties.
7076assert_eq (IntegrationTest \PropsHolder::$ foo , "bar " );
You can’t perform that action at this time.
0 commit comments