@@ -39,7 +39,6 @@ import (
3939 //_ "github.com/ianlancetaylor/cgosymbolizer"
4040
4141 "github.com/dunglas/mercure"
42- "go.uber.org/zap"
4342)
4443
4544type contextKeyStruct struct {}
@@ -578,7 +577,7 @@ func go_is_context_done(threadIndex C.uintptr_t) C.bool {
578577}
579578
580579//export go_mercure_publish
581- func go_mercure_publish (threadIndex C.uintptr_t , topics unsafe. Pointer , data unsafe.Pointer , private bool , id , typ unsafe.Pointer , retry uint64 ) (generatedID * C.zend_string , error C.short ) {
580+ func go_mercure_publish (threadIndex C.uintptr_t , topics * C. struct__zval_struct , data unsafe.Pointer , private bool , id , typ unsafe.Pointer , retry uint64 ) (generatedID * C.zend_string , error C.short ) {
582581 fc := phpThreads [threadIndex ].getRequestContext ()
583582
584583 if fc .mercureHub == nil {
@@ -597,19 +596,26 @@ func go_mercure_publish(threadIndex C.uintptr_t, topics unsafe.Pointer, data uns
597596 Private : private ,
598597 }
599598
600- ts := GoValue [string ](topics )
601- switch t := ts .(type ) {
602- case string :
603- u .Topics = []string {t }
604- case []string :
605- u .Topics = t
599+ zvalType := C .zval_get_type (topics )
600+ switch zvalType {
601+ case C .IS_STRING :
602+ u .Topics = []string {GoString (unsafe .Pointer (topics ))}
603+ case C .IS_ARRAY :
604+ ts , err := GoPackedArray [string ](unsafe .Pointer (topics ))
605+ if err != nil {
606+ logger .Error ("invalid topics type" , slog .String ("error" , err .Error ()))
607+
608+ return nil , 1
609+ }
610+
611+ u .Topics = ts
606612 default :
607613 // Never happens as the function is called from C with proper types
608- panic (fmt . Sprintf ( "invalid topics type %#v" , t ) )
614+ panic ("invalid topics type" )
609615 }
610616
611617 if err := fc .mercureHub .Publish (u ); err != nil {
612- logger .Error ("Unable to publish Mercure update" , zap . Error ( err ))
618+ logger .Error ("Unable to publish Mercure update" , slog . String ( "error" , err . Error () ))
613619
614620 return nil , 2
615621 }
0 commit comments