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 ;
@@ -37,7 +38,7 @@ public function __construct(EventDispatcherInterface $dispatcher, RepositoryProv
3738 */
3839 public function handle (Request $ request )
3940 {
40- $ data = json_decode ($ request ->getContent (), true );
41+ $ data = json_decode (( string ) $ request ->getContent (), true );
4142 if (null === $ data ) {
4243 throw new BadRequestHttpException ('Invalid JSON body! ' );
4344 }
@@ -65,7 +66,12 @@ public function handle(Request $request)
6566 }
6667
6768 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 );
6975 }
7076
7177 $ event = new GitHubEvent ($ data , $ repository );
@@ -74,7 +80,7 @@ public function handle(Request $request)
7480 try {
7581 $ this ->dispatcher ->dispatch ($ event , 'github. ' .$ eventName );
7682 } 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 );
7884 }
7985
8086 $ responseData = $ event ->getResponseData ();
0 commit comments