@@ -16,8 +16,7 @@ use phper::{
1616 types:: { ArgumentTypeHint , ReturnTypeHint } ,
1717 values:: ZVal ,
1818} ;
19- use std:: { collections:: HashMap , convert:: Infallible } ;
20- use std:: rc:: Rc ;
19+ use std:: { collections:: HashMap , convert:: Infallible , rc:: Rc } ;
2120
2221pub fn integrate ( module : & mut Module ) {
2322 integrate_a ( module) ;
@@ -235,50 +234,39 @@ fn integrate_bar_extends_foo(module: &mut Module, foo_class: StateClass<Foo>) {
235234fn integrate_dependent_classes ( module : & mut Module ) {
236235 const A_CLS : & str = r"IntegrationTest\Dependency\A" ;
237236 const B_CLS : & str = r"IntegrationTest\Dependency\B" ;
238- // Build both class entities
239- let mut a_cls = ClassEntity :: new ( A_CLS ) ;
240- let mut b_cls = ClassEntity :: new ( B_CLS ) ;
241237
242- // Placeholder, will clone StateClass into closures after registration
243- let a_cls_ref = std:: rc:: Rc :: new ( std:: cell:: RefCell :: new ( None ) ) ;
244- let b_cls_ref = std:: rc:: Rc :: new ( std:: cell:: RefCell :: new ( None ) ) ;
238+ let ( mut a_cls, a_ref) = define_class_stub ! ( A_CLS , a_ref) ;
239+ let ( mut b_cls, b_ref) = define_class_stub ! ( B_CLS , b_ref) ;
245240
246241 {
247- let b_cls_ref = Rc :: clone ( & b_cls_ref) ;
248- a_cls. add_static_method ( "createB" , Visibility :: Public , move |_| {
249- let borrow = b_cls_ref. borrow ( ) ;
250- let b_state: & StateClass < ( ) > = borrow
251- . as_ref ( )
252- . expect ( "B class not registered" ) ;
253- let obj = b_state. init_object ( ) ?;
254- Ok :: < _ , phper:: Error > ( obj)
255- } )
256- . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( String :: from ( B_CLS ) ) ) ) ;
242+ let b_ref = Rc :: clone ( & b_ref) ;
243+ a_cls
244+ . add_static_method ( "createB" , Visibility :: Public , move |_| {
245+ let borrow = b_ref. borrow ( ) ;
246+ let b_state: & StateClass < ( ) > = borrow. as_ref ( ) . unwrap ( ) ;
247+ Ok :: < _ , phper:: Error > ( b_state. init_object ( ) ?)
248+ } )
249+ . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( B_CLS . into ( ) ) ) ) ;
257250 }
258251
259252 {
260- let a_cls_ref = Rc :: clone ( & a_cls_ref) ;
261- b_cls. add_static_method ( "createA" , Visibility :: Public , move |_| {
262- let borrow = a_cls_ref. borrow ( ) ;
263- let a_state: & StateClass < ( ) > = borrow
264- . as_ref ( )
265- . expect ( "A class not registered" ) ;
266- let obj = a_state. init_object ( ) ?;
267- Ok :: < _ , phper:: Error > ( obj)
268- } )
269- . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( String :: from ( A_CLS ) ) ) ) ;
253+ let a_ref = Rc :: clone ( & a_ref) ;
254+ b_cls
255+ . add_static_method ( "createA" , Visibility :: Public , move |_| {
256+ let borrow = a_ref. borrow ( ) ;
257+ let a_state: & StateClass < ( ) > = borrow. as_ref ( ) . unwrap ( ) ;
258+ Ok :: < _ , phper:: Error > ( a_state. init_object ( ) ?)
259+ } )
260+ . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( A_CLS . into ( ) ) ) ) ;
270261 }
271262
272-
273- // Register both classes and save the StateClass into shared RefCells
263+ // Register both classes
274264 let a_state = module. add_class ( a_cls) ;
275265 let b_state = module. add_class ( b_cls) ;
276-
277- * a_cls_ref. borrow_mut ( ) = Some ( a_state) ;
278- * b_cls_ref. borrow_mut ( ) = Some ( b_state) ;
266+ * a_ref. borrow_mut ( ) = Some ( a_state. clone ( ) ) ;
267+ * b_ref. borrow_mut ( ) = Some ( b_state. clone ( ) ) ;
279268}
280269
281-
282270#[ cfg( phper_major_version = "8" ) ]
283271fn integrate_stringable ( module : & mut Module ) {
284272 use phper:: { functions:: ReturnType , types:: ReturnTypeHint } ;
0 commit comments