This commit is contained in:
Steve Kamerman 2013-05-16 11:59:48 -04:00
commit 63e1797249
11 changed files with 82 additions and 62 deletions

View file

@ -18,9 +18,14 @@ use b8\Registry;
*/ */
class Application extends b8\Application class Application extends b8\Application
{ {
/**
* Handle an incoming web request.
*/
public function handleRequest() public function handleRequest()
{ {
$controllerName = \b8\Registry::getInstance()->get('ControllerName'); $controllerName = \b8\Registry::getInstance()->get('ControllerName');
// Validate the user's session unless it is a login/logout action or a web hook:
$sessionAction = ($controllerName == 'Session' && in_array($this->action, array('login', 'logout'))); $sessionAction = ($controllerName == 'Session' && in_array($this->action, array('login', 'logout')));
$webhookAction = in_array($controllerName, array('Bitbucket', 'Github')); $webhookAction = in_array($controllerName, array('Bitbucket', 'Github'));
@ -28,12 +33,16 @@ class Application extends b8\Application
$this->validateSession(); $this->validateSession();
} }
// Render content into layout and return:
$view = new b8\View('Layout'); $view = new b8\View('Layout');
$view->content = parent::handleRequest(); $view->content = parent::handleRequest();
return $view->render(); return $view->render();
} }
/**
* Validate whether or not the remote user has a valid session:
*/
protected function validateSession() protected function validateSession()
{ {
if (!empty($_SESSION['user_id'])) { if (!empty($_SESSION['user_id'])) {

View file

@ -191,7 +191,7 @@ class Builder
if (is_array($message)) { if (is_array($message)) {
foreach ($message as $item) { foreach ($message as $item) {
if (is_callable($this->logCallback)) { if (is_callable($this->logCallback)) {
call_user_func_array($this->logCallback, $prefix . $item); call_user_func_array($this->logCallback, array($prefix . $item));
} }
$this->log .= $prefix . $item . PHP_EOL; $this->log .= $prefix . $item . PHP_EOL;
@ -201,7 +201,7 @@ class Builder
$this->log .= $message . PHP_EOL; $this->log .= $message . PHP_EOL;
if (isset($this->logCallback) && is_callable($this->logCallback)) { if (isset($this->logCallback) && is_callable($this->logCallback)) {
call_user_func_array($this->logCallback, $prefix . $item); call_user_func_array($this->logCallback, array($message));
} }
} }

View file

@ -30,7 +30,7 @@ class GenerateCommand extends Command
->setDescription('Generate models and stores from the database.'); ->setDescription('Generate models and stores from the database.');
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute()
{ {
$gen = new \b8\Database\CodeGenerator(\b8\Database::getConnection(), 'PHPCI', PHPCI_DIR . '/PHPCI/'); $gen = new \b8\Database\CodeGenerator(\b8\Database::getConnection(), 'PHPCI', PHPCI_DIR . '/PHPCI/');
$gen->generateModels(); $gen->generateModels();

View file

@ -32,7 +32,7 @@ class InstallCommand extends Command
->setDescription('Install PHPCI.'); ->setDescription('Install PHPCI.');
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute()
{ {
$dbHost = $this->ask('Enter your MySQL host: '); $dbHost = $this->ask('Enter your MySQL host: ');
$dbName = $this->ask('Enter the database name PHPCI should use: '); $dbName = $this->ask('Enter the database name PHPCI should use: ');
@ -101,9 +101,9 @@ b8\Database::setReadServers(array('{$dbHost}'));
print $question . ' '; print $question . ' ';
$rtn = ''; $rtn = '';
$fp = fopen('php://stdin', 'r'); $stdin = fopen('php://stdin', 'r');
$rtn = fgets($fp); $rtn = fgets($stdin);
fclose($fp); fclose($stdin);
$rtn = trim($rtn); $rtn = trim($rtn);

View file

@ -58,13 +58,13 @@ class ProjectController extends b8\Controller
header('Location: /build/view/' . $build->getId()); header('Location: /build/view/' . $build->getId());
} }
public function delete($id) public function delete($projectId)
{ {
if (!Registry::getInstance()->get('user')->getIsAdmin()) { if (!Registry::getInstance()->get('user')->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.'); throw new \Exception('You do not have permission to do that.');
} }
$project = $this->_projectStore->getById($id); $project = $this->_projectStore->getById($projectId);
$this->_projectStore->delete($project); $this->_projectStore->delete($project);
header('Location: /'); header('Location: /');
@ -109,16 +109,16 @@ class ProjectController extends b8\Controller
$tempPath = getenv("SystemRoot") . '/TEMP/'; $tempPath = getenv("SystemRoot") . '/TEMP/';
} }
$id = $tempPath . md5(microtime(true)); $keyFile = $tempPath . md5(microtime(true));
if (!is_dir($tempPath)) { if (!is_dir($tempPath)) {
mkdir($tempPath); mkdir($tempPath);
} }
shell_exec('ssh-keygen -q -t rsa -b 2048 -f '.$id.' -N "" -C "deploy@phpci"'); shell_exec('ssh-keygen -q -t rsa -b 2048 -f '.$keyFile.' -N "" -C "deploy@phpci"');
$pub = file_get_contents($id . '.pub'); $pub = file_get_contents($keyFile . '.pub');
$prv = file_get_contents($id); $prv = file_get_contents($keyFile);
$values = array('key' => $prv, 'pubkey' => $pub, 'token' => $_SESSION['github_token']); $values = array('key' => $prv, 'pubkey' => $pub, 'token' => $_SESSION['github_token']);
} }
@ -126,22 +126,7 @@ class ProjectController extends b8\Controller
$form = $this->projectForm($values); $form = $this->projectForm($values);
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
$gh = \b8\Registry::getInstance()->get('github_app'); $this->handleGithubResponse();
$code = $this->getParam('code', null);
if (!is_null($code)) {
$http = new \b8\HttpClient();
$url = 'https://github.com/login/oauth/access_token';
$params = array('client_id' => $gh['id'], 'client_secret' => $gh['secret'], 'code' => $code);
$resp = $http->post($url, $params);
if ($resp['success']) {
parse_str($resp['body'], $resp);
$_SESSION['github_token'] = $resp['access_token'];
header('Location: /project/add');
die;
}
}
$view = new b8\View('ProjectForm'); $view = new b8\View('ProjectForm');
$view->type = 'add'; $view->type = 'add';
@ -165,14 +150,34 @@ class ProjectController extends b8\Controller
die; die;
} }
public function edit($id) protected function handleGithubResponse()
{
$github = \b8\Registry::getInstance()->get('github_app');
$code = $this->getParam('code', null);
if (!is_null($code)) {
$http = new \b8\HttpClient();
$url = 'https://github.com/login/oauth/access_token';
$params = array('client_id' => $github['id'], 'client_secret' => $github['secret'], 'code' => $code);
$resp = $http->post($url, $params);
if ($resp['success']) {
parse_str($resp['body'], $resp);
$_SESSION['github_token'] = $resp['access_token'];
header('Location: /project/add');
die;
}
}
}
public function edit($projectId)
{ {
if (!Registry::getInstance()->get('user')->getIsAdmin()) { if (!Registry::getInstance()->get('user')->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.'); throw new \Exception('You do not have permission to do that.');
} }
$method = Registry::getInstance()->get('requestMethod'); $method = Registry::getInstance()->get('requestMethod');
$project = $this->_projectStore->getById($id); $project = $this->_projectStore->getById($projectId);
if ($method == 'POST') { if ($method == 'POST') {
$values = $this->getParams(); $values = $this->getParams();
@ -181,7 +186,7 @@ class ProjectController extends b8\Controller
$values['key'] = $values['git_key']; $values['key'] = $values['git_key'];
} }
$form = $this->projectForm($values, 'edit/' . $id); $form = $this->projectForm($values, 'edit/' . $projectId);
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
$view = new b8\View('ProjectForm'); $view = new b8\View('ProjectForm');

View file

@ -74,14 +74,14 @@ class UserController extends b8\Controller
die; die;
} }
public function edit($id) public function edit($userId)
{ {
if (!Registry::getInstance()->get('user')->getIsAdmin()) { if (!Registry::getInstance()->get('user')->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.'); throw new \Exception('You do not have permission to do that.');
} }
$method = Registry::getInstance()->get('requestMethod'); $method = Registry::getInstance()->get('requestMethod');
$user = $this->_userStore->getById($id); $user = $this->_userStore->getById($userId);
if ($method == 'POST') { if ($method == 'POST') {
$values = $this->getParams(); $values = $this->getParams();
@ -90,7 +90,7 @@ class UserController extends b8\Controller
$values['admin'] = $values['is_admin']; $values['admin'] = $values['is_admin'];
} }
$form = $this->userForm($values, 'edit/' . $id); $form = $this->userForm($values, 'edit/' . $userId);
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
$view = new b8\View('UserForm'); $view = new b8\View('UserForm');
@ -155,13 +155,13 @@ class UserController extends b8\Controller
return $form; return $form;
} }
public function delete($id) public function delete($userId)
{ {
if (!Registry::getInstance()->get('user')->getIsAdmin()) { if (!Registry::getInstance()->get('user')->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.'); throw new \Exception('You do not have permission to do that.');
} }
$user = $this->_userStore->getById($id); $user = $this->_userStore->getById($userId);
$this->_userStore->delete($user); $this->_userStore->delete($user);
header('Location: /user'); header('Location: /user');

View file

@ -31,10 +31,10 @@ class Mysql implements \PHPCI\Plugin
$this->phpci = $phpci; $this->phpci = $phpci;
$this->queries = $options; $this->queries = $options;
$db = \b8\Database::getConnection('write')->getDetails(); $config = \b8\Database::getConnection('write')->getDetails();
$this->host = PHPCI_DB_HOST; $this->host = PHPCI_DB_HOST;
$this->user = $db['user']; $this->user = $config['user'];
$this->pass = $db['pass']; $this->pass = $config['pass'];
$buildSettings = $phpci->getConfig('build_settings'); $buildSettings = $phpci->getConfig('build_settings');
if (isset($buildSettings['mysql'])) { if (isset($buildSettings['mysql'])) {

View file

@ -31,15 +31,9 @@ class PhpCodeSniffer implements \PHPCI\Plugin
public function execute() public function execute()
{ {
$ignore = ''; $ignore = '';
if (count($this->phpci->ignore)) { if (count($this->phpci->ignore)) {
$map = function ($item) { $ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
};
$ignore = array_map($map, $this->phpci->ignore);
$ignore = ' --ignore=' . implode(',', $ignore);
} }
$cmd = PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"'; $cmd = PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"';

View file

@ -29,12 +29,7 @@ class PhpMessDetector implements \PHPCI\Plugin
$ignore = ''; $ignore = '';
if (count($this->phpci->ignore)) { if (count($this->phpci->ignore)) {
$map = function ($item) { $ignore = ' --exclude ' . implode(',', $this->phpci->ignore);
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
};
$ignore = array_map($map, $this->phpci->ignore);
$ignore = ' --exclude ' . implode(',', $ignore);
} }
$cmd = PHPCI_BIN_DIR . 'phpmd "%s" text codesize,unusedcode,naming %s'; $cmd = PHPCI_BIN_DIR . 'phpmd "%s" text codesize,unusedcode,naming %s';

View file

@ -38,10 +38,22 @@ class PhpUnit implements \PHPCI\Plugin
public function __construct(\PHPCI\Builder $phpci, array $options = array()) public function __construct(\PHPCI\Builder $phpci, array $options = array())
{ {
$this->phpci = $phpci; $this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $options['directory'] : null;
$this->xmlConfigFile = isset($options['config']) ? $options['config'] : null; if(isset($options['directory'])) {
$this->runFrom = isset($options['run_from']) ? $options['run_from'] : null; $this->directory = $options['directory'];
$this->args = isset($options['args']) ? $options['args'] : ''; }
if(isset($options['config'])) {
$this->xmlConfigFile = $options['config'];
}
if(isset($options['run_from'])) {
$this->runFrom = $options['run_from'];
}
if(isset($options['args'])) {
$this->args = $options['args'];
}
} }
public function execute() public function execute()

View file

@ -2,11 +2,16 @@ build_settings:
verbose: false verbose: false
ignore: ignore:
- "vendor" - "vendor"
- "assets"
- "build"
- "Tests"
- "composer.phar"
setup: setup:
composer: composer:
action: "install" action: "install"
test: test:
php_mess_detector: php_mess_detector:
allow_failures: true php_code_sniffer:
standard: "PSR2"