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 ;
@@ -39,7 +40,7 @@ public function __construct(EventDispatcherInterface $dispatcher, RepositoryProv
39
40
*/
40
41
public function handle (Request $ request )
41
42
{
42
- $ data = json_decode ($ request ->getContent (), true );
43
+ $ data = json_decode (( string ) $ request ->getContent (), true );
43
44
if (null === $ data ) {
44
45
throw new BadRequestHttpException ('Invalid JSON body! ' );
45
46
}
@@ -67,7 +68,12 @@ public function handle(Request $request)
67
68
}
68
69
69
70
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 );
71
77
}
72
78
73
79
$ event = new GitHubEvent ($ data , $ repository );
@@ -76,7 +82,7 @@ public function handle(Request $request)
76
82
try {
77
83
$ this ->dispatcher ->dispatch ($ event , 'github. ' .$ eventName );
78
84
} 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 );
80
86
}
81
87
82
88
$ responseData = $ event ->getResponseData ();
0 commit comments