77use Psr \Log \LoggerInterface ;
88use Symfony \Component \DependencyInjection \ContainerInterface ;
99use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
10+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
1011use Symfony \Component \HttpFoundation \Request ;
1112use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
1213use Symfony \Component \HttpKernel \Exception \PreconditionFailedHttpException ;
@@ -39,7 +40,7 @@ public function __construct(EventDispatcherInterface $dispatcher, RepositoryProv
3940 */
4041 public function handle (Request $ request )
4142 {
42- $ data = json_decode ($ request ->getContent (), true );
43+ $ data = json_decode (( string ) $ request ->getContent (), true );
4344 if (null === $ data ) {
4445 throw new BadRequestHttpException ('Invalid JSON body! ' );
4546 }
@@ -67,7 +68,12 @@ public function handle(Request $request)
6768 }
6869
6970 foreach ($ repository ->getSubscribers () as $ subscriberId ) {
70- $ this ->dispatcher ->addSubscriber ($ this ->container ->get ($ subscriberId ));
71+ $ subscriber = $ this ->container ->get ($ subscriberId );
72+ if (!$ subscriber instanceof EventSubscriberInterface) {
73+ throw new \LogicException (sprintf ('Service "%s" is not an instance of "%s" ' , $ subscriberId , EventSubscriberInterface::class));
74+ }
75+
76+ $ this ->dispatcher ->addSubscriber ($ subscriber );
7177 }
7278
7379 $ event = new GitHubEvent ($ data , $ repository );
@@ -76,7 +82,7 @@ public function handle(Request $request)
7682 try {
7783 $ this ->dispatcher ->dispatch ($ event , 'github. ' .$ eventName );
7884 } catch (\Exception $ e ) {
79- throw new \RuntimeException (sprintf ('Failed dispatching "%s" event for "%s" repository. ' , $ eventName , $ repository ->getFullName ()), 0 , $ e );
85+ throw new \RuntimeException (sprintf ('Failed dispatching "%s" event for "%s" repository. ' , ( string ) $ eventName , $ repository ->getFullName ()), 0 , $ e );
8086 }
8187
8288 $ responseData = $ event ->getResponseData ();
0 commit comments