Refactored Controller.

This commit is contained in:
Dmitry Khomutov 2018-03-04 16:15:21 +07:00
commit d1c37fc293
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
4 changed files with 104 additions and 136 deletions

View file

@ -11,10 +11,12 @@ use PHPCensor\Model\Project;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore;
use b8\Controller;
use PHPCensor\Controller;
use PHPCensor\Config;
use b8\Exception\HttpException\NotFoundException;
use PHPCensor\Store\Factory;
use b8\Http\Request;
use b8\Http\Response;
/**
* Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, Gogs, etc.
@ -42,6 +44,18 @@ class WebhookController extends Controller
*/
protected $buildService;
/**
* @param Config $config
* @param Request $request
* @param Response $response
*/
public function __construct(Config $config, Request $request, Response $response)
{
$this->config = $config;
$this->request = $request;
$this->response = $response;
}
/**
* Initialise the controller, set up stores and services.
*/
@ -63,7 +77,7 @@ class WebhookController extends Controller
{
$response = new b8\Http\Response\JsonResponse();
try {
$data = parent::handleAction($action, $actionParams);
$data = call_user_func_array([$this, $action], $actionParams);
if (isset($data['responseCode'])) {
$response->setResponseCode($data['responseCode']);
unset($data['responseCode']);