Refactored Controllers.
This commit is contained in:
parent
7abd3febc1
commit
ba0d9f14fa
20 changed files with 514 additions and 514 deletions
|
|
@ -12,7 +12,7 @@ use PHPCensor\Http\Response\RedirectResponse;
|
|||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Service\BuildService;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Store\Factory;
|
||||
|
||||
|
|
@ -21,8 +21,13 @@ use PHPCensor\Store\Factory;
|
|||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BuildController extends Controller
|
||||
class BuildController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $layoutName = 'layout';
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\BuildStore
|
||||
*/
|
||||
|
|
@ -33,11 +38,10 @@ class BuildController extends Controller
|
|||
*/
|
||||
protected $buildService;
|
||||
|
||||
/**
|
||||
* Initialise the controller, set up stores and services.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->buildStore = Factory::getStore('Build');
|
||||
$this->buildService = new BuildService($this->buildStore);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,27 +10,33 @@ use PHPCensor\BuildFactory;
|
|||
use PHPCensor\Model\Project;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Service\BuildStatusService;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
|
||||
/**
|
||||
* Build Status Controller - Allows external access to build status information / images.
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BuildStatusController extends Controller
|
||||
class BuildStatusController extends WebController
|
||||
{
|
||||
/* @var \PHPCensor\Store\ProjectStore */
|
||||
protected $projectStore;
|
||||
|
||||
/* @var \PHPCensor\Store\BuildStore */
|
||||
protected $buildStore;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $layoutName = 'layoutPublic';
|
||||
|
||||
/**
|
||||
* Initialise the controller, set up stores and services.
|
||||
* @var \PHPCensor\Store\ProjectStore
|
||||
*/
|
||||
protected $projectStore;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\BuildStore
|
||||
*/
|
||||
protected $buildStore;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->response->disableLayout();
|
||||
parent::init();
|
||||
|
||||
$this->buildStore = Factory::getStore('Build');
|
||||
$this->projectStore = Factory::getStore('Project');
|
||||
|
|
@ -74,7 +80,7 @@ class BuildStatusController extends Controller
|
|||
*
|
||||
* @param $projectId
|
||||
*
|
||||
* @return bool
|
||||
* @return Response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
|
@ -114,16 +120,16 @@ class BuildStatusController extends Controller
|
|||
/**
|
||||
* @param \SimpleXMLElement $xml
|
||||
*
|
||||
* @return boolean
|
||||
* @return Response
|
||||
*/
|
||||
protected function renderXml(\SimpleXMLElement $xml = null)
|
||||
{
|
||||
$this->response->setHeader('Content-Type', 'text/xml');
|
||||
$this->response->setContent($xml->asXML());
|
||||
$this->response->flush();
|
||||
echo $xml->asXML();
|
||||
$response = new Response();
|
||||
|
||||
return true;
|
||||
$response->setHeader('Content-Type', 'text/xml');
|
||||
$response->setContent($xml->asXML());
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -179,11 +185,12 @@ class BuildStatusController extends Controller
|
|||
|
||||
$image = file_get_contents($cacheFile);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setHeader('Content-Type', 'image/svg+xml');
|
||||
$this->response->setContent($image);
|
||||
$response = new Response();
|
||||
|
||||
return $this->response;
|
||||
$response->setHeader('Content-Type', 'image/svg+xml');
|
||||
$response->setContent($image);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use PHPCensor\Form;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
use PHPCensor\Http\Response\RedirectResponse;
|
||||
use PHPCensor\Model\ProjectGroup;
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
|
@ -15,18 +15,22 @@ use PHPCensor\Store\Factory;
|
|||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class GroupController extends Controller
|
||||
class GroupController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $layoutName = 'layout';
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\ProjectGroupStore
|
||||
*/
|
||||
protected $groupStore;
|
||||
|
||||
/**
|
||||
* Set up this controller.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->groupStore = Factory::getStore('ProjectGroup');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,18 @@ namespace PHPCensor\Controller;
|
|||
|
||||
use PHPCensor\Config;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
|
||||
/**
|
||||
* Home Controller - Displays the Dashboard.
|
||||
*/
|
||||
class HomeController extends Controller
|
||||
class HomeController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $layoutName = 'layout';
|
||||
|
||||
/**
|
||||
* Display dashboard:
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,14 +17,20 @@ use PHPCensor\Http\Response\RedirectResponse;
|
|||
use PHPCensor\View;
|
||||
use PHPCensor\Store\Factory;
|
||||
use PHPCensor\Model\Project;
|
||||
use PHPCensor\WebController;
|
||||
|
||||
/**
|
||||
* Project Controller - Allows users to create, edit and view projects.
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class ProjectController extends PHPCensor\Controller
|
||||
class ProjectController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $layoutName = 'layout';
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\ProjectStore
|
||||
*/
|
||||
|
|
@ -50,6 +56,8 @@ class ProjectController extends PHPCensor\Controller
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->buildStore = Factory::getStore('Build');
|
||||
$this->projectStore = Factory::getStore('Project');
|
||||
$this->projectService = new ProjectService($this->projectStore);
|
||||
|
|
@ -69,10 +77,10 @@ class ProjectController extends PHPCensor\Controller
|
|||
$perPage = (integer)$this->getParam('per_page', 10);
|
||||
$builds = $this->getLatestBuildsHtml($projectId, $branch, $environment, (($page - 1) * $perPage), $perPage);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($builds[0]);
|
||||
$response = new PHPCensor\Http\Response();
|
||||
$response->setContent($builds[0]);
|
||||
|
||||
return $this->response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -327,10 +335,10 @@ class ProjectController extends PHPCensor\Controller
|
|||
'ssh_private_key' => $this->getParam('key', null),
|
||||
'ssh_public_key' => $this->getParam('pubkey', null),
|
||||
'build_config' => $this->getParam('build_config', null),
|
||||
'allow_public_status' => $this->getParam('allow_public_status', 0),
|
||||
'allow_public_status' => (boolean)$this->getParam('allow_public_status', 0),
|
||||
'branch' => $this->getParam('branch', null),
|
||||
'default_branch_only' => $this->getParam('default_branch_only', 0),
|
||||
'group' => $this->getParam('group_id', null),
|
||||
'default_branch_only' => (boolean)$this->getParam('default_branch_only', 0),
|
||||
'group' => (integer)$this->getParam('group_id', null),
|
||||
'environments' => $this->getParam('environments', null),
|
||||
];
|
||||
|
||||
|
|
@ -380,11 +388,11 @@ class ProjectController extends PHPCensor\Controller
|
|||
$form = $this->projectForm($values, 'edit/' . $projectId);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new View('Project/edit');
|
||||
$view->type = 'edit';
|
||||
$view->project = $project;
|
||||
$view->form = $form;
|
||||
$view->key = $values['pubkey'];
|
||||
$view = new View('Project/edit');
|
||||
$view->type = 'edit';
|
||||
$view->project = $project;
|
||||
$view->form = $form;
|
||||
$view->key = $values['pubkey'];
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
|
@ -397,11 +405,11 @@ class ProjectController extends PHPCensor\Controller
|
|||
'ssh_private_key' => $this->getParam('key', null),
|
||||
'ssh_public_key' => $this->getParam('pubkey', null),
|
||||
'build_config' => $this->getParam('build_config', null),
|
||||
'allow_public_status' => $this->getParam('allow_public_status', false),
|
||||
'archived' => $this->getParam('archived', false),
|
||||
'allow_public_status' => (boolean)$this->getParam('allow_public_status', false),
|
||||
'archived' => (boolean)$this->getParam('archived', false),
|
||||
'branch' => $this->getParam('branch', null),
|
||||
'default_branch_only' => $this->getParam('default_branch_only', false),
|
||||
'group' => $this->getParam('group_id', null),
|
||||
'default_branch_only' => (boolean)$this->getParam('default_branch_only', false),
|
||||
'group' => (integer)$this->getParam('group_id', null),
|
||||
'environments' => $this->getParam('environments', null),
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace PHPCensor\Controller;
|
|||
use PHPCensor\Form\Element\Csrf;
|
||||
use PHPCensor\Helper\Email;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
use PHPCensor\Http\Response\RedirectResponse;
|
||||
use PHPCensor\Security\Authentication\Service;
|
||||
use PHPCensor\Store\UserStore;
|
||||
|
|
@ -16,8 +16,13 @@ use PHPCensor\Store\Factory;
|
|||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class SessionController extends Controller
|
||||
class SessionController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $layoutName = 'layoutSession';
|
||||
|
||||
/**
|
||||
* @var UserStore
|
||||
*/
|
||||
|
|
@ -33,7 +38,7 @@ class SessionController extends Controller
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->response->disableLayout();
|
||||
parent::init();
|
||||
|
||||
$this->userStore = Factory::getStore('User');
|
||||
$this->authentication = Service::getInstance();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace PHPCensor\Controller;
|
|||
use PHPCensor\Config;
|
||||
use PHPCensor\Exception\HttpException\NotFoundException;
|
||||
use PHPCensor\Form;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Http\Response\RedirectResponse;
|
||||
use PHPCensor\Model\User;
|
||||
|
|
@ -18,8 +18,13 @@ use PHPCensor\Store\Factory;
|
|||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class UserController extends Controller
|
||||
class UserController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $layoutName = 'layout';
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\UserStore
|
||||
*/
|
||||
|
|
@ -35,6 +40,8 @@ class UserController extends Controller
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->userStore = Factory::getStore('User');
|
||||
$this->userService = new UserService($this->userStore);
|
||||
}
|
||||
|
|
@ -70,7 +77,7 @@ class UserController extends Controller
|
|||
$language = null;
|
||||
}
|
||||
|
||||
$perPage = $this->getParam('per_page', null);
|
||||
$perPage = (integer)$this->getParam('per_page', null);
|
||||
if (!$perPage) {
|
||||
$perPage = null;
|
||||
}
|
||||
|
|
@ -183,7 +190,7 @@ class UserController extends Controller
|
|||
$name = $this->getParam('name', null);
|
||||
$email = $this->getParam('email', null);
|
||||
$password = $this->getParam('password', null);
|
||||
$isAdmin = (int)$this->getParam('is_admin', 0);
|
||||
$isAdmin = (boolean)$this->getParam('is_admin', 0);
|
||||
|
||||
$this->userService->createUser($name, $email, 'internal', ['type' => 'internal'], $password, $isAdmin);
|
||||
|
||||
|
|
@ -224,7 +231,7 @@ class UserController extends Controller
|
|||
$name = $this->getParam('name', null);
|
||||
$email = $this->getParam('email', null);
|
||||
$password = $this->getParam('password', null);
|
||||
$isAdmin = (int)$this->getParam('is_admin', 0);
|
||||
$isAdmin = (boolean)$this->getParam('is_admin', 0);
|
||||
|
||||
$this->userService->updateUser($user, $name, $email, $password, $isAdmin);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,18 +43,6 @@ 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.
|
||||
*/
|
||||
|
|
@ -77,7 +65,7 @@ class WebhookController extends Controller
|
|||
{
|
||||
$response = new Response\JsonResponse();
|
||||
try {
|
||||
$data = call_user_func_array([$this, $action], $actionParams);
|
||||
$data = parent::handleAction($action, $actionParams);
|
||||
if (isset($data['responseCode'])) {
|
||||
$response->setResponseCode($data['responseCode']);
|
||||
unset($data['responseCode']);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
use PHPCensor\Store\Factory;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Model\Project;
|
||||
|
|
@ -15,7 +15,7 @@ use PHPCensor\Store\ProjectGroupStore;
|
|||
/**
|
||||
* Widget All Projects Controller
|
||||
*/
|
||||
class WidgetAllProjectsController extends Controller
|
||||
class WidgetAllProjectsController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var BuildStore
|
||||
|
|
@ -37,6 +37,8 @@ class WidgetAllProjectsController extends Controller
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->buildStore = Factory::getStore('Build');
|
||||
$this->projectStore = Factory::getStore('Project');
|
||||
$this->groupStore = Factory::getStore('ProjectGroup');
|
||||
|
|
@ -49,10 +51,10 @@ class WidgetAllProjectsController extends Controller
|
|||
{
|
||||
$this->view->groups = $this->getGroupInfo();
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
$response = new Response();
|
||||
$response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -142,9 +144,9 @@ class WidgetAllProjectsController extends Controller
|
|||
$this->view->failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED);
|
||||
$this->view->counts = $counts;
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
$response = new Response();
|
||||
$response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ namespace PHPCensor\Controller;
|
|||
use PHPCensor\Store\Factory;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Http\Response;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
use PHPCensor\Store\BuildStore;
|
||||
use PHPCensor\Store\ProjectStore;
|
||||
|
||||
/**
|
||||
* Widget Build Errors Controller
|
||||
*/
|
||||
class WidgetBuildErrorsController extends Controller
|
||||
class WidgetBuildErrorsController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var BuildStore
|
||||
|
|
@ -29,6 +29,8 @@ class WidgetBuildErrorsController extends Controller
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->buildStore = Factory::getStore('Build');
|
||||
$this->projectStore = Factory::getStore('Project');
|
||||
}
|
||||
|
|
@ -42,10 +44,10 @@ class WidgetBuildErrorsController extends Controller
|
|||
|
||||
$this->view->projects = $this->renderAllProjectsLatestBuilds($view);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
$response = new Response();
|
||||
$response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,10 +55,10 @@ class WidgetBuildErrorsController extends Controller
|
|||
*/
|
||||
public function update()
|
||||
{
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->renderAllProjectsLatestBuilds($this->view));
|
||||
$response = new Response();
|
||||
$response->setContent($this->renderAllProjectsLatestBuilds($this->view));
|
||||
|
||||
return $this->response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ use PHPCensor\Store\Factory;
|
|||
use PHPCensor\View;
|
||||
use PHPCensor\Http\Response;
|
||||
use PHPCensor\BuildFactory;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\WebController;
|
||||
use PHPCensor\Store\BuildStore;
|
||||
|
||||
/**
|
||||
* Widget Last Builds Controller
|
||||
*/
|
||||
class WidgetLastBuildsController extends Controller
|
||||
class WidgetLastBuildsController extends WebController
|
||||
{
|
||||
/**
|
||||
* @var BuildStore
|
||||
|
|
@ -24,6 +24,8 @@ class WidgetLastBuildsController extends Controller
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->buildStore = Factory::getStore('Build');
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +45,10 @@ class WidgetLastBuildsController extends Controller
|
|||
$view->builds = $builds;
|
||||
$this->view->timeline = $view->render();
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
$response = new Response();
|
||||
$response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,9 +64,9 @@ class WidgetLastBuildsController extends Controller
|
|||
|
||||
$this->view->builds = $builds;
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
$response = new Response();
|
||||
$response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue