12
12
use AppBundle \Issues \GitHub \CachedLabelsApi ;
13
13
use AppBundle \Issues \GitHub \GitHubStatusApi ;
14
14
use Github \Api \Issue \Labels ;
15
+ use Symfony \Component \DependencyInjection \ContainerInterface ;
15
16
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
16
17
use Symfony \Component \HttpFoundation \Request ;
17
18
18
19
/**
19
- * Class GitHubRequestHandler.
20
+ * Handles GitHub webhook requests
20
21
*
21
22
* @author Jules Pietri <jules@heahprod.com>
22
23
*/
@@ -25,15 +26,21 @@ class GitHubRequestHandler
25
26
private $ labelsApi ;
26
27
private $ dispatcher ;
27
28
private $ repositories ;
29
+ /**
30
+ * @var ContainerInterface
31
+ */
32
+ private $ container ;
28
33
29
- public function __construct (Labels $ labelsApi , EventDispatcherInterface $ dispatcher , array $ repositories )
34
+ public function __construct (Labels $ labelsApi , EventDispatcherInterface $ dispatcher , array $ repositories, ContainerInterface $ container )
30
35
{
31
36
$ this ->labelsApi = $ labelsApi ;
32
37
$ this ->dispatcher = $ dispatcher ;
33
38
$ this ->repositories = $ repositories ;
39
+ $ this ->container = $ container ;
34
40
}
35
41
36
42
/**
43
+ * @param Request $request
37
44
* @return array The response data
38
45
*
39
46
* @throws GitHubExceptionInterface When the request or the configuration are invalid
@@ -63,20 +70,12 @@ public function handle(Request $request)
63
70
throw new GitHubAccessDeniedException ('Invalid signature. ' );
64
71
}
65
72
}
66
- if (empty ($ config ['listeners ' ])) {
67
- throw new GitHubInvalidConfigurationException ('The repository "%s" has no listeners configured. ' );
73
+ if (empty ($ config ['subscribers ' ])) {
74
+ throw new GitHubInvalidConfigurationException ('The repository "%s" has no subscribers configured. ' );
68
75
}
69
76
70
- $ api = new GitHubStatusApi (
71
- new CachedLabelsApi ($ this ->labelsApi , $ repository ),
72
- $ repository
73
- );
74
- foreach ($ config ['listeners ' ] as $ listener ) {
75
- if (!is_subclass_of ($ listener , __NAMESPACE__ .'\IssueListener ' )) {
76
- throw new GitHubInvalidConfigurationException (sprintf ('The listener "%s" must be an instance of "\AppBundle\Issues\IssueListener". ' , $ listener ));
77
- }
78
-
79
- $ this ->dispatcher ->addSubscriber (new $ listener ($ api ));
77
+ foreach ($ config ['subscribers ' ] as $ subscriberId ) {
78
+ $ this ->dispatcher ->addSubscriber ($ this ->container ->get ($ subscriberId ));
80
79
}
81
80
82
81
$ event = new GitHubEvent ($ data , $ repository , $ config ['maintainers ' ]);
0 commit comments