Refactored Http.

This commit is contained in:
Dmitry Khomutov 2018-03-04 17:22:14 +07:00
parent aadfabd714
commit 1fdf9a7ab1
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
19 changed files with 48 additions and 42 deletions

View file

@ -4,5 +4,5 @@ session_start();
require_once(dirname(__DIR__) . '/bootstrap.php'); require_once(dirname(__DIR__) . '/bootstrap.php');
$fc = new PHPCensor\Application($config, new b8\Http\Request()); $fc = new PHPCensor\Application($config, new PHPCensor\Http\Request());
print $fc->handleRequest(); print $fc->handleRequest();

View file

@ -3,12 +3,12 @@
namespace PHPCensor; namespace PHPCensor;
use PHPCensor\Exception\HttpException; use PHPCensor\Exception\HttpException;
use b8\Http\Response; use PHPCensor\Http\Response;
use b8\Http\Response\RedirectResponse; use PHPCensor\Http\Response\RedirectResponse;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Http\Request; use PHPCensor\Http\Request;
use b8\Http\Router; use PHPCensor\Http\Router;
/** /**
* @author Dan Cryer <dan@block8.co.uk> * @author Dan Cryer <dan@block8.co.uk>

View file

@ -3,8 +3,8 @@
namespace PHPCensor; namespace PHPCensor;
use PHPCensor\Exception\HttpException\ForbiddenException; use PHPCensor\Exception\HttpException\ForbiddenException;
use b8\Http\Request; use PHPCensor\Http\Request;
use b8\Http\Response; use PHPCensor\Http\Response;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Model\User; use PHPCensor\Model\User;
use PHPCensor\Store\UserStore; use PHPCensor\Store\UserStore;

View file

@ -3,11 +3,12 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Http\Response\JsonResponse; use PHPCensor\Http\Response\JsonResponse;
use JasonGrimes\Paginator; use JasonGrimes\Paginator;
use PHPCensor\BuildFactory; use PHPCensor\BuildFactory;
use PHPCensor\Helper\AnsiConverter; use PHPCensor\Helper\AnsiConverter;
use PHPCensor\Helper\Lang; use PHPCensor\Helper\Lang;
use PHPCensor\Http\Response\RedirectResponse;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;
use PHPCensor\Model\User; use PHPCensor\Model\User;
use PHPCensor\Service\BuildService; use PHPCensor\Service\BuildService;
@ -251,7 +252,7 @@ class BuildController extends Controller
$_SESSION['global_error'] = Lang::get('add_to_queue_failed'); $_SESSION['global_error'] = Lang::get('add_to_queue_failed');
} }
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL.'build/view/' . $build->getId()); $response->setHeader('Location', APP_URL.'build/view/' . $build->getId());
return $response; return $response;
@ -272,7 +273,7 @@ class BuildController extends Controller
$this->buildService->deleteBuild($build); $this->buildService->deleteBuild($build);
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL.'project/view/' . $build->getProjectId()); $response->setHeader('Location', APP_URL.'project/view/' . $build->getProjectId());
return $response; return $response;

View file

@ -2,8 +2,8 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use b8\Http\Response; use PHPCensor\Http\Response;
use b8\Http\Response\RedirectResponse; use PHPCensor\Http\Response\RedirectResponse;
use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Exception\HttpException\NotFoundException;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\BuildFactory; use PHPCensor\BuildFactory;

View file

@ -5,6 +5,7 @@ namespace PHPCensor\Controller;
use b8; use b8;
use b8\Form; use b8\Form;
use PHPCensor\Controller; use PHPCensor\Controller;
use PHPCensor\Http\Response\RedirectResponse;
use PHPCensor\Model\ProjectGroup; use PHPCensor\Model\ProjectGroup;
use PHPCensor\Helper\Lang; use PHPCensor\Helper\Lang;
use PHPCensor\Model\User; use PHPCensor\Model\User;
@ -58,8 +59,10 @@ class GroupController extends Controller
/** /**
* Add or edit a project group. * Add or edit a project group.
*
* @param null $groupId * @param null $groupId
* @return void|b8\Http\Response\RedirectResponse *
* @return RedirectResponse
*/ */
public function edit($groupId = null) public function edit($groupId = null)
{ {
@ -83,7 +86,7 @@ class GroupController extends Controller
$this->groupStore->save($group); $this->groupStore->save($group);
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL.'group'); $response->setHeader('Location', APP_URL.'group');
return $response; return $response;
@ -112,7 +115,7 @@ class GroupController extends Controller
/** /**
* Delete a project group. * Delete a project group.
* @param $groupId * @param $groupId
* @return b8\Http\Response\RedirectResponse * @return RedirectResponse
*/ */
public function delete($groupId) public function delete($groupId)
{ {
@ -120,7 +123,7 @@ class GroupController extends Controller
$group = $this->groupStore->getById($groupId); $group = $this->groupStore->getById($groupId);
$this->groupStore->delete($group); $this->groupStore->delete($group);
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL.'group'); $response->setHeader('Location', APP_URL.'group');
return $response; return $response;
} }

View file

@ -13,7 +13,7 @@ use PHPCensor\Helper\SshKey;
use PHPCensor\Service\BuildService; use PHPCensor\Service\BuildService;
use PHPCensor\Service\ProjectService; use PHPCensor\Service\ProjectService;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;
use b8\Http\Response\RedirectResponse; use PHPCensor\Http\Response\RedirectResponse;
use PHPCensor\View; use PHPCensor\View;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
@ -58,7 +58,7 @@ class ProjectController extends PHPCensor\Controller
/** /**
* @param int $projectId * @param int $projectId
* *
* @return b8\Http\Response * @return PHPCensor\Http\Response
*/ */
public function ajaxBuilds($projectId) public function ajaxBuilds($projectId)
{ {
@ -581,7 +581,7 @@ class ProjectController extends PHPCensor\Controller
{ {
$github = new Github(); $github = new Github();
$response = new b8\Http\Response\JsonResponse(); $response = new PHPCensor\Http\Response\JsonResponse();
$response->setContent($github->getRepositories()); $response->setContent($github->getRepositories());
return $response; return $response;

View file

@ -6,6 +6,7 @@ use b8;
use PHPCensor\Helper\Email; use PHPCensor\Helper\Email;
use PHPCensor\Helper\Lang; use PHPCensor\Helper\Lang;
use PHPCensor\Controller; use PHPCensor\Controller;
use PHPCensor\Http\Response\RedirectResponse;
use PHPCensor\Security\Authentication\Service; use PHPCensor\Security\Authentication\Service;
use PHPCensor\Store\UserStore; use PHPCensor\Store\UserStore;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
@ -48,7 +49,7 @@ class SessionController extends Controller
if ($user) { if ($user) {
$_SESSION['php-censor-user-id'] = $user->getId(); $_SESSION['php-censor-user-id'] = $user->getId();
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', $this->getLoginRedirect()); $response->setHeader('Location', $this->getLoginRedirect());
return $response; return $response;
@ -108,7 +109,7 @@ class SessionController extends Controller
); );
} }
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', $this->getLoginRedirect()); $response->setHeader('Location', $this->getLoginRedirect());
return $response; return $response;
@ -176,7 +177,7 @@ class SessionController extends Controller
true true
); );
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL); $response->setHeader('Location', APP_URL);
return $response; return $response;
} }
@ -237,7 +238,7 @@ class SessionController extends Controller
$_SESSION['php-censor-user-id'] = $user->getId(); $_SESSION['php-censor-user-id'] = $user->getId();
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL); $response->setHeader('Location', APP_URL);
return $response; return $response;
} }

View file

@ -7,6 +7,7 @@ use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Form; use b8\Form;
use PHPCensor\Controller; use PHPCensor\Controller;
use PHPCensor\Helper\Lang; use PHPCensor\Helper\Lang;
use PHPCensor\Http\Response\RedirectResponse;
use PHPCensor\Model\User; use PHPCensor\Model\User;
use PHPCensor\Service\UserService; use PHPCensor\Service\UserService;
use PHPCensor\View; use PHPCensor\View;
@ -183,7 +184,7 @@ class UserController extends Controller
$this->userService->createUser($name, $email, 'internal', json_encode(['type' => 'internal']), $password, $isAdmin); $this->userService->createUser($name, $email, 'internal', json_encode(['type' => 'internal']), $password, $isAdmin);
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL . 'user'); $response->setHeader('Location', APP_URL . 'user');
return $response; return $response;
} }
@ -224,7 +225,7 @@ class UserController extends Controller
$this->userService->updateUser($user, $name, $email, $password, $isAdmin); $this->userService->updateUser($user, $name, $email, $password, $isAdmin);
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL . 'user'); $response->setHeader('Location', APP_URL . 'user');
return $response; return $response;
} }
@ -298,7 +299,7 @@ class UserController extends Controller
$this->userService->deleteUser($user); $this->userService->deleteUser($user);
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', APP_URL . 'user'); $response->setHeader('Location', APP_URL . 'user');
return $response; return $response;
} }

View file

@ -14,8 +14,8 @@ use PHPCensor\Controller;
use PHPCensor\Config; use PHPCensor\Config;
use PHPCensor\Exception\HttpException\NotFoundException; use PHPCensor\Exception\HttpException\NotFoundException;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use b8\Http\Request; use PHPCensor\Http\Request;
use b8\Http\Response; use PHPCensor\Http\Response;
/** /**
* Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, Gogs, etc. * Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, Gogs, etc.
@ -70,7 +70,7 @@ class WebhookController extends Controller
* @param string $action * @param string $action
* @param mixed $actionParams * @param mixed $actionParams
* *
* @return \b8\Http\Response * @return Response
*/ */
public function handleAction($action, $actionParams) public function handleAction($action, $actionParams)
{ {

View file

@ -7,7 +7,7 @@ use PHPCensor\Controller;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\View; use PHPCensor\View;
use PHPCensor\Model\Project; use PHPCensor\Model\Project;
use b8\Http\Response; use PHPCensor\Http\Response;
use PHPCensor\Store\BuildStore; use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore; use PHPCensor\Store\ProjectStore;
use PHPCensor\Store\ProjectGroupStore; use PHPCensor\Store\ProjectGroupStore;

View file

@ -4,7 +4,7 @@ namespace PHPCensor\Controller;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\View; use PHPCensor\View;
use b8\Http\Response; use PHPCensor\Http\Response;
use PHPCensor\Controller; use PHPCensor\Controller;
use PHPCensor\Store\BuildStore; use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore; use PHPCensor\Store\ProjectStore;

View file

@ -4,7 +4,7 @@ namespace PHPCensor\Controller;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\View; use PHPCensor\View;
use b8\Http\Response; use PHPCensor\Http\Response;
use PHPCensor\BuildFactory; use PHPCensor\BuildFactory;
use PHPCensor\Controller; use PHPCensor\Controller;
use PHPCensor\Store\BuildStore; use PHPCensor\Store\BuildStore;

View file

@ -1,6 +1,6 @@
<?php <?php
namespace b8\Http; namespace PHPCensor\Http;
class Request class Request
{ {

View file

@ -1,6 +1,6 @@
<?php <?php
namespace b8\Http; namespace PHPCensor\Http;
class Response class Response
{ {

View file

@ -1,8 +1,8 @@
<?php <?php
namespace b8\Http\Response; namespace PHPCensor\Http\Response;
use b8\Http\Response; use PHPCensor\Http\Response;
class JsonResponse extends Response class JsonResponse extends Response
{ {

View file

@ -1,8 +1,8 @@
<?php <?php
namespace b8\Http\Response; namespace PHPCensor\Http\Response;
use b8\Http\Response; use PHPCensor\Http\Response;
class RedirectResponse extends Response class RedirectResponse extends Response
{ {

View file

@ -1,6 +1,6 @@
<?php <?php
namespace b8\Http; namespace PHPCensor\Http;
use PHPCensor\Application; use PHPCensor\Application;
use PHPCensor\Config; use PHPCensor\Config;

View file

@ -10,13 +10,13 @@ class WebhookControllerTest extends \PHPUnit\Framework\TestCase
{ {
$webController = new WebhookController( $webController = new WebhookController(
$this->prophesize('PHPCensor\Config')->reveal(), $this->prophesize('PHPCensor\Config')->reveal(),
$this->prophesize('b8\Http\Request')->reveal(), $this->prophesize('PHPCensor\Http\Request')->reveal(),
$this->prophesize('b8\Http\Response')->reveal() $this->prophesize('PHPCensor\Http\Response')->reveal()
); );
$error = $webController->handleAction('test', []); $error = $webController->handleAction('test', []);
self::assertInstanceOf('b8\Http\Response\JsonResponse', $error); self::assertInstanceOf('PHPCensor\Http\Response\JsonResponse', $error);
$responseData = $error->getData(); $responseData = $error->getData();
self::assertEquals(500, $responseData['code']); self::assertEquals(500, $responseData['code']);