From 489f71b8c2d96e6304e11882aa55a823c70d4cfd Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Thu, 12 Feb 2015 12:37:56 +0000 Subject: [PATCH] Cleaning up unnecessary use of 'die' and 'exit' --- PHPCI/Command/InstallCommand.php | 10 ++- PHPCI/Command/PollCommand.php | 2 +- PHPCI/Command/UpdateCommand.php | 10 ++- PHPCI/Controller.php | 4 ++ PHPCI/Controller/BuildController.php | 37 +++++++---- PHPCI/Controller/BuildStatusController.php | 9 ++- PHPCI/Controller/HomeController.php | 6 +- PHPCI/Controller/PluginController.php | 23 ++++--- PHPCI/Controller/ProjectController.php | 35 ++++++---- PHPCI/Controller/SessionController.php | 16 +++-- PHPCI/Controller/SettingsController.php | 51 +++++++++------ PHPCI/Controller/UserController.php | 15 +++-- PHPCI/Controller/WebhookController.php | 76 ++++++++++++---------- 13 files changed, 188 insertions(+), 106 deletions(-) diff --git a/PHPCI/Command/InstallCommand.php b/PHPCI/Command/InstallCommand.php index 3dab656b..77b6b962 100644 --- a/PHPCI/Command/InstallCommand.php +++ b/PHPCI/Command/InstallCommand.php @@ -59,7 +59,9 @@ class InstallCommand extends Command { $this->configFilePath = $input->getOption('config-path'); - $this->verifyNotInstalled($output); + if (!$this->verifyNotInstalled($output)) { + return; + } $output->writeln(''); $output->writeln('******************'); @@ -346,7 +348,6 @@ class InstallCommand extends Command } catch (\Exception $ex) { $output->writeln(''.Lang::get('failed_to_create').''); $output->writeln('' . $ex->getMessage() . ''); - die; } } @@ -361,6 +362,7 @@ class InstallCommand extends Command /** * @param OutputInterface $output + * @return bool */ protected function verifyNotInstalled(OutputInterface $output) { @@ -370,8 +372,10 @@ class InstallCommand extends Command if (!empty($content)) { $output->writeln(''.Lang::get('config_exists').''); $output->writeln(''.Lang::get('update_instead').''); - die; + return false; } } + + return true; } } diff --git a/PHPCI/Command/PollCommand.php b/PHPCI/Command/PollCommand.php index 07b628b8..42a07067 100644 --- a/PHPCI/Command/PollCommand.php +++ b/PHPCI/Command/PollCommand.php @@ -60,7 +60,7 @@ class PollCommand extends Command if (!$token) { $this->logger->error(Lang::get('no_token')); - exit(); + return; } $buildStore = Factory::getStore('Build'); diff --git a/PHPCI/Command/UpdateCommand.php b/PHPCI/Command/UpdateCommand.php index 32ce09b2..1ca1341d 100644 --- a/PHPCI/Command/UpdateCommand.php +++ b/PHPCI/Command/UpdateCommand.php @@ -49,7 +49,9 @@ class UpdateCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $this->verifyInstalled($output); + if (!$this->verifyInstalled($output)) { + return; + } $output->write(Lang::get('updating_phpci')); @@ -63,14 +65,16 @@ class UpdateCommand extends Command if (!file_exists(PHPCI_DIR . 'PHPCI/config.yml')) { $output->writeln(''.Lang::get('not_installed').''); $output->writeln(''.Lang::get('install_instead').''); - die; + return false; } $content = file_get_contents(PHPCI_DIR . 'PHPCI/config.yml'); if (empty($content)) { $output->writeln(''.Lang::get('not_installed').''); $output->writeln(''.Lang::get('install_instead').''); - die; + return false; } + + return true; } } diff --git a/PHPCI/Controller.php b/PHPCI/Controller.php index 4f941251..68b1c845 100644 --- a/PHPCI/Controller.php +++ b/PHPCI/Controller.php @@ -92,6 +92,10 @@ class Controller extends \b8\Controller $this->setView($action); $response = parent::handleAction($action, $actionParams); + if ($response instanceof Response) { + return $response; + } + if (is_string($response)) { $this->controllerView->content = $response; } elseif (isset($this->view)) { diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index d552f5b3..bf898d2d 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -11,6 +11,7 @@ namespace PHPCI\Controller; use b8; use b8\Exception\HttpException\NotFoundException; +use b8\Http\Response\JsonResponse; use PHPCI\BuildFactory; use PHPCI\Helper\Lang; use PHPCI\Model\Build; @@ -61,7 +62,7 @@ class BuildController extends \PHPCI\Controller $this->view->plugins = $this->getUiPlugins(); $this->view->build = $build; - $this->view->data = $this->getBuildData($build); + $this->view->data = json_encode($this->getBuildData($build)); $this->layout->title = Lang::get('build_n', $buildId); $this->layout->subtitle = $build->getProjectTitle(); @@ -107,7 +108,17 @@ class BuildController extends \PHPCI\Controller */ public function data($buildId) { - die($this->getBuildData(BuildFactory::getBuildById($buildId))); + $response = new JsonResponse(); + $build = BuildFactory::getBuildById($buildId); + + if (!$build) { + $response->setResponseCode(404); + $response->setContent(array()); + return $response; + } + + $response->setContent($this->getBuildData($build)); + return $response; } /** @@ -124,7 +135,9 @@ class BuildController extends \PHPCI\Controller $data = $this->buildStore->getMeta($key, $build->getProjectId(), $buildId, $build->getBranch(), $numBuilds); } - die(json_encode($data)); + $response = new JsonResponse(); + $response->setContent($data); + return $response; } /** @@ -139,7 +152,7 @@ class BuildController extends \PHPCI\Controller $data['started'] = !is_null($build->getStarted()) ? $build->getStarted()->format('Y-m-d H:i:s') : null; $data['finished'] = !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : null; - return json_encode($data); + return $data; } /** @@ -155,8 +168,9 @@ class BuildController extends \PHPCI\Controller $build = $this->buildService->createDuplicateBuild($copy); - header('Location: '.PHPCI_URL.'build/view/' . $build->getId()); - exit; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId()); + return $response; } /** @@ -174,8 +188,9 @@ class BuildController extends \PHPCI\Controller $this->buildService->deleteBuild($build); - header('Location: '.PHPCI_URL.'project/view/' . $build->getProjectId()); - exit; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL.'project/view/' . $build->getProjectId()); + return $response; } /** @@ -200,9 +215,9 @@ class BuildController extends \PHPCI\Controller 'running' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_RUNNING)), ); - if ($this->request->isAjax()) { - die(json_encode($rtn)); - } + $response = new JsonResponse(); + $response->setContent($rtn); + return $response; } /** diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index 71ad1e11..13b68cd8 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -53,7 +53,7 @@ class BuildStatusController extends \PHPCI\Controller $status = 'passing'; if (!$project->getAllowPublicStatus()) { - die(); + return null; } if (isset($project) && $project instanceof Project) { @@ -76,6 +76,13 @@ class BuildStatusController extends \PHPCI\Controller public function image($projectId) { $status = $this->getStatus($projectId); + + if (is_null($status)) { + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', '/'); + return $response; + } + $color = ($status == 'passing') ? 'green' : 'red'; header('Content-Type: image/svg+xml'); diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index 20d4cead..c48f40ee 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -68,7 +68,8 @@ class HomeController extends \PHPCI\Controller */ public function latest() { - die($this->getLatestBuildsHtml()); + $this->response->setContent($this->getLatestBuildsHtml()); + return $this->response; } /** @@ -77,7 +78,8 @@ class HomeController extends \PHPCI\Controller public function summary() { $projects = $this->projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC')); - die($this->getSummaryHtml($projects)); + $this->response->setContent($this->getSummaryHtml($projects)); + return $this->response; } /** diff --git a/PHPCI/Controller/PluginController.php b/PHPCI/Controller/PluginController.php index ac829f7f..a090798e 100644 --- a/PHPCI/Controller/PluginController.php +++ b/PHPCI/Controller/PluginController.php @@ -82,16 +82,18 @@ class PluginController extends \PHPCI\Controller $package = $this->getParam('package', null); $json = $this->getComposerJson(); + $response = new b8\Http\Response\RedirectResponse(); + if (!in_array($package, $this->required)) { unset($json['require'][$package]); $this->setComposerJson($json); - header('Location: ' . PHPCI_URL . 'plugin?r=' . $package); - die; + $response->setHeader('Location', PHPCI_URL . 'plugin?r=' . $package); + return $response; } - header('Location: ' . PHPCI_URL); - die; + $response->setHeader('Location', PHPCI_URL); + return $response; } /** @@ -108,8 +110,9 @@ class PluginController extends \PHPCI\Controller $json['require'][$package] = $version; $this->setComposerJson($json); - header('Location: ' . PHPCI_URL . 'plugin?w=' . $package); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL . 'plugin?w=' . $package); + return $response; } /** @@ -181,7 +184,9 @@ class PluginController extends \PHPCI\Controller $http->setHeaders(array('User-Agent: PHPCI/1.0 (+https://www.phptesting.org)')); $res = $http->get('https://packagist.org/search.json', array('q' => $searchQuery)); - die(json_encode($res['body'])); + $response = new b8\Http\Response\JsonResponse(); + $response->setContent($res['body']); + return $response; } /** @@ -194,6 +199,8 @@ class PluginController extends \PHPCI\Controller $http->setHeaders(array('User-Agent: PHPCI/1.0 (+https://www.phptesting.org)')); $res = $http->get('https://packagist.org/packages/'.$name.'.json'); - die(json_encode($res['body'])); + $response = new b8\Http\Response\JsonResponse(); + $response->setContent($res['body']); + return $response; } } diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 01900aa0..5a914adf 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -81,8 +81,9 @@ class ProjectController extends \PHPCI\Controller $pages = $builds[1] == 0 ? 1 : ceil($builds[1] / $per_page); if ($page > $pages) { - header('Location: '.PHPCI_URL.'project/view/'.$projectId); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL.'project/view/'.$projectId); + return $response; } $this->view->builds = $builds[0]; @@ -118,8 +119,9 @@ class ProjectController extends \PHPCI\Controller $email = $_SESSION['phpci_user']->getEmail(); $build = $this->buildService->createBuild($project, null, urldecode($branch), $email); - header('Location: '.PHPCI_URL.'build/view/' . $build->getId()); - exit; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId()); + return $response; } /** @@ -132,8 +134,9 @@ class ProjectController extends \PHPCI\Controller $project = $this->projectStore->getById($projectId); $this->projectService->deleteProject($project); - header('Location: '.PHPCI_URL); - exit; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL); + return $response; } /** @@ -143,7 +146,9 @@ class ProjectController extends \PHPCI\Controller { $branch = $this->getParam('branch', ''); $builds = $this->getLatestBuildsHtml($projectId, urldecode($branch)); - die($builds[0]); + + $this->response->setContent($builds[0]); + return $this->response; } /** @@ -220,8 +225,10 @@ class ProjectController extends \PHPCI\Controller ); $project = $this->projectService->createProject($title, $type, $reference, $options); - header('Location: '.PHPCI_URL.'project/view/' . $project->getId()); - die; + + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL.'project/view/' . $project->getId()); + return $response; } } @@ -282,8 +289,9 @@ class ProjectController extends \PHPCI\Controller $project = $this->projectService->updateProject($project, $title, $type, $reference, $options); - header('Location: '.PHPCI_URL.'project/view/' . $project->getId()); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL.'project/view/' . $project->getId()); + return $response; } /** @@ -366,7 +374,10 @@ class ProjectController extends \PHPCI\Controller protected function githubRepositories() { $github = new Github(); - die(json_encode($github->getRepositories())); + + $response = new b8\Http\Response\JsonResponse(); + $response->setContent($github->getRepositories()); + return $response; } /** diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index c5f8b962..540b043f 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -47,8 +47,9 @@ class SessionController extends \PHPCI\Controller if ($user && password_verify($this->getParam('password', ''), $user->getHash())) { $_SESSION['phpci_user_id'] = $user->getId(); - header('Location: ' . $this->getLoginRedirect()); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', $this->getLoginRedirect()); + return $response; } else { $isLoginFailure = true; } @@ -92,8 +93,10 @@ class SessionController extends \PHPCI\Controller unset($_SESSION['phpci_user_id']); session_destroy(); - header('Location: ' . PHPCI_URL); - die; + + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL); + return $response; } /** @@ -151,8 +154,9 @@ class SessionController extends \PHPCI\Controller $_SESSION['phpci_user'] = $this->userStore->save($user); $_SESSION['phpci_user_id'] = $user->getId(); - header('Location: ' . PHPCI_URL); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL); + return $response; } $this->view->id = $userId; diff --git a/PHPCI/Controller/SettingsController.php b/PHPCI/Controller/SettingsController.php index 72df7c95..ba9b0141 100644 --- a/PHPCI/Controller/SettingsController.php +++ b/PHPCI/Controller/SettingsController.php @@ -102,13 +102,15 @@ class SettingsController extends Controller $this->settings['phpci']['github']['secret'] = $this->getParam('githubsecret', ''); $error = $this->storeSettings(); + $response = new b8\Http\Response\RedirectResponse(); + if ($error) { - header('Location: ' . PHPCI_URL . 'settings?saved=2'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=2'); } else { - header('Location: ' . PHPCI_URL . 'settings?saved=1'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=1'); } - die; + return $response; } /** @@ -123,13 +125,15 @@ class SettingsController extends Controller $error = $this->storeSettings(); + $response = new b8\Http\Response\RedirectResponse(); + if ($error) { - header('Location: ' . PHPCI_URL . 'settings?saved=2'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=2'); } else { - header('Location: ' . PHPCI_URL . 'settings?saved=1'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=1'); } - die; + return $response; } /** @@ -143,13 +147,15 @@ class SettingsController extends Controller $error = $this->storeSettings(); + $response = new b8\Http\Response\RedirectResponse(); + if ($error) { - header('Location: ' . PHPCI_URL . 'settings?saved=2'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=2'); } else { - header('Location: ' . PHPCI_URL . 'settings?saved=1'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=1'); } - die; + return $response; } /** @@ -162,13 +168,15 @@ class SettingsController extends Controller $this->settings['phpci']['basic'] = $this->getParams(); $error = $this->storeSettings(); + $response = new b8\Http\Response\RedirectResponse(); + if ($error) { - header('Location: ' . PHPCI_URL . 'settings?saved=2'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=2'); } else { - header('Location: ' . PHPCI_URL . 'settings?saved=1'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=1'); } - die; + return $response; } /** @@ -183,13 +191,15 @@ class SettingsController extends Controller $error = $this->storeSettings(); + $response = new b8\Http\Response\RedirectResponse(); + if ($error) { - header('Location: ' . PHPCI_URL . 'settings?saved=2'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=2'); } else { - header('Location: ' . PHPCI_URL . 'settings?saved=1'); + $response->setHeader('Location', PHPCI_URL . 'settings?saved=1'); } - die; + return $response; } /** @@ -212,14 +222,15 @@ class SettingsController extends Controller $this->settings['phpci']['github']['token'] = $resp['access_token']; $this->storeSettings(); - header('Location: ' . PHPCI_URL . 'settings?linked=1'); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL . 'settings?linked=1'); + return $response; } } - - header('Location: ' . PHPCI_URL . 'settings?linked=2'); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL . 'settings?linked=2'); + return $response; } /** diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index 7710c503..48092ad5 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -175,8 +175,9 @@ class UserController extends Controller $this->userService->createUser($name, $email, $password, $isAdmin); - header('Location: '.PHPCI_URL.'user'); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL . 'user'); + return $response; } /** @@ -215,8 +216,9 @@ class UserController extends Controller $this->userService->updateUser($user, $name, $email, $password, $isAdmin); - header('Location: '.PHPCI_URL.'user'); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL . 'user'); + return $response; } /** @@ -288,7 +290,8 @@ class UserController extends Controller $this->userService->deleteUser($user); - header('Location: '.PHPCI_URL.'user'); - die; + $response = new b8\Http\Response\RedirectResponse(); + $response->setHeader('Location', PHPCI_URL . 'user'); + return $response; } } diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index a7652971..5ce4849b 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -55,6 +55,9 @@ class WebhookController extends \PHPCI\Controller */ public function bitbucket($project) { + $response = new b8\Http\Response\JsonResponse(); + $response->setContent(array('status' => 'ok')); + $payload = json_decode($this->getParam('payload'), true); foreach ($payload['commits'] as $commit) { @@ -65,13 +68,13 @@ class WebhookController extends \PHPCI\Controller $this->createBuild($project, $commit['raw_node'], $commit['branch'], $email, $commit['message']); } catch (\Exception $ex) { - header('HTTP/1.1 500 Internal Server Error'); - header('Ex: ' . $ex->getMessage()); - die('FAIL'); + $response->setResponseCode(500); + $response->setContent(array('status' => 'failed', 'error' => $ex->getMessage())); + break; } } - die('OK'); + return $response; } /** @@ -81,6 +84,9 @@ class WebhookController extends \PHPCI\Controller */ public function git($project) { + $response = new b8\Http\Response\JsonResponse(); + $response->setContent(array('status' => 'ok')); + $branch = $this->getParam('branch'); $commit = $this->getParam('commit'); $commitMessage = $this->getParam('message'); @@ -105,12 +111,11 @@ class WebhookController extends \PHPCI\Controller $this->createBuild($project, $commit, $branch, $committer, $commitMessage); } catch (\Exception $ex) { - header('HTTP/1.1 400 Bad Request'); - header('Ex: ' . $ex->getMessage()); - die('FAIL'); + $response->setResponseCode(500); + $response->setContent(array('status' => 'failed', 'error' => $ex->getMessage())); } - die('OK'); + return $response; } /** @@ -118,6 +123,9 @@ class WebhookController extends \PHPCI\Controller */ public function github($project) { + $response = new b8\Http\Response\JsonResponse(); + $response->setContent(array('status' => 'ok')); + switch ($_SERVER['CONTENT_TYPE']) { case 'application/json': $payload = json_decode(file_get_contents('php://input'), true); @@ -128,22 +136,22 @@ class WebhookController extends \PHPCI\Controller break; default: - header('HTTP/1.1 400 Bad Request'); - die('Request content type not supported'); + $response->setResponseCode(401); + $response->setContent(array('status' => 'failed', 'error' => 'Content type not supported.')); + return $response; } // Handle Pull Request web hooks: if (array_key_exists('pull_request', $payload)) { - return $this->githubPullRequest($project, $payload); + return $this->githubPullRequest($project, $payload, $response); } // Handle Push web hooks: if (array_key_exists('commits', $payload)) { - return $this->githubCommitRequest($project, $payload); + return $this->githubCommitRequest($project, $payload, $response); } - header('HTTP/1.1 200 OK'); - die('This request type is not supported, this is not an error.'); + return $response; } /** @@ -151,12 +159,12 @@ class WebhookController extends \PHPCI\Controller * @param $project * @param array $payload */ - protected function githubCommitRequest($project, array $payload) + protected function githubCommitRequest($project, array $payload, b8\Http\Response\JsonResponse $response) { // Github sends a payload when you close a pull request with a // non-existant commit. We don't want this. if (array_key_exists('after', $payload) && $payload['after'] === '0000000000000000000000000000000000000000') { - die('OK'); + return $response; } try { @@ -182,12 +190,12 @@ class WebhookController extends \PHPCI\Controller } } catch (\Exception $ex) { - header('HTTP/1.1 500 Internal Server Error'); - header('Ex: ' . $ex->getMessage()); - die('FAIL'); + $response->setResponseCode(500); + $response->setContent(array('status' => 'failed', 'error' => $ex->getMessage())); + } - die('OK'); + return $response; } /** @@ -195,11 +203,11 @@ class WebhookController extends \PHPCI\Controller * @param $projectId * @param array $payload */ - protected function githubPullRequest($projectId, array $payload) + protected function githubPullRequest($projectId, array $payload, b8\Http\Response\JsonResponse $response) { // We only want to know about open pull requests: if (!in_array($payload['action'], array('opened', 'synchronize', 'reopened'))) { - die('OK'); + return $response; } try { @@ -217,9 +225,10 @@ class WebhookController extends \PHPCI\Controller // Check we got a success response: if (!$response['success']) { - header('HTTP/1.1 500 Internal Server Error'); - header('Ex: Could not get commits, failed API request.'); - die('FAIL'); + $message = 'Could not get commits, failed API request.'; + $response->setResponseCode(500); + $response->setContent(array('status' => 'failed', 'error' => $message)); + return $response; } foreach ($response['body'] as $commit) { @@ -238,12 +247,11 @@ class WebhookController extends \PHPCI\Controller $this->createBuild($projectId, $commit['sha'], $branch, $committer, $message, $extra); } } catch (\Exception $ex) { - header('HTTP/1.1 500 Internal Server Error'); - header('Ex: ' . $ex->getMessage()); - die('FAIL'); + $response->setResponseCode(500); + $response->setContent(array('status' => 'failed', 'error' => $ex->getMessage())); } - die('OK'); + return $response; } /** @@ -251,6 +259,9 @@ class WebhookController extends \PHPCI\Controller */ public function gitlab($project) { + $response = new b8\Http\Response\JsonResponse(); + $response->setContent(array('status' => 'ok')); + $payloadString = file_get_contents("php://input"); $payload = json_decode($payloadString, true); @@ -282,12 +293,11 @@ class WebhookController extends \PHPCI\Controller } } catch (\Exception $ex) { - header('HTTP/1.1 500 Internal Server Error'); - header('Ex: ' . $ex->getMessage()); - die('FAIL'); + $response->setResponseCode(500); + $response->setContent(array('status' => 'failed', 'error' => $ex->getMessage())); } - die('OK'); + return $response; } /**