7
7
use Psr \Log \LoggerInterface ;
8
8
use Symfony \Component \DependencyInjection \ContainerInterface ;
9
9
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
10
+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
10
11
use Symfony \Component \HttpFoundation \Request ;
11
12
use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
12
13
use Symfony \Component \HttpKernel \Exception \PreconditionFailedHttpException ;
@@ -37,7 +38,7 @@ public function __construct(EventDispatcherInterface $dispatcher, RepositoryProv
37
38
*/
38
39
public function handle (Request $ request )
39
40
{
40
- $ data = json_decode ($ request ->getContent (), true );
41
+ $ data = json_decode (( string ) $ request ->getContent (), true );
41
42
if (null === $ data ) {
42
43
throw new BadRequestHttpException ('Invalid JSON body! ' );
43
44
}
@@ -65,7 +66,12 @@ public function handle(Request $request)
65
66
}
66
67
67
68
foreach ($ repository ->getSubscribers () as $ subscriberId ) {
68
- $ this ->dispatcher ->addSubscriber ($ this ->container ->get ($ subscriberId ));
69
+ $ subscriber = $ this ->container ->get ($ subscriberId );
70
+ if (!$ subscriber instanceof EventSubscriberInterface) {
71
+ throw new \LogicException (sprintf ('Service "%s" is not an instance of "%s" ' , $ subscriberId , EventSubscriberInterface::class));
72
+ }
73
+
74
+ $ this ->dispatcher ->addSubscriber ($ subscriber );
69
75
}
70
76
71
77
$ event = new GitHubEvent ($ data , $ repository );
@@ -74,7 +80,7 @@ public function handle(Request $request)
74
80
try {
75
81
$ this ->dispatcher ->dispatch ($ event , 'github. ' .$ eventName );
76
82
} catch (\Exception $ e ) {
77
- throw new \RuntimeException (sprintf ('Failed dispatching "%s" event for "%s" repository. ' , $ eventName , $ repository ->getFullName ()), 0 , $ e );
83
+ throw new \RuntimeException (sprintf ('Failed dispatching "%s" event for "%s" repository. ' , ( string ) $ eventName , $ repository ->getFullName ()), 0 , $ e );
78
84
}
79
85
80
86
$ responseData = $ event ->getResponseData ();
0 commit comments