946bb0cc4c8d215aff03ee0af9b3485256dd214b
[pharext/pharext.org] / app / Controller / Github / Hook.php
1 <?php
2
3 namespace app\Github\API;
4
5 use app\Controller;
6 use app\Github\API;
7 use app\Web;
8
9 class Hook implements Controller
10 {
11 private $app;
12 private $github;
13
14 function __construct(Web $app, API $github) {
15 $this->app = $app;
16 $this->github = $github;
17 }
18
19 function __invoke(array $args = []) {
20 $request = $this->app->getRequest();
21 $response = $this->app->getResponse();
22
23 if (!($sig = $request->getHeader("X-Github-Signature")) || !($evt = $request->getHeader("X-Github-Event"))) {
24 $response->setResponseCode(400);
25 } elseif ($sig !== hash_hmac("sha1", $request->getBody(), $this->app->getConfig()->github->client->secret)) {
26 $response->setResponseCode(403);
27 } elseif ($evt === "ping") {
28 $response->setReponseStatus("PONG");
29 } elseif ($evt !== "push") {
30 $this->app->getResponse()->setResponseCode(204);
31 } else {
32 $push = json_decode($request->getBody());
33 }
34 }
35 }