Better docblock type hinting for stores.

This commit is contained in:
Dan Cryer 2013-10-08 18:24:20 +01:00
parent cccf0b9869
commit d060227fbd
10 changed files with 105 additions and 50 deletions

View file

@ -9,6 +9,16 @@ use b8\View;
class Controller extends \b8\Controller
{
/**
* @var \b8\View
*/
protected $controllerView;
/**
* @var \b8\View
*/
protected $view;
public function init() {}
public function __construct(Config $config, Request $request, Response $response)

View file

@ -21,9 +21,14 @@ use PHPCI\Model\Build;
*/
class BitbucketController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\BuildStore
*/
protected $buildStore;
public function init()
{
$this->_buildStore = Store\Factory::getStore('Build');
$this->buildStore = Store\Factory::getStore('Build');
}
/**
@ -31,9 +36,9 @@ class BitbucketController extends \PHPCI\Controller
*/
public function webhook($project)
{
$payload = json_decode($this->getParam('payload'), true);
$branches = array();
$commits = array();
$payload = json_decode($this->getParam('payload'), true);
$branches = array();
$commits = array();
foreach ($payload['commits'] as $commit) {
if (!in_array($commit['branch'], $branches)) {
@ -45,14 +50,14 @@ class BitbucketController extends \PHPCI\Controller
foreach ($branches as $branch) {
try {
$build = new Build();
$build = new Build();
$build->setProjectId($project);
$build->setCommitId($commits[$branch]);
$build->setStatus(0);
$build->setLog('');
$build->setCreated(new \DateTime());
$build->setBranch($branch);
$this->_buildStore->save($build);
$this->buildStore->save($build);
} catch (\Exception $ex) {
}
}

View file

@ -20,9 +20,14 @@ use PHPCI\Model\Build;
*/
class BuildController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\BuildStore
*/
protected $buildStore;
public function init()
{
$this->_buildStore = b8\Store\Factory::getStore('Build');
$this->buildStore = b8\Store\Factory::getStore('Build');
}
/**
@ -30,7 +35,7 @@ class BuildController extends \PHPCI\Controller
*/
public function view($buildId)
{
$build = $this->_buildStore->getById($buildId);
$build = $this->buildStore->getById($buildId);
$this->view->plugins = $this->getUiPlugins();
$this->view->build = $build;
$this->view->data = $this->getBuildData($buildId);
@ -66,13 +71,13 @@ class BuildController extends \PHPCI\Controller
*/
public function meta($buildId)
{
$build = $this->_buildStore->getById($buildId);
$build = $this->buildStore->getById($buildId);
$key = $this->getParam('key', null);
$numBuilds = $this->getParam('num_builds', 1);
$data = null;
if ($key && $build) {
$data = $this->_buildStore->getMeta($key, $build->getProjectId(), $buildId, $numBuilds);
$data = $this->buildStore->getMeta($key, $build->getProjectId(), $buildId, $numBuilds);
}
die(json_encode($data));
@ -83,7 +88,7 @@ class BuildController extends \PHPCI\Controller
*/
protected function getBuildData($buildId)
{
$build = $this->_buildStore->getById($buildId);
$build = $this->buildStore->getById($buildId);
$data = array();
$data['status'] = (int)$build->getStatus();
@ -101,7 +106,7 @@ class BuildController extends \PHPCI\Controller
*/
public function rebuild($buildId)
{
$copy = $this->_buildStore->getById($buildId);
$copy = $this->buildStore->getById($buildId);
$build = new Build();
$build->setProjectId($copy->getProjectId());
@ -110,7 +115,7 @@ class BuildController extends \PHPCI\Controller
$build->setBranch($copy->getBranch());
$build->setCreated(new \DateTime());
$build = $this->_buildStore->save($build);
$build = $this->buildStore->save($build);
header('Location: '.PHPCI_URL.'build/view/' . $build->getId());
exit;
@ -125,8 +130,8 @@ class BuildController extends \PHPCI\Controller
throw new \Exception('You do not have permission to do that.');
}
$build = $this->_buildStore->getById($buildId);
$this->_buildStore->delete($build);
$build = $this->buildStore->getById($buildId);
$this->buildStore->delete($build);
header('Location: '.PHPCI_URL.'project/view/' . $build->getProjectId());
exit;

View file

@ -22,9 +22,14 @@ use PHPCI\Model\Build;
*/
class BuildStatusController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\ProjectStore
*/
protected $projectStore;
public function init()
{
$this->_projectStore = Store\Factory::getStore('Project');
$this->projectStore = Store\Factory::getStore('Project');
}
/**
@ -32,9 +37,9 @@ class BuildStatusController extends \PHPCI\Controller
*/
public function image($projectId)
{
$branch = $this->getParam('branch', 'master');
$project = $this->_projectStore->getById($projectId);
$status = 'ok';
$branch = $this->getParam('branch', 'master');
$project = $this->projectStore->getById($projectId);
$status = 'ok';
if (isset($project) && $project instanceof Project) {
$build = $project->getLatestBuild($branch, array(2,3));

View file

@ -21,9 +21,14 @@ use PHPCI\Model\Build;
*/
class GithubController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\BuildStore
*/
protected $buildStore;
public function init()
{
$this->_buildStore = Store\Factory::getStore('Build');
$this->buildStore = Store\Factory::getStore('Build');
}
/**
@ -53,7 +58,7 @@ class GithubController extends \PHPCI\Controller
}
try {
$build = $this->_buildStore->save($build);
$build = $this->buildStore->save($build);
$build->sendStatusPostback();
} catch (\Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');

View file

@ -21,9 +21,14 @@ use PHPCI\Model\Build;
*/
class GitlabController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\BuildStore
*/
protected $buildStore;
public function init()
{
$this->_buildStore = Store\Factory::getStore('Build');
$this->buildStore = Store\Factory::getStore('Build');
}
/**
@ -48,7 +53,7 @@ class GitlabController extends \PHPCI\Controller
}
try {
$build = $this->_buildStore->save($build);
$build = $this->buildStore->save($build);
$build->sendStatusPostback();
} catch (\Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');

View file

@ -22,17 +22,17 @@ class HomeController extends \PHPCI\Controller
/**
* @var \b8\Store\BuildStore
*/
protected $_buildStore;
protected $buildStore;
/**
* @var \b8\Store\ProjectStore
*/
protected $_projectStore;
protected $projectStore;
public function init()
{
$this->_buildStore = b8\Store\Factory::getStore('Build');
$this->_projectStore = b8\Store\Factory::getStore('Project');
$this->buildStore = b8\Store\Factory::getStore('Build');
$this->projectStore = b8\Store\Factory::getStore('Project');
}
/**
@ -40,11 +40,11 @@ class HomeController extends \PHPCI\Controller
*/
public function index()
{
$projects = $this->_projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));
$projects = $this->projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));
$summaryBuilds = array();
foreach ($projects['items'] as $project) {
$summaryBuilds[$project->getId()] = $this->_buildStore->getLatestBuilds($project->getId());
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());
}
$summaryView = new b8\View('SummaryTable');
@ -71,7 +71,7 @@ class HomeController extends \PHPCI\Controller
*/
protected function getLatestBuildsHtml()
{
$builds = $this->_buildStore->getWhere(array(), 5, 0, array(), array('id' => 'DESC'));
$builds = $this->buildStore->getWhere(array(), 5, 0, array(), array('id' => 'DESC'));
$view = new b8\View('BuildsTable');
$view->builds = $builds['items'];

View file

@ -24,10 +24,20 @@ use b8\Form;
*/
class ProjectController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\BuildStore
*/
protected $buildStore;
/**
* @var \PHPCI\Store\ProjectStore
*/
protected $projectStore;
public function init()
{
$this->_buildStore = Store\Factory::getStore('Build');
$this->_projectStore = Store\Factory::getStore('Project');
$this->buildStore = Store\Factory::getStore('Build');
$this->projectStore = Store\Factory::getStore('Project');
}
/**
@ -35,7 +45,7 @@ class ProjectController extends \PHPCI\Controller
*/
public function view($projectId)
{
$project = $this->_projectStore->getById($projectId);
$project = $this->projectStore->getById($projectId);
$page = $this->getParam('p', 1);
$builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * 10));
@ -53,7 +63,7 @@ class ProjectController extends \PHPCI\Controller
public function build($projectId)
{
/* @var \PHPCI\Model\Project $project */
$project = $this->_projectStore->getById($projectId);
$project = $this->projectStore->getById($projectId);
$build = new Build();
$build->setProjectId($projectId);
@ -62,7 +72,7 @@ class ProjectController extends \PHPCI\Controller
$build->setBranch($project->getType() === 'hg' ? 'default' : 'master');
$build->setCreated(new \DateTime());
$build = $this->_buildStore->save($build);
$build = $this->buildStore->save($build);
header('Location: '.PHPCI_URL.'build/view/' . $build->getId());
exit;
@ -77,8 +87,8 @@ class ProjectController extends \PHPCI\Controller
throw new \Exception('You do not have permission to do that.');
}
$project = $this->_projectStore->getById($projectId);
$this->_projectStore->delete($project);
$project = $this->projectStore->getById($projectId);
$this->projectStore->delete($project);
header('Location: '.PHPCI_URL);
exit;
@ -100,7 +110,7 @@ class ProjectController extends \PHPCI\Controller
{
$criteria = array('project_id' => $projectId);
$order = array('id' => 'DESC');
$builds = $this->_buildStore->getWhere($criteria, 10, $start, array(), $order);
$builds = $this->buildStore->getWhere($criteria, 10, $start, array(), $order);
$view = new b8\View('BuildsTable');
$view->builds = $builds['items'];
@ -176,7 +186,7 @@ class ProjectController extends \PHPCI\Controller
$project = new Project();
$project->setValues($values);
$project = $this->_projectStore->save($project);
$project = $this->projectStore->save($project);
header('Location: '.PHPCI_URL.'project/view/' . $project->getId());
die;
@ -219,7 +229,7 @@ class ProjectController extends \PHPCI\Controller
}
$method = $this->request->getMethod();
$project = $this->_projectStore->getById($projectId);
$project = $this->projectStore->getById($projectId);
if ($method == 'POST') {
$values = $this->getParams();
@ -258,7 +268,7 @@ class ProjectController extends \PHPCI\Controller
}
$project->setValues($values);
$project = $this->_projectStore->save($project);
$project = $this->projectStore->save($project);
header('Location: '.PHPCI_URL.'project/view/' . $project->getId());
die;

View file

@ -19,10 +19,15 @@ use b8;
*/
class SessionController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\UserStore
*/
protected $userStore;
public function init()
{
$this->response->disableLayout();
$this->_userStore = b8\Store\Factory::getStore('User');
$this->userStore = b8\Store\Factory::getStore('User');
}
/**
@ -33,7 +38,7 @@ class SessionController extends \PHPCI\Controller
$isLoginFailure = false;
if ($this->request->getMethod() == 'POST') {
$user = $this->_userStore->getByEmail($this->getParam('email'));
$user = $this->userStore->getByEmail($this->getParam('email'));
if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
$_SESSION['user_id'] = $user->getId();

View file

@ -21,9 +21,14 @@ use b8\Form;
*/
class UserController extends \PHPCI\Controller
{
/**
* @var \PHPCI\Store\UserStore
*/
protected $userStore;
public function init()
{
$this->_userStore = b8\Store\Factory::getStore('User');
$this->userStore = b8\Store\Factory::getStore('User');
}
/**
@ -31,7 +36,7 @@ class UserController extends \PHPCI\Controller
*/
public function index()
{
$users = $this->_userStore->getWhere(array(), 1000, 0, array(), array('email' => 'ASC'));
$users = $this->userStore->getWhere(array(), 1000, 0, array(), array('email' => 'ASC'));
$this->view->users = $users;
return $this->view->render();
@ -72,7 +77,7 @@ class UserController extends \PHPCI\Controller
$user = new User();
$user->setValues($values);
$user = $this->_userStore->save($user);
$user = $this->userStore->save($user);
header('Location: '.PHPCI_URL.'user');
die;
@ -88,7 +93,7 @@ class UserController extends \PHPCI\Controller
}
$method = $this->request->getMethod();
$user = $this->_userStore->getById($userId);
$user = $this->userStore->getById($userId);
if ($method == 'POST') {
$values = $this->getParams();
@ -116,7 +121,7 @@ class UserController extends \PHPCI\Controller
}
$user->setValues($values);
$user = $this->_userStore->save($user);
$user = $this->userStore->save($user);
header('Location: '.PHPCI_URL.'user');
die;
@ -178,8 +183,8 @@ class UserController extends \PHPCI\Controller
throw new \Exception('You do not have permission to do that.');
}
$user = $this->_userStore->getById($userId);
$this->_userStore->delete($user);
$user = $this->userStore->getById($userId);
$this->userStore->delete($user);
header('Location: '.PHPCI_URL.'user');
die;