@@ -17,7 +17,6 @@ use phper::{
1717 values:: ZVal ,
1818} ;
1919use std:: { collections:: HashMap , convert:: Infallible } ;
20- use std:: rc:: Rc ;
2120
2221pub fn integrate ( module : & mut Module ) {
2322 integrate_a ( module) ;
@@ -238,46 +237,28 @@ fn integrate_dependent_classes(module: &mut Module) {
238237 let mut a_cls = ClassEntity :: new ( A_CLS ) ;
239238 let mut b_cls = ClassEntity :: new ( B_CLS ) ;
240239
241- // Placeholder, will clone StateClass into closures after registration
242- let a_cls_ref = std:: rc:: Rc :: new ( std:: cell:: RefCell :: new ( None ) ) ;
243- let b_cls_ref = std:: rc:: Rc :: new ( std:: cell:: RefCell :: new ( None ) ) ;
244-
245- {
246- let b_cls_ref = Rc :: clone ( & b_cls_ref) ;
247- a_cls. add_static_method ( "createB" , Visibility :: Public , move |_| {
248- let borrow = b_cls_ref. borrow ( ) ;
249- let b_state: & StateClass < ( ) > = borrow
250- . as_ref ( )
251- . expect ( "B class not registered" ) ;
252- let obj = b_state. init_object ( ) ?;
253- Ok :: < _ , phper:: Error > ( obj)
254- } )
255- . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( String :: from ( B_CLS ) ) ) ) ;
256- }
257-
258- {
259- let a_cls_ref = Rc :: clone ( & a_cls_ref) ;
260- b_cls. add_static_method ( "createA" , Visibility :: Public , move |_| {
261- let borrow = a_cls_ref. borrow ( ) ;
262- let a_state: & StateClass < ( ) > = borrow
263- . as_ref ( )
264- . expect ( "A class not registered" ) ;
265- let obj = a_state. init_object ( ) ?;
266- Ok :: < _ , phper:: Error > ( obj)
267- } )
268- . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( String :: from ( A_CLS ) ) ) ) ;
269- }
240+ let a_bound_class = a_cls. bound_class ( ) ;
241+ let b_bound_class = b_cls. bound_class ( ) ;
270242
243+ a_cls
244+ . add_static_method ( "createB" , Visibility :: Public , move |_| {
245+ let object = b_bound_class. init_object ( ) ?;
246+ Ok :: < _ , phper:: Error > ( object)
247+ } )
248+ . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( B_CLS . into ( ) ) ) ) ;
271249
272- // Register both classes and save the StateClass into shared RefCells
273- let a_state = module. add_class ( a_cls) ;
274- let b_state = module. add_class ( b_cls) ;
250+ b_cls
251+ . add_static_method ( "createA" , Visibility :: Public , move |_| {
252+ let object = a_bound_class. init_object ( ) ?;
253+ Ok :: < _ , phper:: Error > ( object)
254+ } )
255+ . return_type ( ReturnType :: new ( ReturnTypeHint :: ClassEntry ( A_CLS . into ( ) ) ) ) ;
275256
276- * a_cls_ref. borrow_mut ( ) = Some ( a_state) ;
277- * b_cls_ref. borrow_mut ( ) = Some ( b_state) ;
257+ // Register both classes
258+ module. add_class ( a_cls) ;
259+ module. add_class ( b_cls) ;
278260}
279261
280-
281262#[ cfg( phper_major_version = "8" ) ]
282263fn integrate_stringable ( module : & mut Module ) {
283264 use phper:: { functions:: ReturnType , types:: ReturnTypeHint } ;
0 commit comments