Controller are now services.

This commit is contained in:
Marco Vito Moscaritolo 2015-05-31 13:31:34 +02:00
commit 56082f201b
8 changed files with 207 additions and 62 deletions

View file

@ -12,11 +12,15 @@ namespace PHPCI\Controller;
use b8;
use b8\Exception\HttpException\NotFoundException;
use b8\Http\Response\JsonResponse;
use b8\Http\Request;
use b8\Http\Response;
use PHPCI\Config;
use PHPCI\BuildFactory;
use PHPCI\Helper\AnsiConverter;
use PHPCI\Helper\Lang;
use PHPCI\Model\Build;
use PHPCI\Model\Project;
use PHPCI\Store\BuildStore;
use PHPCI\Service\BuildService;
/**
@ -28,22 +32,27 @@ use PHPCI\Service\BuildService;
class BuildController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\BuildStore
* @var BuildStore
*/
protected $buildStore;
/**
* @var \PHPCI\Service\BuildService
* @var BuildService
*/
protected $buildService;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
public function __construct(
Config $config,
Request $request,
Response $response,
BuildStore $buildStore,
BuildService $buildService
)
{
$this->buildStore = b8\Store\Factory::getStore('Build');
$this->buildService = new BuildService($this->buildStore);
parent::__construct($config, $request, $response);
$this->buildStore = $buildStore;
$this->buildService = $buildService;
}
/**

View file

@ -12,10 +12,15 @@ namespace PHPCI\Controller;
use b8;
use b8\Exception\HttpException\NotFoundException;
use b8\Store;
use b8\Http\Request;
use b8\Http\Response;
use PHPCI\Config;
use PHPCI\BuildFactory;
use PHPCI\Model\Project;
use PHPCI\Model\Build;
use PHPCI\Service\BuildStatusService;
use PHPCI\Store\BuildStore;
use PHPCI\Store\ProjectStore;
/**
* Build Status Controller - Allows external access to build status information / images.
@ -25,19 +30,30 @@ use PHPCI\Service\BuildStatusService;
*/
class BuildStatusController extends \PHPCI\Controller
{
/* @var \PHPCI\Store\ProjectStore */
protected $projectStore;
/* @var \PHPCI\Store\BuildStore */
/**
* @var BuildStore
*/
protected $buildStore;
/**
* Initialise the controller, set up stores and services.
* @var ProjectStore
*/
public function init()
protected $projectStore;
public function __construct(
Config $config,
Request $request,
Response $response,
BuildStore $buildStore,
ProjectStore $projectStore
)
{
parent::__construct($config, $request, $response);
$this->response->disableLayout();
$this->buildStore = Store\Factory::getStore('Build');
$this->projectStore = Store\Factory::getStore('Project');
$this->buildStore = $buildStore;
$this->projectStore = $projectStore;
}
/**

View file

@ -10,9 +10,14 @@
namespace PHPCI\Controller;
use b8;
use b8\Http\Request;
use b8\Http\Response;
use PHPCI\Config;
use PHPCI\BuildFactory;
use PHPCI\Helper\Lang;
use PHPCI\Model\Build;
use PHPCI\Store\BuildStore;
use PHPCI\Store\ProjectStore;
/**
* Home Controller - Displays the PHPCI Dashboard.
@ -23,22 +28,27 @@ use PHPCI\Model\Build;
class HomeController extends \PHPCI\Controller
{
/**
* @var \b8\Store\BuildStore
* @var BuildStore
*/
protected $buildStore;
/**
* @var \b8\Store\ProjectStore
* @var ProjectStore
*/
protected $projectStore;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
public function __construct(
Config $config,
Request $request,
Response $response,
BuildStore $buildStore,
ProjectStore $projectStore
)
{
$this->buildStore = b8\Store\Factory::getStore('Build');
$this->projectStore = b8\Store\Factory::getStore('Project');
parent::__construct($config, $request, $response);
$this->buildStore = $buildStore;
$this->projectStore = $projectStore;
}
/**

View file

@ -13,11 +13,16 @@ use b8;
use b8\Form;
use b8\Exception\HttpException\NotFoundException;
use b8\Store;
use b8\Http\Request;
use b8\Http\Response;
use PHPCI;
use PHPCI\Config;
use PHPCI\BuildFactory;
use PHPCI\Helper\Github;
use PHPCI\Helper\Lang;
use PHPCI\Helper\SshKey;
use PHPCI\Store\BuildStore;
use PHPCI\Store\ProjectStore;
use PHPCI\Service\BuildService;
use PHPCI\Service\ProjectService;
@ -30,34 +35,41 @@ use PHPCI\Service\ProjectService;
class ProjectController extends PHPCI\Controller
{
/**
* @var \PHPCI\Store\ProjectStore
* @var ProjectStore
*/
protected $projectStore;
/**
* @var \PHPCI\Service\ProjectService
* @var ProjectService
*/
protected $projectService;
/**
* @var \PHPCI\Store\BuildStore
* @var BuildStore
*/
protected $buildStore;
/**
* @var \PHPCI\Service\BuildService
* @var BuildService
*/
protected $buildService;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
public function __construct(
Config $config,
Request $request,
Response $response,
BuildStore $buildStore,
ProjectStore $projectStore,
ProjectService $projectService,
BuildService $buildService
)
{
$this->buildStore = Store\Factory::getStore('Build');
$this->projectStore = Store\Factory::getStore('Project');
$this->projectService = new ProjectService($this->projectStore);
$this->buildService = new BuildService($this->buildStore);
parent::__construct($config, $request, $response);
$this->buildStore = $buildStore;
$this->projectStore = $projectStore;
$this->projectService = $projectService;
$this->buildService = $buildService;
}
/**
@ -313,7 +325,7 @@ class ProjectController extends PHPCI\Controller
'local' => Lang::get('local'),
'hg' => Lang::get('hg'),
'svn' => Lang::get('svn'),
);
);
$field = Form\Element\Select::create('type', Lang::get('where_hosted'), true);
$field->setPattern('^(github|bitbucket|gitlab|remote|local|hg|svn)');

View file

@ -10,8 +10,12 @@
namespace PHPCI\Controller;
use b8;
use b8\Http\Request;
use b8\Http\Response;
use PHPCI\Config;
use PHPCI\Helper\Email;
use PHPCI\Helper\Lang;
use PHPCI\Store\UserStore;
/**
* Session Controller - Handles user login / logout.
@ -22,17 +26,21 @@ use PHPCI\Helper\Lang;
class SessionController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\UserStore
* @var UserStore
*/
protected $userStore;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
public function __construct(
Config $config,
Request $request,
Response $response,
UserStore $userStore,
)
{
parent::__construct($config, $request, $response);
$this->response->disableLayout();
$this->userStore = b8\Store\Factory::getStore('User');
$this->userStore = $userStore;
}
/**

View file

@ -12,8 +12,12 @@ namespace PHPCI\Controller;
use b8;
use b8\Exception\HttpException\NotFoundException;
use b8\Form;
use b8\Http\Request;
use b8\Http\Response;
use PHPCI\Config;
use PHPCI\Controller;
use PHPCI\Helper\Lang;
use PHPCI\Store\UserStore;
use PHPCI\Service\UserService;
/**
@ -25,22 +29,27 @@ use PHPCI\Service\UserService;
class UserController extends Controller
{
/**
* @var \PHPCI\Store\UserStore
* @var UserStore
*/
protected $userStore;
/**
* @var \PHPCI\Service\UserService
* @var UserService
*/
protected $userService;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
public function __construct(
Config $config,
Request $request,
Response $response,
UserStore $userStore,
UserService $userService
)
{
$this->userStore = b8\Store\Factory::getStore('User');
$this->userService = new UserService($this->userStore);
parent::__construct($config, $request, $response);
$this->userStore = $userStore;
$this->userService = $userService;
}
/**
@ -48,8 +57,8 @@ class UserController extends Controller
*/
public function index()
{
$users = $this->userStore->getWhere(array(), 1000, 0, array(), array('email' => 'ASC'));
$this->view->users = $users;
$users = $this->userStore->getWhere(array(), 1000, 0, array(), array('email' => 'ASC'));
$this->view->users = $users;
$this->layout->title = Lang::get('manage_users');

View file

@ -11,7 +11,10 @@ namespace PHPCI\Controller;
use b8;
use b8\Store;
use b8\Http\Request;
use b8\Http\Response;
use Exception;
use PHPCI\Config;
use PHPCI\BuildFactory;
use PHPCI\Model\Project;
use PHPCI\Service\BuildService;
@ -45,14 +48,20 @@ class WebhookController extends \b8\Controller
*/
protected $buildService;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
public function __construct(
Config $config,
Request $request,
Response $response,
BuildStore $buildStore,
ProjectStore $projectStore,
BuildService $buildService
)
{
$this->buildStore = Store\Factory::getStore('Build');
$this->projectStore = Store\Factory::getStore('Project');
$this->buildService = new BuildService($this->buildStore);
parent::__construct($config, $request, $response);
$this->buildStore = $buildStore;
$this->projectStore = $projectStore;
$this->buildService = $buildService;
}
/** Handle the action, Ensuring to return a JsonResponse.

View file

@ -47,15 +47,87 @@ services:
- @storage.user
- @storage.project
- @service_container
application.controller.home:
class: PHPCI\Controller\HomeController
arguments:
- @config
- @http.request
- @http.response
- @storage.build
- @storage.project
application.controller.project:
class: PHPCI\Controller\ProjectController
arguments:
- @config
- @http.request
- @http.response
- @storage.build
- @storage.project
- @service.project
- @service.build
application.controller.build:
class: PHPCI\Controller\BuildController
arguments:
- @config
- @http.request
- @http.response
- @storage.build
- @service.build
application.controller.buildstatus:
class: PHPCI\Controller\BuildStatusController
arguments:
- @config
- @http.request
- @http.response
- @storage.build
- @storage.project
application.controller.user:
class: PHPCI\Controller\UserController
arguments:
- @config
- @http.request
- @http.response
- @storage.user
- @service.user
application.controller.session:
class: PHPCI\Controller\SessionController
arguments:
- @config
- @http.request
- @http.response
- @storage.user
application.controller.settings:
class: PHPCI\Controller\SettingsController
arguments:
- @config
- @http.request
- @http.response
- @storage.user
- @service.user
application.controller.plugin:
class: PHPCI\Controller\PluginController
arguments:
- @config
- @http.request
- @http.response
application.controller.webhook:
class: PHPCI\Controller\WebhookController
arguments:
- @config
- @http.request
- @http.response
- @storage.build
- @storage.project
- @service.build
service.build:
class: PHPCI\Service\BuildService
arguments: [@storage.build]
service.user:
class: PHPCI\Service\UserService
arguments: [@storage.user]
service.build:
class: PHPCI\Service\BuildService
arguments: [@storage.build]
service.project:
class: PHPCI\Service\ProjectService
arguments: [@storage.project]
process_control:
factory: [PHPCI\ProcessControl\Factory, getInstance]
console.application: