/** * Define the route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * * @return void */ public function boot(Router $router) { parent::boot($router); $router->bind('analysis', function ($value) { $decoded = Hashids::connection('analyses')->decode($value); if (isset($decoded[0]) && is_numeric($decoded[0]) && ($analysis = Analysis::find($decoded[0]))) { return $analysis; } throw new NotFoundHttpException('Analysis not found.'); }); $router->bind('repo', function ($value) { if (is_numeric($value) && ($repo = Repo::find($value))) { return $repo; } throw new NotFoundHttpException('Repo not found.'); }); }
/** * Handles the request made to StyleCI by the GitHub API. * * @return \Illuminate\Http\JsonResponse */ public function handle() { $class = 'StyleCI\\StyleCI\\Events\\Repo\\GitHub\\GitHub' . ucfirst(camel_case(Request::header('X-GitHub-Event'))) . 'Event'; if (!class_exists($class)) { throw new BadRequestHttpException('Event not supported.'); } $data = Request::input(); $repo = Repo::find($data['repository']['id']); if (!$repo) { throw new BadRequestHttpException('Request integrity validation failed.'); } list($algo, $sig) = explode('=', Request::header('X-Hub-Signature')); $hash = hash_hmac($algo, Request::getContent(), $repo->token); if (!Str::equals($hash, $sig)) { throw new BadRequestHttpException('Request integrity validation failed.'); } event(new $class($repo, $data)); return new JsonResponse(['message' => 'Event successfully received.']); }