From 65aba6b3c6bb38467427a21155551eeb1fae782d Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sat, 30 May 2015 21:33:48 +0200 Subject: [PATCH 01/33] Update pimple to version 3. --- PHPCI/Plugin/Util/Factory.php | 10 ++++++---- composer.json | 2 +- composer.lock | 24 +++++++++++------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/PHPCI/Plugin/Util/Factory.php b/PHPCI/Plugin/Util/Factory.php index 30c68340..62a64c78 100644 --- a/PHPCI/Plugin/Util/Factory.php +++ b/PHPCI/Plugin/Util/Factory.php @@ -2,6 +2,8 @@ namespace PHPCI\Plugin\Util; +use Pimple\Container; + /** * Plugin Factory - Loads Plugins and passes required dependencies. * @package PHPCI\Plugin\Util @@ -15,19 +17,19 @@ class Factory private $currentPluginOptions; /** - * @var \Pimple + * @var Container */ private $container; /** - * @param \Pimple $container + * @param Container $container */ - public function __construct(\Pimple $container = null) + public function __construct(Container $container = null) { if ($container) { $this->container = $container; } else { - $this->container = new \Pimple(); + $this->container = new Container(); } $self = $this; diff --git a/composer.json b/composer.json index 3de523e5..8e64798c 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "symfony/console": "~2.1", "psr/log": "~1.0", "monolog/monolog": "~1.6", - "pimple/pimple": "~1.1", + "pimple/pimple": "~3.0", "robmorgan/phinx": "~0.4", "sensiolabs/ansi-to-html": "~1.1", "jakub-onderka/php-parallel-lint": "0.8.*" diff --git a/composer.lock b/composer.lock index 21e42d42..497bd77a 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "0be92d5565a805ffe462c6061ed1dcf4", + "hash": "e12b5e931e334892180b1d963c3b3226", "packages": [ { "name": "block8/b8framework", @@ -216,16 +216,16 @@ }, { "name": "pimple/pimple", - "version": "v1.1.1", + "version": "v3.0.0", "source": { "type": "git", - "url": "https://github.com/fabpot/Pimple.git", - "reference": "2019c145fe393923f3441b23f29bbdfaa5c58c4d" + "url": "https://github.com/silexphp/Pimple.git", + "reference": "876bf0899d01feacd2a2e83f04641e51350099ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fabpot/Pimple/zipball/2019c145fe393923f3441b23f29bbdfaa5c58c4d", - "reference": "2019c145fe393923f3441b23f29bbdfaa5c58c4d", + "url": "https://api.github.com/repos/silexphp/Pimple/zipball/876bf0899d01feacd2a2e83f04641e51350099ef", + "reference": "876bf0899d01feacd2a2e83f04641e51350099ef", "shasum": "" }, "require": { @@ -234,12 +234,12 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { "psr-0": { - "Pimple": "lib/" + "Pimple": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -249,9 +249,7 @@ "authors": [ { "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" + "email": "fabien@symfony.com" } ], "description": "Pimple is a simple Dependency Injection Container for PHP 5.3", @@ -260,7 +258,7 @@ "container", "dependency injection" ], - "time": "2013-11-22 08:30:29" + "time": "2014-07-24 09:48:15" }, { "name": "psr/log", From ebf5a5dd7bd08a6f3309e8a0f4e7f33862174682 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sat, 30 May 2015 23:04:47 +0200 Subject: [PATCH 02/33] First draft of DIC initialization with config. --- PHPCI/Application.php | 13 ++++++++++ PHPCI/Controller.php | 1 - bootstrap.php | 52 +++++++++++++++++++++------------------- composer.json | 5 ++-- composer.lock | 56 ++++++++++++++++++++++++++++++++++++++++--- public/index.php | 7 +++--- services.yml | 16 +++++++++++++ vars.php | 6 ++--- 8 files changed, 119 insertions(+), 37 deletions(-) create mode 100644 services.yml diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 8dcdf76d..2d16444b 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -11,8 +11,10 @@ namespace PHPCI; use b8; use b8\Exception\HttpException; +use b8\Http\Request; use b8\Http\Response; use b8\Http\Response\RedirectResponse; +use b8\Http\Router; use b8\View; /** @@ -26,6 +28,17 @@ class Application extends b8\Application */ protected $controller; + public function __construct(Config $config, Request $request, Response $response) + { + $this->config = $config; + $this->response = $response; + $this->request = $request; + + $this->router = new Router($this, $this->request, $this->config); + + $this->init(); + } + /** * Initialise PHPCI - Handles session verification, routing, etc. */ diff --git a/PHPCI/Controller.php b/PHPCI/Controller.php index 68b1c845..803c9dbf 100644 --- a/PHPCI/Controller.php +++ b/PHPCI/Controller.php @@ -9,7 +9,6 @@ namespace PHPCI; -use b8\Config; use b8\Exception\HttpException\ForbiddenException; use b8\Http\Request; use b8\Http\Response; diff --git a/bootstrap.php b/bootstrap.php index 18d91d07..1b63ce3e 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -7,15 +7,31 @@ * @link http://www.phptesting.org/ */ -// Let PHP take a guess as to the default timezone, if the user hasn't set one: -use PHPCI\Logging\LoggerConfig; +// If composer has not been run, fail at this point and tell the user to install: +if (!file_exists(__DIR__ . '/vendor/autoload.php') && defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) { + $message = 'Please install PHPCI with "composer install" (or "php composer.phar install"'; + $message .= ' for Windows) before using console'; + file_put_contents('php://stderr', $message); + exit(1); +} + +// Load Composer autoloader: +require_once(__DIR__ . '/vendor/autoload.php'); + +// Let PHP take a guess as to the default timezone, if the user hasn't set one: $timezone = ini_get('date.timezone'); if (empty($timezone)) { date_default_timezone_set('UTC'); } -$configFile = dirname(__FILE__) . '/PHPCI/config.yml'; +use PHPCI\Logging\LoggerConfig; +use Pimple\Container; +use G\Yaml2Pimple\ContainerBuilder; +use G\Yaml2Pimple\YamlFileLoader; +use Symfony\Component\Config\FileLocator; + +$configFile = __DIR__ . '/PHPCI/config.yml'; $configEnv = getenv('phpci_config_file'); if (!empty($configEnv) && file_exists($configEnv)) { @@ -30,34 +46,20 @@ if (!file_exists($configFile) && (!defined('PHPCI_IS_CONSOLE') || !PHPCI_IS_CONS die($message); } -// If composer has not been run, fail at this point and tell the user to install: -if (!file_exists(dirname(__FILE__) . '/vendor/autoload.php') && defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) { - $message = 'Please install PHPCI with "composer install" (or "php composer.phar install"'; - $message .= ' for Windows) before using console'; - - file_put_contents('php://stderr', $message); - exit(1); -} - -// Load Composer autoloader: -require_once(dirname(__FILE__) . '/vendor/autoload.php'); - \PHPCI\ErrorHandler::register(); if (defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) { $loggerConfig = LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php"); } -// Load configuration if present: -$conf = array(); -$conf['b8']['app']['namespace'] = 'PHPCI'; -$conf['b8']['app']['default_controller'] = 'Home'; -$conf['b8']['view']['path'] = dirname(__FILE__) . '/PHPCI/View/'; +$container = new Container(); -$config = new b8\Config($conf); +$builder = new ContainerBuilder($container); +$loader = new YamlFileLoader($builder, new FileLocator(__DIR__)); +$loader->load('services.yml'); if (file_exists($configFile)) { - $config->loadYaml($configFile); + $container['config_file'] = $configFile; } /** @@ -66,11 +68,11 @@ if (file_exists($configFile)) { * * @ticket 781 */ -$localVarsFile = dirname(__FILE__) . '/local_vars.php'; +$localVarsFile = __DIR__ . '/local_vars.php'; if (is_readable($localVarsFile)) { require_once $localVarsFile; } -require_once(dirname(__FILE__) . '/vars.php'); +require_once(__DIR__ . '/vars.php'); -\PHPCI\Helper\Lang::init($config); +\PHPCI\Helper\Lang::init($container['config']); diff --git a/composer.json b/composer.json index 8e64798c..ca900c55 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name" : "block8/phpci", "description" : "Simple continuous integration for PHP projects.", - "minimum-stability": "stable", + "minimum-stability": "dev", "type" : "library", "keywords" : ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"], "homepage" : "http://www.phptesting.org/", @@ -48,7 +48,8 @@ "pimple/pimple": "~3.0", "robmorgan/phinx": "~0.4", "sensiolabs/ansi-to-html": "~1.1", - "jakub-onderka/php-parallel-lint": "0.8.*" + "jakub-onderka/php-parallel-lint": "0.8.*", + "gonzalo123/yaml2pimple": "^1.0@dev" }, "autoload-dev": { diff --git a/composer.lock b/composer.lock index 497bd77a..31679fad 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e12b5e931e334892180b1d963c3b3226", + "hash": "bd1ad78288fdaea0e4a92b25d644b204", "packages": [ { "name": "block8/b8framework", @@ -53,6 +53,54 @@ ], "time": "2014-12-01 21:02:58" }, + { + "name": "gonzalo123/yaml2pimple", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/gonzalo123/yml2pimple.git", + "reference": "63145b8c1506cc4a01e4b79b2c5b7222f5ab9d94" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gonzalo123/yml2pimple/zipball/63145b8c1506cc4a01e4b79b2c5b7222f5ab9d94", + "reference": "63145b8c1506cc4a01e4b79b2c5b7222f5ab9d94", + "shasum": "" + }, + "require": { + "pimple/pimple": "3.0.*@dev", + "symfony/config": "2.6.*@dev", + "symfony/yaml": "2.6.*@dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "G\\Yaml2Pimple\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gonzalo Ayuso", + "email": "gonzalo123@gmail.com" + } + ], + "description": "Build a Pimple/Container from a config file", + "keywords": [ + "container", + "dependency injection", + "pimple" + ], + "time": "2014-10-04 14:56:45" + }, { "name": "ircmaxell/password-compat", "version": "v1.0.4", @@ -2072,8 +2120,10 @@ } ], "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], + "minimum-stability": "dev", + "stability-flags": { + "gonzalo123/yaml2pimple": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/public/index.php b/public/index.php index 56ebed12..d83c1785 100644 --- a/public/index.php +++ b/public/index.php @@ -10,7 +10,8 @@ session_set_cookie_params(43200); // Set session cookie to last 12 hours. session_start(); -require_once('../bootstrap.php'); +require_once(__DIR__ . '/../bootstrap.php'); -$fc = new PHPCI\Application($config, new b8\Http\Request()); -print $fc->handleRequest(); +$app = $container['application']; + +print $app->handleRequest(); diff --git a/services.yml b/services.yml new file mode 100644 index 00000000..945e77cf --- /dev/null +++ b/services.yml @@ -0,0 +1,16 @@ +parameters: + config_file: ./PHPCI/config.yml + +services: + http.request: + class: b8\Http\Request + arguments: [] + http.response: + class: b8\Http\Response + arguments: [] + config: + class: PHPCI\Config + arguments: [%config_file%] + application: + class: PHPCI\Application + arguments: [@config, @http.request, @http.response] diff --git a/vars.php b/vars.php index 98c07377..db6c3593 100644 --- a/vars.php +++ b/vars.php @@ -7,8 +7,8 @@ if (!defined('APPLICATION_PATH')) { } // Define our PHPCI_URL, if not already defined: -if (!defined('PHPCI_URL') && isset($config)) { - define('PHPCI_URL', $config->get('phpci.url', '') . '/'); +if (!defined('PHPCI_URL')) { + define('PHPCI_URL', $container['config']->get('phpci.url')); } // Define PHPCI_BIN_DIR @@ -38,5 +38,5 @@ if (!defined('IS_WIN')) { // If an environment variable is set defining our config location, use that // otherwise fall back to PHPCI/config.yml. if (!defined('PHPCI_CONFIG_FILE')) { - define('PHPCI_CONFIG_FILE', $configFile); + define('PHPCI_CONFIG_FILE', $container['config_file']); } From a9545e4104f26d5d960ead95667e5675b68a9428 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sat, 30 May 2015 23:20:13 +0200 Subject: [PATCH 03/33] Added store.entity services and fixed application to use it. --- PHPCI/Application.php | 31 +++++++++++++++++++++---------- bootstrap.php | 16 ++++++++++++++++ services.yml | 2 +- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 2d16444b..46e213ff 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -16,6 +16,8 @@ use b8\Http\Response; use b8\Http\Response\RedirectResponse; use b8\Http\Router; use b8\View; +use PHPCI\Store\UserStore; +use PHPCI\Store\ProjectStore; /** * PHPCI Front Controller @@ -28,11 +30,23 @@ class Application extends b8\Application */ protected $controller; - public function __construct(Config $config, Request $request, Response $response) + /** + * @var \PHPCI\Store\UserStore + */ + protected $userStore; + + /** + * @var \PHPCI\Store\ProjectStore + */ + protected $projectStore; + + public function __construct(Config $config, Request $request, Response $response, UserStore $userStore, ProjectStore $projectStore) { $this->config = $config; $this->response = $response; $this->request = $request; + $this->userStore = $userStore; + $this->projectStore = $projectStore; $this->router = new Router($this, $this->request, $this->config); @@ -51,7 +65,7 @@ class Application extends b8\Application // Inlined as a closure to fix "using $this when not in object context" on 5.3 $validateSession = function () { if (!empty($_SESSION['phpci_user_id'])) { - $user = b8\Store\Factory::getStore('User')->getByPrimaryKey($_SESSION['phpci_user_id']); + $user = $this->userStore->getByPrimaryKey($_SESSION['phpci_user_id']); if ($user) { $_SESSION['phpci_user'] = $user; @@ -148,9 +162,7 @@ class Application extends b8\Application */ protected function setLayoutVariables(View &$layout) { - /** @var \PHPCI\Store\ProjectStore $projectStore */ - $projectStore = b8\Store\Factory::getStore('Project'); - $layout->projects = $projectStore->getWhere( + $layout->projects = $this->projectStore->getWhere( array('archived' => (int)isset($_GET['archived'])), 50, 0, @@ -161,17 +173,16 @@ class Application extends b8\Application /** * Check whether we should skip auth (because it is disabled) + * * @return bool */ protected function shouldSkipAuth() { - $config = b8\Config::getInstance(); - $state = (bool)$config->get('phpci.authentication_settings.state', false); - $userId = $config->get('phpci.authentication_settings.user_id', 0); + $state = (bool) $this->config->get('phpci.authentication_settings.state', false); + $userId = $this->config->get('phpci.authentication_settings.user_id', 0); if (false !== $state && 0 != (int)$userId) { - $user = b8\Store\Factory::getStore('User') - ->getByPrimaryKey($userId); + $user = $this->userStore->getByPrimaryKey($userId); if ($user) { $_SESSION['phpci_user'] = $user; diff --git a/bootstrap.php b/bootstrap.php index 1b63ce3e..50d9bc73 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -62,6 +62,22 @@ if (file_exists($configFile)) { $container['config_file'] = $configFile; } +$container['store.user'] = $container->factory(function () { + return b8\Store\Factory::getStore('User'); +}); + +$container['store.project'] = $container->factory(function () { + return b8\Store\Factory::getStore('Project'); +}); + +$container['store.build'] = $container->factory(function () { + return b8\Store\Factory::getStore('Build'); +}); + +$container['store.build_meta'] = $container->factory(function () { + return b8\Store\Factory::getStore('BuildMeta'); +}); + /** * Allow to modify PHPCI configuration without modify versioned code. * Dameons should be killed to apply changes in the file. diff --git a/services.yml b/services.yml index 945e77cf..6249960e 100644 --- a/services.yml +++ b/services.yml @@ -13,4 +13,4 @@ services: arguments: [%config_file%] application: class: PHPCI\Application - arguments: [@config, @http.request, @http.response] + arguments: [@config, @http.request, @http.response, @store.user, @store.project] From a0e72b9bc7c4f74b424f14f8376a4a2edd733241 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sat, 30 May 2015 23:24:14 +0200 Subject: [PATCH 04/33] Remove new instance of each store. --- bootstrap.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 50d9bc73..a8820301 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -62,21 +62,21 @@ if (file_exists($configFile)) { $container['config_file'] = $configFile; } -$container['store.user'] = $container->factory(function () { +$container['store.user'] = function () { return b8\Store\Factory::getStore('User'); -}); +}; -$container['store.project'] = $container->factory(function () { +$container['store.project'] = function () { return b8\Store\Factory::getStore('Project'); -}); +}; -$container['store.build'] = $container->factory(function () { +$container['store.build'] = function () { return b8\Store\Factory::getStore('Build'); -}); +}; -$container['store.build_meta'] = $container->factory(function () { +$container['store.build_meta'] = function () { return b8\Store\Factory::getStore('BuildMeta'); -}); +}; /** * Allow to modify PHPCI configuration without modify versioned code. From 3eb1648e13f21c45986c8cd258041b30bd7153e3 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 10:33:27 +0200 Subject: [PATCH 05/33] Swtich DIC to symfony container. --- bootstrap.php | 31 ++------- composer.json | 4 +- composer.lock | 176 +++++++++++++++++------------------------------ public/index.php | 2 +- services.yml | 47 +++++++++---- vars.php | 4 +- 6 files changed, 108 insertions(+), 156 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index a8820301..c6e809aa 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -26,10 +26,9 @@ if (empty($timezone)) { } use PHPCI\Logging\LoggerConfig; -use Pimple\Container; -use G\Yaml2Pimple\ContainerBuilder; -use G\Yaml2Pimple\YamlFileLoader; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; $configFile = __DIR__ . '/PHPCI/config.yml'; $configEnv = getenv('phpci_config_file'); @@ -52,32 +51,14 @@ if (defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) { $loggerConfig = LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php"); } -$container = new Container(); - -$builder = new ContainerBuilder($container); -$loader = new YamlFileLoader($builder, new FileLocator(__DIR__)); +$container = new ContainerBuilder(); +$loader = new YamlFileLoader($container, new FileLocator(__DIR__)); $loader->load('services.yml'); if (file_exists($configFile)) { - $container['config_file'] = $configFile; + $container->set('config_file', $configFile); } -$container['store.user'] = function () { - return b8\Store\Factory::getStore('User'); -}; - -$container['store.project'] = function () { - return b8\Store\Factory::getStore('Project'); -}; - -$container['store.build'] = function () { - return b8\Store\Factory::getStore('Build'); -}; - -$container['store.build_meta'] = function () { - return b8\Store\Factory::getStore('BuildMeta'); -}; - /** * Allow to modify PHPCI configuration without modify versioned code. * Dameons should be killed to apply changes in the file. @@ -91,4 +72,4 @@ if (is_readable($localVarsFile)) { require_once(__DIR__ . '/vars.php'); -\PHPCI\Helper\Lang::init($container['config']); +\PHPCI\Helper\Lang::init($container->get('config')); diff --git a/composer.json b/composer.json index ca900c55..de51da75 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name" : "block8/phpci", "description" : "Simple continuous integration for PHP projects.", - "minimum-stability": "dev", + "minimum-stability": "stable", "type" : "library", "keywords" : ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"], "homepage" : "http://www.phptesting.org/", @@ -49,7 +49,7 @@ "robmorgan/phinx": "~0.4", "sensiolabs/ansi-to-html": "~1.1", "jakub-onderka/php-parallel-lint": "0.8.*", - "gonzalo123/yaml2pimple": "^1.0@dev" + "symfony/dependency-injection": "~2.7" }, "autoload-dev": { diff --git a/composer.lock b/composer.lock index 31679fad..a32dc7ae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "bd1ad78288fdaea0e4a92b25d644b204", + "hash": "4c1675c48cc8ac6ab60ff9a6663bcdb8", "packages": [ { "name": "block8/b8framework", @@ -53,54 +53,6 @@ ], "time": "2014-12-01 21:02:58" }, - { - "name": "gonzalo123/yaml2pimple", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/gonzalo123/yml2pimple.git", - "reference": "63145b8c1506cc4a01e4b79b2c5b7222f5ab9d94" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/gonzalo123/yml2pimple/zipball/63145b8c1506cc4a01e4b79b2c5b7222f5ab9d94", - "reference": "63145b8c1506cc4a01e4b79b2c5b7222f5ab9d94", - "shasum": "" - }, - "require": { - "pimple/pimple": "3.0.*@dev", - "symfony/config": "2.6.*@dev", - "symfony/yaml": "2.6.*@dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "G\\Yaml2Pimple\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gonzalo Ayuso", - "email": "gonzalo123@gmail.com" - } - ], - "description": "Build a Pimple/Container from a config file", - "keywords": [ - "container", - "dependency injection", - "pimple" - ], - "time": "2014-10-04 14:56:45" - }, { "name": "ircmaxell/password-compat", "version": "v1.0.4", @@ -609,6 +561,66 @@ "homepage": "http://symfony.com", "time": "2015-01-25 04:39:26" }, + { + "name": "symfony/dependency-injection", + "version": "v2.7.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/DependencyInjection.git", + "reference": "137bf489c5151c7eb1e4b7dd34a123f9a74b966d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/137bf489c5151c7eb1e4b7dd34a123f9a74b966d", + "reference": "137bf489c5151c7eb1e4b7dd34a123f9a74b966d", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "conflict": { + "symfony/expression-language": "<2.6" + }, + "require-dev": { + "symfony/config": "~2.2", + "symfony/expression-language": "~2.6", + "symfony/phpunit-bridge": "~2.7", + "symfony/yaml": "~2.1" + }, + "suggest": { + "symfony/config": "", + "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DependencyInjection\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DependencyInjection Component", + "homepage": "https://symfony.com", + "time": "2015-05-29 14:44:44" + }, { "name": "symfony/filesystem", "version": "v2.6.4", @@ -1971,66 +1983,6 @@ ], "time": "2015-03-04 02:07:03" }, - { - "name": "symfony/dependency-injection", - "version": "v2.6.4", - "target-dir": "Symfony/Component/DependencyInjection", - "source": { - "type": "git", - "url": "https://github.com/symfony/DependencyInjection.git", - "reference": "42bbb43fab66292a1865dc9616c299904c3d4d14" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/42bbb43fab66292a1865dc9616c299904c3d4d14", - "reference": "42bbb43fab66292a1865dc9616c299904c3d4d14", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "conflict": { - "symfony/expression-language": "<2.6" - }, - "require-dev": { - "symfony/config": "~2.2", - "symfony/expression-language": "~2.6", - "symfony/yaml": "~2.1" - }, - "suggest": { - "symfony/config": "", - "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", - "symfony/yaml": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\DependencyInjection\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony DependencyInjection Component", - "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" - }, { "name": "symfony/finder", "version": "v2.6.4", @@ -2120,10 +2072,8 @@ } ], "aliases": [], - "minimum-stability": "dev", - "stability-flags": { - "gonzalo123/yaml2pimple": 20 - }, + "minimum-stability": "stable", + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/public/index.php b/public/index.php index d83c1785..d83582f3 100644 --- a/public/index.php +++ b/public/index.php @@ -12,6 +12,6 @@ session_start(); require_once(__DIR__ . '/../bootstrap.php'); -$app = $container['application']; +$app = $container->get('application'); print $app->handleRequest(); diff --git a/services.yml b/services.yml index 6249960e..25a2eea8 100644 --- a/services.yml +++ b/services.yml @@ -1,16 +1,37 @@ parameters: - config_file: ./PHPCI/config.yml + config_file: ./../PHPCI/config.yml + storage.factory: b8\Store\Factory services: - http.request: - class: b8\Http\Request - arguments: [] - http.response: - class: b8\Http\Response - arguments: [] - config: - class: PHPCI\Config - arguments: [%config_file%] - application: - class: PHPCI\Application - arguments: [@config, @http.request, @http.response, @store.user, @store.project] + storage.user: + class: PHPCI\Store\Base\UserStore + factory: [%storage.factory%, getStore] + arguments: + - User + storage.project: + class: PHPCI\Store\Base\ProjectStore + factory: [%storage.factory%, getStore] + arguments: + - Project + storage.build: + class: PHPCI\Store\Base\BuildStore + factory: [%storage.factory%, getStore] + arguments: + - Build + storage.build_meta: + class: PHPCI\Store\Base\BuildMetaStore + factory: [%storage.factory%, getStore] + arguments: + - BuildMeta + http.request: + class: b8\Http\Request + arguments: [] + http.response: + class: b8\Http\Response + arguments: [] + config: + class: PHPCI\Config + arguments: [%config_file%] + application: + class: PHPCI\Application + arguments: [@config, @http.request, @http.response, @storage.user, @storage.project] diff --git a/vars.php b/vars.php index db6c3593..74c0a070 100644 --- a/vars.php +++ b/vars.php @@ -8,7 +8,7 @@ if (!defined('APPLICATION_PATH')) { // Define our PHPCI_URL, if not already defined: if (!defined('PHPCI_URL')) { - define('PHPCI_URL', $container['config']->get('phpci.url')); + define('PHPCI_URL', $container->get('config')->get('phpci.url')); } // Define PHPCI_BIN_DIR @@ -38,5 +38,5 @@ if (!defined('IS_WIN')) { // If an environment variable is set defining our config location, use that // otherwise fall back to PHPCI/config.yml. if (!defined('PHPCI_CONFIG_FILE')) { - define('PHPCI_CONFIG_FILE', $container['config_file']); + define('PHPCI_CONFIG_FILE', $container->get('config_file')); } From 063bec407d5e9da09a59f5f9e7653e28a6a424f3 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:01:40 +0200 Subject: [PATCH 06/33] Move CLI app to use DIC. --- console | 24 ++------------------ services.yml | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++-- vars.php | 2 +- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/console b/console index 36645768..dc3b3a41 100755 --- a/console +++ b/console @@ -12,29 +12,9 @@ define('PHPCI_IS_CONSOLE', true); require('bootstrap.php'); -use PHPCI\Command\RunCommand; -use PHPCI\Command\RebuildCommand; -use PHPCI\Command\GenerateCommand; -use PHPCI\Command\UpdateCommand; -use PHPCI\Command\InstallCommand; -use PHPCI\Command\DaemonCommand; -use PHPCI\Command\PollCommand; -use PHPCI\Command\CreateAdminCommand; -use PHPCI\Command\CreateBuildCommand; -use PHPCI\Service\BuildService; use Symfony\Component\Console\Application; -use b8\Store\Factory; -$application = new Application(); - -$application->add(new RunCommand($loggerConfig->getFor('RunCommand'))); -$application->add(new RebuildCommand($loggerConfig->getFor('RunCommand'))); -$application->add(new InstallCommand); -$application->add(new UpdateCommand($loggerConfig->getFor('UpdateCommand'))); -$application->add(new GenerateCommand); -$application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand'))); -$application->add(new PollCommand($loggerConfig->getFor('PollCommand'))); -$application->add(new CreateAdminCommand(Factory::getStore('User'))); -$application->add(new CreateBuildCommand(Factory::getStore('Project'), new BuildService(Factory::getStore('Build')))); +/** @var Application */ +$application = $container->get('console.application'); $application->run(); diff --git a/services.yml b/services.yml index 25a2eea8..977a1792 100644 --- a/services.yml +++ b/services.yml @@ -1,6 +1,8 @@ parameters: - config_file: ./../PHPCI/config.yml - storage.factory: b8\Store\Factory + application.name: PHPCI + application.version: 1.7-dev + config_file: PHPCI/config.yml + storage.factory: b8\Store\Factory services: storage.user: @@ -35,3 +37,59 @@ services: application: class: PHPCI\Application arguments: [@config, @http.request, @http.response, @storage.user, @storage.project] + build: + class: PHPCI\Service\BuildService + arguments: [@storage.build] + + console.application: + class: Symfony\Component\Console\Application + arguments: + - %application.name% + - %application.version% + calls: + - [add, ['@console.command.run']] + - [add, ['@console.command.rebuild']] + - [add, ['@console.command.install']] + - [add, ['@console.command.update']] + - [add, ['@console.command.generate']] + - [add, ['@console.command.daemon']] + - [add, ['@console.command.poll']] + - [add, ['@console.command.create_admin']] + - [add, ['@console.command.create_build']] + console.logger: + class: Monolog\Logger + arguments: + - cli + console.command.run: + class: PHPCI\Command\RunCommand + arguments: + - @console.logger + console.command.rebuild: + class: PHPCI\Command\RebuildCommand + arguments: + - @console.logger + console.command.update: + class: PHPCI\Command\UpdateCommand + arguments: + - @console.logger + console.command.daemon: + class: PHPCI\Command\DaemonCommand + arguments: + - @console.logger + console.command.poll: + class: PHPCI\Command\PollCommand + arguments: + - @console.logger + console.command.create_admin: + class: PHPCI\Command\CreateAdminCommand + arguments: + - @storage.user + console.command.create_build: + class: PHPCI\Command\CreateBuildCommand + arguments: + - @storage.project + - @build + console.command.install: + class: PHPCI\Command\InstallCommand + console.command.generate: + class: PHPCI\Command\GenerateCommand diff --git a/vars.php b/vars.php index 74c0a070..5306b9b8 100644 --- a/vars.php +++ b/vars.php @@ -2,7 +2,7 @@ // Define our APPLICATION_PATH, if not already defined: if (!defined('APPLICATION_PATH')) { - define('APPLICATION_PATH', dirname(__FILE__) . '/'); + define('APPLICATION_PATH', __DIR__ . '/'); define('PHPCI_DIR', APPLICATION_PATH); } From 74ed1b14e10daa3baa8427bd58ec39a2e5a6942a Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:05:49 +0200 Subject: [PATCH 07/33] Use user service to manage user on admin command. --- PHPCI/Command/CreateAdminCommand.php | 14 ++++++-------- services.yml | 9 ++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/PHPCI/Command/CreateAdminCommand.php b/PHPCI/Command/CreateAdminCommand.php index 265f03b4..dd92e529 100644 --- a/PHPCI/Command/CreateAdminCommand.php +++ b/PHPCI/Command/CreateAdminCommand.php @@ -25,18 +25,18 @@ use Symfony\Component\Console\Output\OutputInterface; class CreateAdminCommand extends Command { /** - * @var UserStore + * @var UserService */ - protected $userStore; + protected $userService; /** - * @param UserStore $userStore + * @param UserService $userService */ - public function __construct(UserStore $userStore) + public function __construct(UserService $userService) { parent::__construct(); - $this->userStore = $userStore; + $this->userService = $userService; } protected function configure() @@ -53,8 +53,6 @@ class CreateAdminCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $userService = new UserService($this->userStore); - /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ $dialog = $this->getHelperSet()->get('dialog'); @@ -72,7 +70,7 @@ class CreateAdminCommand extends Command $adminPass = $dialog->askHiddenResponse($output, Lang::get('enter_password')); try { - $userService->createUser($adminName, $adminEmail, $adminPass, true); + $this->userService->createUser($adminName, $adminEmail, $adminPass, true); $output->writeln(Lang::get('user_created')); } catch (\Exception $e) { $output->writeln(sprintf('%s', Lang::get('failed_to_create'))); diff --git a/services.yml b/services.yml index 977a1792..8fe0bda6 100644 --- a/services.yml +++ b/services.yml @@ -37,9 +37,12 @@ services: application: class: PHPCI\Application arguments: [@config, @http.request, @http.response, @storage.user, @storage.project] - build: + service.build: class: PHPCI\Service\BuildService arguments: [@storage.build] + service.user: + class: PHPCI\Service\UserService + arguments: [@storage.user] console.application: class: Symfony\Component\Console\Application @@ -83,12 +86,12 @@ services: console.command.create_admin: class: PHPCI\Command\CreateAdminCommand arguments: - - @storage.user + - @service.user console.command.create_build: class: PHPCI\Command\CreateBuildCommand arguments: - @storage.project - - @build + - @service.build console.command.install: class: PHPCI\Command\InstallCommand console.command.generate: From e4e08e32b029b462f805b6877b303dd9e9bbd04a Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:06:19 +0200 Subject: [PATCH 08/33] Use user service to manage user on admin command. --- PHPCI/Command/CreateAdminCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/PHPCI/Command/CreateAdminCommand.php b/PHPCI/Command/CreateAdminCommand.php index dd92e529..a6488834 100644 --- a/PHPCI/Command/CreateAdminCommand.php +++ b/PHPCI/Command/CreateAdminCommand.php @@ -11,7 +11,6 @@ namespace PHPCI\Command; use PHPCI\Service\UserService; use PHPCI\Helper\Lang; -use PHPCI\Store\UserStore; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; From 5a516732eddc47bd8c4ee178693f4c6dc675e781 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:13:16 +0200 Subject: [PATCH 09/33] Move process controlll initialization in config. --- PHPCI/Command/DaemonCommand.php | 7 ++++--- services.yml | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PHPCI/Command/DaemonCommand.php b/PHPCI/Command/DaemonCommand.php index cb303eff..8bf26de2 100644 --- a/PHPCI/Command/DaemonCommand.php +++ b/PHPCI/Command/DaemonCommand.php @@ -48,11 +48,12 @@ class DaemonCommand extends Command */ protected $processControl; - public function __construct(Logger $logger, ProcessControlInterface $processControl = null, $name = null) + public function __construct(Logger $logger, ProcessControlInterface $processControl) { - parent::__construct($name); + parent::__construct(); + $this->logger = $logger; - $this->processControl = $processControl ?: Factory::getInstance(); + $this->processControl = $processControl; } protected function configure() diff --git a/services.yml b/services.yml index 8fe0bda6..01ad0eb6 100644 --- a/services.yml +++ b/services.yml @@ -43,7 +43,8 @@ services: service.user: class: PHPCI\Service\UserService arguments: [@storage.user] - + process_control: + factory: [PHPCI\ProcessControl\Factory, getInstance] console.application: class: Symfony\Component\Console\Application arguments: @@ -79,6 +80,7 @@ services: class: PHPCI\Command\DaemonCommand arguments: - @console.logger + - @process_control console.command.poll: class: PHPCI\Command\PollCommand arguments: From bfe21bc687a5cfe9c95d3c647f892d4787d2b5c3 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:18:04 +0200 Subject: [PATCH 10/33] Remove unrequired parameters from CLI command constructors. --- PHPCI/Command/DaemoniseCommand.php | 4 ++-- PHPCI/Command/PollCommand.php | 5 +++-- PHPCI/Command/RebuildCommand.php | 3 ++- PHPCI/Command/RunCommand.php | 4 ++-- PHPCI/Command/UpdateCommand.php | 5 +++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/PHPCI/Command/DaemoniseCommand.php b/PHPCI/Command/DaemoniseCommand.php index eadd334e..c9e97295 100644 --- a/PHPCI/Command/DaemoniseCommand.php +++ b/PHPCI/Command/DaemoniseCommand.php @@ -47,9 +47,9 @@ class DaemoniseCommand extends Command * @param \Monolog\Logger $logger * @param string $name */ - public function __construct(Logger $logger, $name = null) + public function __construct(Logger $logger) { - parent::__construct($name); + parent::__construct(); $this->logger = $logger; } diff --git a/PHPCI/Command/PollCommand.php b/PHPCI/Command/PollCommand.php index a8729515..d0381b10 100644 --- a/PHPCI/Command/PollCommand.php +++ b/PHPCI/Command/PollCommand.php @@ -32,9 +32,10 @@ class PollCommand extends Command */ protected $logger; - public function __construct(Logger $logger, $name = null) + public function __construct(Logger $logger) { - parent::__construct($name); + parent::__construct(); + $this->logger = $logger; } diff --git a/PHPCI/Command/RebuildCommand.php b/PHPCI/Command/RebuildCommand.php index 4c24b359..d4dee396 100644 --- a/PHPCI/Command/RebuildCommand.php +++ b/PHPCI/Command/RebuildCommand.php @@ -49,9 +49,10 @@ class RebuildCommand extends Command * @param \Monolog\Logger $logger * @param string $name */ - public function __construct(Logger $logger, $name = null) + public function __construct(Logger $logger) { parent::__construct($name); + $this->logger = $logger; } diff --git a/PHPCI/Command/RunCommand.php b/PHPCI/Command/RunCommand.php index c2c352e6..e4d0a3f2 100644 --- a/PHPCI/Command/RunCommand.php +++ b/PHPCI/Command/RunCommand.php @@ -55,9 +55,9 @@ class RunCommand extends Command * @param \Monolog\Logger $logger * @param string $name */ - public function __construct(Logger $logger, $name = null) + public function __construct(Logger $logger) { - parent::__construct($name); + parent::__construct(); $this->logger = $logger; } diff --git a/PHPCI/Command/UpdateCommand.php b/PHPCI/Command/UpdateCommand.php index 13e31f79..f8e66150 100644 --- a/PHPCI/Command/UpdateCommand.php +++ b/PHPCI/Command/UpdateCommand.php @@ -29,9 +29,10 @@ class UpdateCommand extends Command */ protected $logger; - public function __construct(Logger $logger, $name = null) + public function __construct(Logger $logger) { - parent::__construct($name); + parent::__construct(); + $this->logger = $logger; } From 455f9a59a846fbfa6ed614a33fc9e1f087d0e5f2 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:20:18 +0200 Subject: [PATCH 11/33] Remove unrequired parameters from CLI command constructors. --- PHPCI/Command/RebuildCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PHPCI/Command/RebuildCommand.php b/PHPCI/Command/RebuildCommand.php index d4dee396..14a90dfd 100644 --- a/PHPCI/Command/RebuildCommand.php +++ b/PHPCI/Command/RebuildCommand.php @@ -47,11 +47,10 @@ class RebuildCommand extends Command /** * @param \Monolog\Logger $logger - * @param string $name */ public function __construct(Logger $logger) { - parent::__construct($name); + parent::__construct(); $this->logger = $logger; } From 86de54b65882af4a6050c4bf414906a7d92ab147 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:20:31 +0200 Subject: [PATCH 12/33] Use config as service. --- PHPCI/Command/UpdateCommand.php | 13 +++++++++---- services.yml | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/PHPCI/Command/UpdateCommand.php b/PHPCI/Command/UpdateCommand.php index f8e66150..492ffeff 100644 --- a/PHPCI/Command/UpdateCommand.php +++ b/PHPCI/Command/UpdateCommand.php @@ -9,7 +9,7 @@ namespace PHPCI\Command; -use b8\Config; +use PHPCI\Config; use Monolog\Logger; use PHPCI\Helper\Lang; use Symfony\Component\Console\Command\Command; @@ -29,11 +29,17 @@ class UpdateCommand extends Command */ protected $logger; - public function __construct(Logger $logger) + /** + * @var Config + */ + protected $config; + + public function __construct(Logger $logger, Config $config) { parent::__construct(); $this->logger = $logger; + $this->config = $config; } protected function configure() @@ -61,8 +67,7 @@ class UpdateCommand extends Command protected function verifyInstalled(OutputInterface $output) { - $config = Config::getInstance(); - $phpciUrl = $config->get('phpci.url'); + $phpciUrl = $this->config->get('phpci.url'); return !empty($phpciUrl); } diff --git a/services.yml b/services.yml index 01ad0eb6..83144b6e 100644 --- a/services.yml +++ b/services.yml @@ -76,6 +76,7 @@ services: class: PHPCI\Command\UpdateCommand arguments: - @console.logger + - @config console.command.daemon: class: PHPCI\Command\DaemonCommand arguments: From a461fb580da309e19079f630929c397b38077250 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:33:44 +0200 Subject: [PATCH 13/33] Update poll command to use services. --- PHPCI/Command/PollCommand.php | 53 +++++++++++++++++++++++------------ services.yml | 16 ++++++++--- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/PHPCI/Command/PollCommand.php b/PHPCI/Command/PollCommand.php index d0381b10..e930adff 100644 --- a/PHPCI/Command/PollCommand.php +++ b/PHPCI/Command/PollCommand.php @@ -9,15 +9,16 @@ namespace PHPCI\Command; -use b8\Store\Factory; use b8\HttpClient; use Monolog\Logger; use PHPCI\Helper\Lang; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Yaml\Parser; +use PHPCI\Config; use PHPCI\Model\Build; +use PHPCI\Store\BuildStore; +use PHPCI\Store\ProjectStore; /** * Run console command - Poll github for latest commit id @@ -28,15 +29,39 @@ use PHPCI\Model\Build; class PollCommand extends Command { /** - * @var \Monolog\Logger + * @var Config + */ + protected $config; + + /** + * @var Logger */ protected $logger; - public function __construct(Logger $logger) + /** + * @var BuildStore + */ + protected $buildStore; + + /** + * @var ProjectStore + */ + protected $projectStore; + + /** + * @var HttpClient + */ + protected $githubClient; + + public function __construct(Config $config, Logger $logger, BuildStore $buildStore, ProjectStore $projectStore, HttpClient $githubClient) { parent::__construct(); + $this->config = $config; $this->logger = $logger; + $this->buildStore = $buildStore; + $this->projectStore = $projectStore; + $this->githubClient = $githubClient; } protected function configure() @@ -51,27 +76,19 @@ class PollCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $parser = new Parser(); - $yaml = file_get_contents(APPLICATION_PATH . 'PHPCI/config.yml'); - $this->settings = $parser->parse($yaml); - - $token = $this->settings['phpci']['github']['token']; + $token = $this->config->get('phpci.github.token'); if (!$token) { $this->logger->error(Lang::get('no_token')); return; } - $buildStore = Factory::getStore('Build'); - $this->logger->addInfo(Lang::get('finding_projects')); - $projectStore = Factory::getStore('Project'); - $result = $projectStore->getWhere(); + $result = $this->projectStore->getWhere(); $this->logger->addInfo(Lang::get('found_n_projects', count($result['items']))); foreach ($result['items'] as $project) { - $http = new HttpClient('https://api.github.com'); - $commits = $http->get('/repos/' . $project->getReference() . '/commits', array('access_token' => $token)); + $commits = $this->githubClient->get('/repos/' . $project->getReference() . '/commits', array('access_token' => $token)); $last_commit = $commits['body'][0]['sha']; $last_committer = $commits['body'][0]['commit']['committer']['email']; @@ -90,14 +107,14 @@ class PollCommand extends Command $build->setStatus(Build::STATUS_NEW); $build->setBranch($project->getBranch()); $build->setCreated(new \DateTime()); - $build->setCommitMessage($message); + $build->setCommitMessage($message); if (!empty($last_committer)) { $build->setCommitterEmail($last_committer); } - $buildStore->save($build); + $this->buildStore->save($build); $project->setLastCommit($last_commit); - $projectStore->save($project); + $this->projectStore->save($project); } } diff --git a/services.yml b/services.yml index 83144b6e..45e5287e 100644 --- a/services.yml +++ b/services.yml @@ -6,22 +6,22 @@ parameters: services: storage.user: - class: PHPCI\Store\Base\UserStore + class: PHPCI\Store\UserStore factory: [%storage.factory%, getStore] arguments: - User storage.project: - class: PHPCI\Store\Base\ProjectStore + class: PHPCI\Store\ProjectStore factory: [%storage.factory%, getStore] arguments: - Project storage.build: - class: PHPCI\Store\Base\BuildStore + class: PHPCI\Store\BuildStore factory: [%storage.factory%, getStore] arguments: - Build storage.build_meta: - class: PHPCI\Store\Base\BuildMetaStore + class: PHPCI\Store\BuildMetaStore factory: [%storage.factory%, getStore] arguments: - BuildMeta @@ -31,6 +31,10 @@ services: http.response: class: b8\Http\Response arguments: [] + http_client.github: + class: b8\HttpClient + arguments: + - https://api.github.com config: class: PHPCI\Config arguments: [%config_file%] @@ -85,7 +89,11 @@ services: console.command.poll: class: PHPCI\Command\PollCommand arguments: + - @config - @console.logger + - @storage.build + - @storage.project + - @http_client.github console.command.create_admin: class: PHPCI\Command\CreateAdminCommand arguments: From 6a43003f240d5f4ad8924ca455434ea6a713a882 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:41:18 +0200 Subject: [PATCH 14/33] User services in rebuild command. --- PHPCI/Command/RebuildCommand.php | 22 +++++++++++++++------- services.yml | 5 +++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/PHPCI/Command/RebuildCommand.php b/PHPCI/Command/RebuildCommand.php index 14a90dfd..1ed474d2 100644 --- a/PHPCI/Command/RebuildCommand.php +++ b/PHPCI/Command/RebuildCommand.php @@ -12,6 +12,7 @@ namespace PHPCI\Command; use b8\Store\Factory; use Monolog\Logger; use PHPCI\Service\BuildService; +use PHPCI\Store\BuildStore; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; @@ -46,13 +47,22 @@ class RebuildCommand extends Command protected $sleep; /** - * @param \Monolog\Logger $logger + * @param BuildStore */ - public function __construct(Logger $logger) + protected $buildStore; + + /** + * @param BuildService + */ + protected $buildService; + + public function __construct(Logger $logger, BuildStore $buildStore, BuildService $buildService) { parent::__construct(); $this->logger = $logger; + $this->buildStore = $buildStore; + $this->buildService = $buildService; } protected function configure() @@ -71,13 +81,11 @@ class RebuildCommand extends Command $runner->setMaxBuilds(1); $runner->setDaemon(false); - /** @var \PHPCI\Store\BuildStore $store */ - $store = Factory::getStore('Build'); - $service = new BuildService($store); + $service = new BuildService($this->buildStore); - $builds = $store->getLatestBuilds(null, 1); + $builds = $this->buildStore->getLatestBuilds(null, 1); $lastBuild = array_shift($builds); - $service->createDuplicateBuild($lastBuild); + $this->buildService->createDuplicateBuild($lastBuild); $runner->run(new ArgvInput(array()), $output); } diff --git a/services.yml b/services.yml index 45e5287e..42c96463 100644 --- a/services.yml +++ b/services.yml @@ -47,6 +47,9 @@ services: service.user: class: PHPCI\Service\UserService arguments: [@storage.user] + service.build: + class: PHPCI\Service\BuildService + arguments: [@storage.build] process_control: factory: [PHPCI\ProcessControl\Factory, getInstance] console.application: @@ -76,6 +79,8 @@ services: class: PHPCI\Command\RebuildCommand arguments: - @console.logger + - @storage.build + - @service.build console.command.update: class: PHPCI\Command\UpdateCommand arguments: From 7e71e2ec7bae1f0fb6b144265325833881ba8228 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 11:43:21 +0200 Subject: [PATCH 15/33] User services in rebuild command. --- PHPCI/Command/RebuildCommand.php | 15 +++++++++------ services.yml | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/PHPCI/Command/RebuildCommand.php b/PHPCI/Command/RebuildCommand.php index 1ed474d2..fc9ef0ab 100644 --- a/PHPCI/Command/RebuildCommand.php +++ b/PHPCI/Command/RebuildCommand.php @@ -56,13 +56,19 @@ class RebuildCommand extends Command */ protected $buildService; - public function __construct(Logger $logger, BuildStore $buildStore, BuildService $buildService) + /** + * @param RunCommand + */ + protected $runCommand; + + public function __construct(Logger $logger, BuildStore $buildStore, BuildService $buildService, RunCommand $runCommand) { parent::__construct(); $this->logger = $logger; $this->buildStore = $buildStore; $this->buildService = $buildService; + $this->runCommand = $runCommand; } protected function configure() @@ -77,11 +83,8 @@ class RebuildCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $runner = new RunCommand($this->logger); - $runner->setMaxBuilds(1); - $runner->setDaemon(false); - - $service = new BuildService($this->buildStore); + $this->runCommand->setMaxBuilds(1); + $this->runCommand->setDaemon(false); $builds = $this->buildStore->getLatestBuilds(null, 1); $lastBuild = array_shift($builds); diff --git a/services.yml b/services.yml index 42c96463..d66f3f47 100644 --- a/services.yml +++ b/services.yml @@ -81,6 +81,7 @@ services: - @console.logger - @storage.build - @service.build + - @console.command.run console.command.update: class: PHPCI\Command\UpdateCommand arguments: From 601d42ea6ee4f523ebf5768f3ad1dea09c0e791d Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 13:30:38 +0200 Subject: [PATCH 16/33] Added container service into application. --- PHPCI/Application.php | 4 +++- services.yml | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 46e213ff..ca96b92d 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -18,6 +18,7 @@ use b8\Http\Router; use b8\View; use PHPCI\Store\UserStore; use PHPCI\Store\ProjectStore; +use Symfony\Component\DependencyInjection\Container; /** * PHPCI Front Controller @@ -40,13 +41,14 @@ class Application extends b8\Application */ protected $projectStore; - public function __construct(Config $config, Request $request, Response $response, UserStore $userStore, ProjectStore $projectStore) + public function __construct(Config $config, Request $request, Response $response, UserStore $userStore, ProjectStore $projectStore, Container $container) { $this->config = $config; $this->response = $response; $this->request = $request; $this->userStore = $userStore; $this->projectStore = $projectStore; + $this->container = $container; $this->router = new Router($this, $this->request, $this->config); diff --git a/services.yml b/services.yml index d66f3f47..69115d9b 100644 --- a/services.yml +++ b/services.yml @@ -40,7 +40,13 @@ services: arguments: [%config_file%] application: class: PHPCI\Application - arguments: [@config, @http.request, @http.response, @storage.user, @storage.project] + arguments: + - @config + - @http.request + - @http.response + - @storage.user + - @storage.project + - @service_container service.build: class: PHPCI\Service\BuildService arguments: [@storage.build] From b6f25e77c3439a1c56cf8d37430feab04093501b Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 13:31:16 +0200 Subject: [PATCH 17/33] Load controller as services. --- PHPCI/Application.php | 29 ++++++++++++++++++----------- PHPCI/Controller.php | 4 ++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index ca96b92d..e938d423 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -135,8 +135,7 @@ class Application extends b8\Application if ($this->response->hasLayout() && $this->controller->layout) { $this->setLayoutVariables($this->controller->layout); - - $this->controller->layout->content = $this->response->getContent(); + $this->controller->layout->content = $this->response->getContent(); $this->response->setContent($this->controller->layout->render()); } @@ -144,18 +143,26 @@ class Application extends b8\Application } /** - * Loads a particular controller, and injects our layout view into it. - * @param $class - * @return mixed + * @return \PHPCI\Controller */ - protected function loadController($class) + public function getController() { - $controller = parent::loadController($class); - $controller->layout = new View('layout'); - $controller->layout->title = 'PHPCI'; - $controller->layout->breadcrumb = array(); + if (empty($this->controller)) { + try { + $this->controller = $this->container->get('application.controller.' . strtolower($this->route['controller'])); + } + catch (\Exception $e) { + var_dump($this->route); + var_dump($e); + } + } - return $controller; + return $this->controller; + } + + public function controllerExists($route) + { + return $this->container->has('application.controller.' . strtolower($route['controller'])); } /** diff --git a/PHPCI/Controller.php b/PHPCI/Controller.php index 803c9dbf..29eab80f 100644 --- a/PHPCI/Controller.php +++ b/PHPCI/Controller.php @@ -52,6 +52,10 @@ class Controller extends \b8\Controller { parent::__construct($config, $request, $response); + $this->layout = new View('layout'); + $this->layout->title = 'PHPCI'; + $this->layout->breadcrumb = array(); + $class = explode('\\', get_class($this)); $this->className = substr(array_pop($class), 0, -10); $this->setControllerView(); From 56082f201b8fe4175bdf6a4c7c61914c5ca83335 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 13:31:34 +0200 Subject: [PATCH 18/33] Controller are now services. --- PHPCI/Controller/BuildController.php | 25 ++++--- PHPCI/Controller/BuildStatusController.php | 30 +++++++-- PHPCI/Controller/HomeController.php | 26 +++++--- PHPCI/Controller/ProjectController.php | 38 +++++++---- PHPCI/Controller/SessionController.php | 20 ++++-- PHPCI/Controller/UserController.php | 29 +++++--- PHPCI/Controller/WebhookController.php | 23 +++++-- services.yml | 78 +++++++++++++++++++++- 8 files changed, 207 insertions(+), 62 deletions(-) diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index e4660ba7..006abe4b 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -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; } /** diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index 0090e85f..a6f582e7 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -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; } /** diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index d0e5a14b..db563b40 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -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; } /** diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 3a55f49b..6d5e877b 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -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)'); diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index 2995c514..cf643c36 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -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; } /** diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index 19a7313f..37e72214 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -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'); diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index 45a775ad..e279f188 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -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. diff --git a/services.yml b/services.yml index 69115d9b..44072633 100644 --- a/services.yml +++ b/services.yml @@ -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: From 4b957e8d5d37382dfbf38f7f055e50b758195709 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 15:06:45 +0200 Subject: [PATCH 19/33] Daemon application using DIC. --- console | 4 +--- daemonise | 6 ++---- services.yml | 7 +++++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/console b/console index dc3b3a41..31103d33 100755 --- a/console +++ b/console @@ -12,9 +12,7 @@ define('PHPCI_IS_CONSOLE', true); require('bootstrap.php'); -use Symfony\Component\Console\Application; - -/** @var Application */ +/** @var \Symfony\Component\Console\Application */ $application = $container->get('console.application'); $application->run(); diff --git a/daemonise b/daemonise index c6238568..fbe21ceb 100755 --- a/daemonise +++ b/daemonise @@ -12,9 +12,7 @@ define('PHPCI_IS_CONSOLE', true); require('bootstrap.php'); -use PHPCI\Command\DaemoniseCommand; -use Symfony\Component\Console\Application; +/** @var \Symfony\Component\Console\Application */ +$application = $container->get('daemon.application'); -$application = new Application(); -$application->add(new DaemoniseCommand($loggerConfig->getFor('DaemoniseCommand'))); $application->run(); diff --git a/services.yml b/services.yml index 44072633..f955034a 100644 --- a/services.yml +++ b/services.yml @@ -145,6 +145,13 @@ services: - [add, ['@console.command.poll']] - [add, ['@console.command.create_admin']] - [add, ['@console.command.create_build']] + daemon.application: + class: Symfony\Component\Console\Application + arguments: + - %application.name% + - %application.version% + calls: + - [add, ['@console.command.daemon']] console.logger: class: Monolog\Logger arguments: From 98221397b507f8748e103b762e631024242b7882 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 15:15:38 +0200 Subject: [PATCH 20/33] Check about bootstrap for test phase. --- vars.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars.php b/vars.php index 5306b9b8..40c1a6c4 100644 --- a/vars.php +++ b/vars.php @@ -8,7 +8,7 @@ if (!defined('APPLICATION_PATH')) { // Define our PHPCI_URL, if not already defined: if (!defined('PHPCI_URL')) { - define('PHPCI_URL', $container->get('config')->get('phpci.url')); + define('PHPCI_URL', isset($container) ? $container->get('config')->get('phpci.url') : ''); } // Define PHPCI_BIN_DIR @@ -38,5 +38,5 @@ if (!defined('IS_WIN')) { // If an environment variable is set defining our config location, use that // otherwise fall back to PHPCI/config.yml. if (!defined('PHPCI_CONFIG_FILE')) { - define('PHPCI_CONFIG_FILE', $container->get('config_file')); + define('PHPCI_CONFIG_FILE', isset($container) ? $container->get('config_file') : 'PHPCI/config.yml'); } From 7d9e0659636816af3494e3714d31390a5e8d8a8b Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 15:19:20 +0200 Subject: [PATCH 21/33] Fixed tests after DIC introduction refactoring. --- Tests/PHPCI/Command/CreateAdminCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/PHPCI/Command/CreateAdminCommandTest.php b/Tests/PHPCI/Command/CreateAdminCommandTest.php index 10b7b7f3..d68f4ba5 100644 --- a/Tests/PHPCI/Command/CreateAdminCommandTest.php +++ b/Tests/PHPCI/Command/CreateAdminCommandTest.php @@ -35,7 +35,7 @@ class CreateAdminCommandTest extends \PHPUnit_Framework_TestCase parent::setup(); $this->command = $this->getMockBuilder('PHPCI\\Command\\CreateAdminCommand') - ->setConstructorArgs(array($this->getMock('PHPCI\\Store\\UserStore'))) + ->setConstructorArgs(array($this->getMock('PHPCI\\Service\\UserService', array(), array(), '', false))) ->setMethods(array('reloadConfig')) ->getMock() ; From 180bdcf4fe04955de68b8109c6e86008a1c6bcd8 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 16:01:51 +0200 Subject: [PATCH 22/33] Improve CS. --- PHPCI/Controller/BuildController.php | 1 + PHPCI/Helper/BaseCommandExecutor.php | 10 ++++++++++ PHPCI/Store/Base/BuildMetaStoreBase.php | 19 ++++++++++++++----- PHPCI/Store/Base/BuildStoreBase.php | 16 +++++++++++++--- PHPCI/Store/Base/ProjectStoreBase.php | 13 ++++++++++--- PHPCI/Store/Base/UserStoreBase.php | 19 +++++++++++++++---- 6 files changed, 63 insertions(+), 15 deletions(-) diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index 006abe4b..cd4e3a58 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -223,6 +223,7 @@ class BuildController extends \PHPCI\Controller $response = new JsonResponse(); $response->setContent($rtn); + return $response; } diff --git a/PHPCI/Helper/BaseCommandExecutor.php b/PHPCI/Helper/BaseCommandExecutor.php index bd948834..0b3d3398 100644 --- a/PHPCI/Helper/BaseCommandExecutor.php +++ b/PHPCI/Helper/BaseCommandExecutor.php @@ -34,9 +34,19 @@ abstract class BaseCommandExecutor implements CommandExecutor */ protected $verbose; + /** + * @var string + */ protected $lastOutput; + + /** + * @var string + */ protected $lastError; + /** + * @var bool + */ public $logExecOutput = true; /** diff --git a/PHPCI/Store/Base/BuildMetaStoreBase.php b/PHPCI/Store/Base/BuildMetaStoreBase.php index 7a3d4159..7a493691 100644 --- a/PHPCI/Store/Base/BuildMetaStoreBase.php +++ b/PHPCI/Store/Base/BuildMetaStoreBase.php @@ -22,8 +22,10 @@ class BuildMetaStoreBase extends Store /** * Returns a BuildMeta model by primary key. + * * @param mixed $value * @param string $useConnection + * * @return \@appNamespace\Model\BuildMeta|null */ public function getByPrimaryKey($value, $useConnection = 'read') @@ -33,10 +35,13 @@ class BuildMetaStoreBase extends Store /** * Returns a BuildMeta model by Id. + * * @param mixed $value * @param string $useConnection - * @throws HttpException + * * @return \@appNamespace\Model\BuildMeta|null + * + * @throws HttpException */ public function getById($value, $useConnection = 'read') { @@ -59,11 +64,14 @@ class BuildMetaStoreBase extends Store /** * Returns an array of BuildMeta models by ProjectId. + * * @param mixed $value * @param int $limit * @param string $useConnection - * @throws HttpException + * * @return array + * + * @throws HttpException */ public function getByProjectId($value, $limit = 1000, $useConnection = 'read') { @@ -71,7 +79,6 @@ class BuildMetaStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id LIMIT :limit'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':project_id', $value); @@ -95,11 +102,14 @@ class BuildMetaStoreBase extends Store /** * Returns an array of BuildMeta models by BuildId. + * * @param mixed $value * @param int $limit * @param string $useConnection - * @throws HttpException + * * @return array + * + * @throws HttpException */ public function getByBuildId($value, $limit = 1000, $useConnection = 'read') { @@ -107,7 +117,6 @@ class BuildMetaStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id LIMIT :limit'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':build_id', $value); diff --git a/PHPCI/Store/Base/BuildStoreBase.php b/PHPCI/Store/Base/BuildStoreBase.php index 0560d72b..3d1d5cec 100644 --- a/PHPCI/Store/Base/BuildStoreBase.php +++ b/PHPCI/Store/Base/BuildStoreBase.php @@ -22,8 +22,10 @@ class BuildStoreBase extends Store /** * Returns a Build model by primary key. + * * @param mixed $value * @param string $useConnection + * * @return \@appNamespace\Model\Build|null */ public function getByPrimaryKey($value, $useConnection = 'read') @@ -33,10 +35,13 @@ class BuildStoreBase extends Store /** * Returns a Build model by Id. + * * @param mixed $value * @param string $useConnection - * @throws HttpException + * * @return \@appNamespace\Model\Build|null + * + * @throws HttpException */ public function getById($value, $useConnection = 'read') { @@ -59,10 +64,13 @@ class BuildStoreBase extends Store /** * Returns an array of Build models by ProjectId. + * * @param mixed $value * @param int $limit * @param string $useConnection + * * @throws HttpException + * * @return array */ public function getByProjectId($value, $limit = 1000, $useConnection = 'read') @@ -95,11 +103,14 @@ class BuildStoreBase extends Store /** * Returns an array of Build models by Status. + * * @param mixed $value * @param int $limit * @param string $useConnection - * @throws HttpException + * * @return array + * + * @throws HttpException */ public function getByStatus($value, $limit = 1000, $useConnection = 'read') { @@ -107,7 +118,6 @@ class BuildStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM `build` WHERE `status` = :status LIMIT :limit'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':status', $value); diff --git a/PHPCI/Store/Base/ProjectStoreBase.php b/PHPCI/Store/Base/ProjectStoreBase.php index 562afba2..4fab932c 100644 --- a/PHPCI/Store/Base/ProjectStoreBase.php +++ b/PHPCI/Store/Base/ProjectStoreBase.php @@ -22,8 +22,10 @@ class ProjectStoreBase extends Store /** * Returns a Project model by primary key. + * * @param mixed $value * @param string $useConnection + * * @return \@appNamespace\Model\Project|null */ public function getByPrimaryKey($value, $useConnection = 'read') @@ -33,10 +35,13 @@ class ProjectStoreBase extends Store /** * Returns a Project model by Id. + * * @param mixed $value * @param string $useConnection - * @throws HttpException + * * @return \@appNamespace\Model\Project|null + * + * @throws HttpException */ public function getById($value, $useConnection = 'read') { @@ -59,11 +64,14 @@ class ProjectStoreBase extends Store /** * Returns an array of Project models by Title. + * * @param mixed $value * @param int $limit * @param string $useConnection - * @throws HttpException + * * @return array + * + * @throws HttpException */ public function getByTitle($value, $limit = 1000, $useConnection = 'read') { @@ -71,7 +79,6 @@ class ProjectStoreBase extends Store throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } - $query = 'SELECT * FROM `project` WHERE `title` = :title LIMIT :limit'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':title', $value); diff --git a/PHPCI/Store/Base/UserStoreBase.php b/PHPCI/Store/Base/UserStoreBase.php index f2893ac5..36cbb389 100644 --- a/PHPCI/Store/Base/UserStoreBase.php +++ b/PHPCI/Store/Base/UserStoreBase.php @@ -22,8 +22,10 @@ class UserStoreBase extends Store /** * Returns a User model by primary key. + * * @param mixed $value * @param string $useConnection + * * @return \@appNamespace\Model\User|null */ public function getByPrimaryKey($value, $useConnection = 'read') @@ -33,10 +35,13 @@ class UserStoreBase extends Store /** * Returns a User model by Id. + * * @param mixed $value * @param string $useConnection - * @throws HttpException + * * @return \@appNamespace\Model\User|null + * + * @throws HttpException */ public function getById($value, $useConnection = 'read') { @@ -59,10 +64,13 @@ class UserStoreBase extends Store /** * Returns a User model by Email. + * * @param string $value * @param string $useConnection + * + * @return \@appNamespace\Model\User|null + * * @throws HttpException - * @return \@appNamespace\Model\User|null */ public function getByEmail($value, $useConnection = 'read') { @@ -82,13 +90,16 @@ class UserStoreBase extends Store return null; } - + /** * Returns a User model by Email. + * * @param string $value * @param string $useConnection - * @throws HttpException + * * @return \@appNamespace\Model\User|null + * + * @throws HttpException */ public function getByLoginOrEmail($value, $useConnection = 'read') { From e977360083a5ff8345c7657ffb65a3d44930a68a Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 16:32:50 +0200 Subject: [PATCH 23/33] Added BuildStatus::ccxml tests. --- PHPCI/Controller/BuildStatusController.php | 21 +++--- .../Controller/BuildStatusControllerTest.php | 70 +++++++++++++++++++ 2 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 Tests/PHPCI/Controller/BuildStatusControllerTest.php diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index a6f582e7..20625dc0 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -11,11 +11,13 @@ namespace PHPCI\Controller; use b8; use b8\Exception\HttpException\NotFoundException; +use b8\Exception\HttpException\NotAuthorizedException; use b8\Store; use b8\Http\Request; use b8\Http\Response; use PHPCI\Config; use PHPCI\BuildFactory; +use PHPCI\Helper\Lang; use PHPCI\Model\Project; use PHPCI\Model\Build; use PHPCI\Service\BuildStatusService; @@ -50,8 +52,6 @@ class BuildStatusController extends \PHPCI\Controller { parent::__construct($config, $request, $response); - $this->response->disableLayout(); - $this->buildStore = $buildStore; $this->projectStore = $projectStore; } @@ -98,12 +98,16 @@ class BuildStatusController extends \PHPCI\Controller { /* @var Project $project */ $project = $this->projectStore->getById($projectId); - $xml = new \SimpleXMLElement(''); - if (!$project instanceof Project || !$project->getAllowPublicStatus()) { - return $this->renderXml($xml); + if (!$project instanceof Project) { + throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } + if (!$project->getAllowPublicStatus()) { + throw new NotAuthorizedException(); + } + + $xml = new \SimpleXMLElement(''); try { $branchList = $this->buildStore->getBuildBranches($projectId); @@ -120,7 +124,6 @@ class BuildStatusController extends \PHPCI\Controller } } } - } catch (\Exception $e) { $xml = new \SimpleXMLElement(''); } @@ -134,12 +137,11 @@ class BuildStatusController extends \PHPCI\Controller */ protected function renderXml(\SimpleXMLElement $xml = null) { + $this->response->disableLayout(); $this->response->setHeader('Content-Type', 'text/xml'); $this->response->setContent($xml->asXML()); - $this->response->flush(); - echo $xml->asXML(); - return true; + return $this->response; } /** @@ -170,6 +172,7 @@ class BuildStatusController extends \PHPCI\Controller $this->response->disableLayout(); $this->response->setHeader('Content-Type', 'image/svg+xml'); $this->response->setContent($image); + return $this->response; } diff --git a/Tests/PHPCI/Controller/BuildStatusControllerTest.php b/Tests/PHPCI/Controller/BuildStatusControllerTest.php new file mode 100644 index 00000000..36c4fce9 --- /dev/null +++ b/Tests/PHPCI/Controller/BuildStatusControllerTest.php @@ -0,0 +1,70 @@ +prophesize('PHPCI\Store\BuildStore'); + $projectStore = $this->prophesize('PHPCI\Store\ProjectStore'); + + $project = new Project(); + $project->setAllowPublicStatus(false); + + $projectStore->getById(Argument::any())->willReturn($project); + + $webController = new BuildStatusController( + $this->prophesize('PHPCI\Config')->reveal(), + $this->prophesize('b8\Http\Request')->reveal(), + new \b8\Http\Response(), + $buildStore->reveal(), + $projectStore->reveal() + ); + + $result = $webController->handleAction('ccxml', [1]); + } + + public function test_ccxml_visible_for_public_project() + { + $buildStore = $this->prophesize('PHPCI\Store\BuildStore'); + $projectStore = $this->prophesize('PHPCI\Store\ProjectStore'); + $project = new Project(); + $project->setId(1); + $project->setBranch('test'); + $project->setAllowPublicStatus(true); + + $projectStore->getById(1)->willReturn($project); + + $webController = new BuildStatusController( + $this->prophesize('PHPCI\Config')->reveal(), + $this->prophesize('b8\Http\Request')->reveal(), + new \b8\Http\Response(), + $buildStore->reveal(), + $projectStore->reveal() + ); + + $result = $webController->handleAction('ccxml', [1]); + $this->assertInstanceOf('b8\Http\Response', $result); + + $responseData = $result->getData(); + $this->assertEquals('text/xml', $responseData['headers']['Content-Type']); + $this->assertXmlStringEqualsXmlString('', $responseData['body']); + } +} From f125047951421434f2cabe6d46f0db39190ca0c1 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 16:56:42 +0200 Subject: [PATCH 24/33] Use a HttpClient service to get the shield.io badge. --- PHPCI/Controller/BuildStatusController.php | 50 ++++++++++++------- .../Controller/BuildStatusControllerTest.php | 6 ++- services.yml | 5 ++ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index 20625dc0..d7ccac2f 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -13,8 +13,10 @@ use b8; use b8\Exception\HttpException\NotFoundException; use b8\Exception\HttpException\NotAuthorizedException; use b8\Store; +use b8\HttpClient; use b8\Http\Request; use b8\Http\Response; +use Exception; use PHPCI\Config; use PHPCI\BuildFactory; use PHPCI\Helper\Lang; @@ -47,19 +49,25 @@ class BuildStatusController extends \PHPCI\Controller Request $request, Response $response, BuildStore $buildStore, - ProjectStore $projectStore + ProjectStore $projectStore, + HttpClient $shieldsClient ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; $this->projectStore = $projectStore; + $this->shieldsClient = $shieldsClient; } /** * Returns status of the last build - * @param $projectId + * + * @param int $projectId + * * @return string + * + * @throws Exception */ protected function getStatus($projectId) { @@ -79,7 +87,7 @@ class BuildStatusController extends \PHPCI\Controller $status = 'failed'; } } - } catch (\Exception $e) { + } catch (Exception $e) { $status = 'error'; } @@ -89,10 +97,12 @@ class BuildStatusController extends \PHPCI\Controller /** * Displays projects information in ccmenu format * - * @param $projectId - * @return bool - * @throws \Exception - * @throws b8\Exception\HttpException + * @param int $projectId + * + * @return Response + * + * @throws Exception + * @throws HttpException */ public function ccxml($projectId) { @@ -132,8 +142,11 @@ class BuildStatusController extends \PHPCI\Controller } /** + * Render the XML object + * * @param \SimpleXMLElement $xml - * @return bool + * + * @return Response */ protected function renderXml(\SimpleXMLElement $xml = null) { @@ -146,6 +159,10 @@ class BuildStatusController extends \PHPCI\Controller /** * Returns the appropriate build status image in SVG format for a given project. + * + * @param int $projectId + * + * @return Response */ public function image($projectId) { @@ -161,17 +178,14 @@ class BuildStatusController extends \PHPCI\Controller } $color = ($status == 'passing') ? 'green' : 'red'; - $image = file_get_contents(sprintf( - 'http://img.shields.io/badge/%s-%s-%s.svg?style=%s', - $label, - $status, - $color, - $style - )); + $image = $this->shieldsClient->get( + sprintf('/badge/%s-%s-%s.svg', $label, $status, $color), + array('style' => $style) + ); $this->response->disableLayout(); $this->response->setHeader('Content-Type', 'image/svg+xml'); - $this->response->setContent($image); + $this->response->setContent($image['body']); return $this->response; } @@ -187,11 +201,11 @@ class BuildStatusController extends \PHPCI\Controller $project = $this->projectStore->getById($projectId); if (empty($project)) { - throw new NotFoundException('Project with id: ' . $projectId . ' not found'); + throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } if (!$project->getAllowPublicStatus()) { - throw new NotFoundException('Project with id: ' . $projectId . ' not found'); + throw new NotAuthorizedException(); } $builds = $this->getLatestBuilds($projectId); diff --git a/Tests/PHPCI/Controller/BuildStatusControllerTest.php b/Tests/PHPCI/Controller/BuildStatusControllerTest.php index 36c4fce9..a8332e8e 100644 --- a/Tests/PHPCI/Controller/BuildStatusControllerTest.php +++ b/Tests/PHPCI/Controller/BuildStatusControllerTest.php @@ -35,7 +35,8 @@ class BuildStatusControllerTest extends \PHPUnit_Framework_TestCase $this->prophesize('b8\Http\Request')->reveal(), new \b8\Http\Response(), $buildStore->reveal(), - $projectStore->reveal() + $projectStore->reveal(), + $this->prophesize('b8\HttpClient')->reveal() ); $result = $webController->handleAction('ccxml', [1]); @@ -57,7 +58,8 @@ class BuildStatusControllerTest extends \PHPUnit_Framework_TestCase $this->prophesize('b8\Http\Request')->reveal(), new \b8\Http\Response(), $buildStore->reveal(), - $projectStore->reveal() + $projectStore->reveal(), + $this->prophesize('b8\HttpClient')->reveal() ); $result = $webController->handleAction('ccxml', [1]); diff --git a/services.yml b/services.yml index f955034a..3ac11f28 100644 --- a/services.yml +++ b/services.yml @@ -35,6 +35,10 @@ services: class: b8\HttpClient arguments: - https://api.github.com + http_client.shields: + class: b8\HttpClient + arguments: + - http://img.shields.io config: class: PHPCI\Config arguments: [%config_file%] @@ -81,6 +85,7 @@ services: - @http.response - @storage.build - @storage.project + - @http_client.shields application.controller.user: class: PHPCI\Controller\UserController arguments: From b1e387e19557a44507d6f7a61ee4f25e25eeaa4f Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 17:09:17 +0200 Subject: [PATCH 25/33] Shields.io integration cleanup. --- PHPCI/Controller/BuildStatusController.php | 90 ++++++++----------- .../Controller/BuildStatusControllerTest.php | 59 ++++++++++++ 2 files changed, 95 insertions(+), 54 deletions(-) diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index d7ccac2f..56f82011 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -60,40 +60,6 @@ class BuildStatusController extends \PHPCI\Controller $this->shieldsClient = $shieldsClient; } - /** - * Returns status of the last build - * - * @param int $projectId - * - * @return string - * - * @throws Exception - */ - protected function getStatus($projectId) - { - $branch = $this->getParam('branch', 'master'); - try { - $project = $this->projectStore->getById($projectId); - $status = 'passing'; - - if (!$project->getAllowPublicStatus()) { - return null; - } - - if (isset($project) && $project instanceof Project) { - $build = $project->getLatestBuild($branch, array(2,3)); - - if (isset($build) && $build instanceof Build && $build->getStatus() != 2) { - $status = 'failed'; - } - } - } catch (Exception $e) { - $status = 'error'; - } - - return $status; - } - /** * Displays projects information in ccmenu format * @@ -138,18 +104,6 @@ class BuildStatusController extends \PHPCI\Controller $xml = new \SimpleXMLElement(''); } - return $this->renderXml($xml); - } - - /** - * Render the XML object - * - * @param \SimpleXMLElement $xml - * - * @return Response - */ - protected function renderXml(\SimpleXMLElement $xml = null) - { $this->response->disableLayout(); $this->response->setHeader('Content-Type', 'text/xml'); $this->response->setContent($xml->asXML()); @@ -166,16 +120,20 @@ class BuildStatusController extends \PHPCI\Controller */ public function image($projectId) { + $project = $this->projectStore->getById($projectId); + + if (empty($project)) { + throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); + } + + if (!$project->getAllowPublicStatus()) { + throw new NotAuthorizedException(); + } + $style = $this->getParam('style', 'plastic'); $label = $this->getParam('label', 'build'); - - $status = $this->getStatus($projectId); - - if (is_null($status)) { - $response = new b8\Http\Response\RedirectResponse(); - $response->setHeader('Location', '/'); - return $response; - } + $branch = $this->getParam('branch', 'master'); + $status = $this->getStatus($project, $branch); $color = ($status == 'passing') ? 'green' : 'red'; $image = $this->shieldsClient->get( @@ -235,4 +193,28 @@ class BuildStatusController extends \PHPCI\Controller return $builds['items']; } + + /** + * Returns status of the last build + * + * @param int $projectId + * + * @return string + * + * @throws Exception + */ + protected function getStatus($project, $branch) + { + try { + $build = $project->getLatestBuild($branch, array(2,3)); + + if (isset($build) && $build instanceof Build && $build->getStatus() != 2) { + return 'failed'; + } + } catch (Exception $e) { + return 'error'; + } + + return 'passing'; + } } diff --git a/Tests/PHPCI/Controller/BuildStatusControllerTest.php b/Tests/PHPCI/Controller/BuildStatusControllerTest.php index a8332e8e..05d9dc8c 100644 --- a/Tests/PHPCI/Controller/BuildStatusControllerTest.php +++ b/Tests/PHPCI/Controller/BuildStatusControllerTest.php @@ -69,4 +69,63 @@ class BuildStatusControllerTest extends \PHPUnit_Framework_TestCase $this->assertEquals('text/xml', $responseData['headers']['Content-Type']); $this->assertXmlStringEqualsXmlString('', $responseData['body']); } + + + /** + * @expectedException \b8\Exception\HttpException\NotAuthorizedException + */ + public function test_image_hidden_for_non_public_project() + { + $buildStore = $this->prophesize('PHPCI\Store\BuildStore'); + $projectStore = $this->prophesize('PHPCI\Store\ProjectStore'); + + $project = new Project(); + $project->setAllowPublicStatus(false); + + $projectStore->getById(Argument::any())->willReturn($project); + + $webController = new BuildStatusController( + $this->prophesize('PHPCI\Config')->reveal(), + $this->prophesize('b8\Http\Request')->reveal(), + new \b8\Http\Response(), + $buildStore->reveal(), + $projectStore->reveal(), + $this->prophesize('b8\HttpClient')->reveal() + ); + + $result = $webController->handleAction('image', [1]); + } + + public function test_image_visible_for_public_project() + { + $buildStore = $this->prophesize('PHPCI\Store\BuildStore'); + $projectStore = $this->prophesize('PHPCI\Store\ProjectStore'); + $project = new Project(); + $project->setId(1); + $project->setBranch('test'); + $project->setAllowPublicStatus(true); + + $projectStore->getById(1)->willReturn($project); + + $shieldsClient = $this->prophesize('b8\HttpClient'); + $shieldsClient->get(Argument::any(), Argument::any())->willReturn(array( + 'body' => '', + )); + + $webController = new BuildStatusController( + $this->prophesize('PHPCI\Config')->reveal(), + $this->prophesize('b8\Http\Request')->reveal(), + new \b8\Http\Response(), + $buildStore->reveal(), + $projectStore->reveal(), + $shieldsClient->reveal() + ); + + $result = $webController->handleAction('image', [1]); + $this->assertInstanceOf('b8\Http\Response', $result); + + $responseData = $result->getData(); + $this->assertEquals('image/svg+xml', $responseData['headers']['Content-Type']); + $this->assertXmlStringEqualsXmlString('', $responseData['body']); + } } From 9d03112aed66a777bb5bac786d438d5ce2c75f06 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 17:26:53 +0200 Subject: [PATCH 26/33] Fixed indendentation. --- PHPCI/Application.php | 15 ++++++++------- PHPCI/Controller/BuildController.php | 12 ++++++------ PHPCI/Controller/BuildStatusController.php | 14 +++++++------- PHPCI/Controller/HomeController.php | 12 ++++++------ PHPCI/Controller/ProjectController.php | 16 ++++++++-------- PHPCI/Controller/SessionController.php | 10 +++++----- PHPCI/Controller/UserController.php | 12 ++++++------ PHPCI/Controller/WebhookController.php | 14 +++++++------- 8 files changed, 53 insertions(+), 52 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index e938d423..2d4b37a9 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -41,7 +41,14 @@ class Application extends b8\Application */ protected $projectStore; - public function __construct(Config $config, Request $request, Response $response, UserStore $userStore, ProjectStore $projectStore, Container $container) + public function __construct( + Config $config, + Request $request, + Response $response, + UserStore $userStore, + ProjectStore $projectStore, + Container $container + ) { $this->config = $config; $this->response = $response; @@ -148,13 +155,7 @@ class Application extends b8\Application public function getController() { if (empty($this->controller)) { - try { $this->controller = $this->container->get('application.controller.' . strtolower($this->route['controller'])); - } - catch (\Exception $e) { - var_dump($this->route); - var_dump($e); - } } return $this->controller; diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index cd4e3a58..cbc0876e 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -42,12 +42,12 @@ class BuildController extends \PHPCI\Controller protected $buildService; public function __construct( - Config $config, - Request $request, - Response $response, - BuildStore $buildStore, - BuildService $buildService - ) + Config $config, + Request $request, + Response $response, + BuildStore $buildStore, + BuildService $buildService + ) { parent::__construct($config, $request, $response); diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index 56f82011..0d3c881d 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -45,13 +45,13 @@ class BuildStatusController extends \PHPCI\Controller protected $projectStore; public function __construct( - Config $config, - Request $request, - Response $response, - BuildStore $buildStore, - ProjectStore $projectStore, - HttpClient $shieldsClient - ) + Config $config, + Request $request, + Response $response, + BuildStore $buildStore, + ProjectStore $projectStore, + HttpClient $shieldsClient + ) { parent::__construct($config, $request, $response); diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index db563b40..55c79bd8 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -38,12 +38,12 @@ class HomeController extends \PHPCI\Controller protected $projectStore; public function __construct( - Config $config, - Request $request, - Response $response, - BuildStore $buildStore, - ProjectStore $projectStore - ) + Config $config, + Request $request, + Response $response, + BuildStore $buildStore, + ProjectStore $projectStore + ) { parent::__construct($config, $request, $response); diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 6d5e877b..70a6e00b 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -55,14 +55,14 @@ class ProjectController extends PHPCI\Controller protected $buildService; public function __construct( - Config $config, - Request $request, - Response $response, - BuildStore $buildStore, - ProjectStore $projectStore, - ProjectService $projectService, - BuildService $buildService - ) + Config $config, + Request $request, + Response $response, + BuildStore $buildStore, + ProjectStore $projectStore, + ProjectService $projectService, + BuildService $buildService + ) { parent::__construct($config, $request, $response); diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index cf643c36..91b6cb0b 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -31,11 +31,11 @@ class SessionController extends \PHPCI\Controller protected $userStore; public function __construct( - Config $config, - Request $request, - Response $response, - UserStore $userStore, - ) + Config $config, + Request $request, + Response $response, + UserStore $userStore, + ) { parent::__construct($config, $request, $response); diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index 37e72214..eed41830 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -39,12 +39,12 @@ class UserController extends Controller protected $userService; public function __construct( - Config $config, - Request $request, - Response $response, - UserStore $userStore, - UserService $userService - ) + Config $config, + Request $request, + Response $response, + UserStore $userStore, + UserService $userService + ) { parent::__construct($config, $request, $response); diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index e279f188..a1212f4f 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -49,13 +49,13 @@ class WebhookController extends \b8\Controller protected $buildService; public function __construct( - Config $config, - Request $request, - Response $response, - BuildStore $buildStore, - ProjectStore $projectStore, - BuildService $buildService - ) + Config $config, + Request $request, + Response $response, + BuildStore $buildStore, + ProjectStore $projectStore, + BuildService $buildService + ) { parent::__construct($config, $request, $response); From e0803df283f0255ffb14fc520292e92c3fe2365f Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 17:32:03 +0200 Subject: [PATCH 27/33] Fixed dockblock. --- PHPCI/Application.php | 18 ++++++++++++++++++ PHPCI/Controller/BuildController.php | 9 +++++++++ PHPCI/Controller/BuildStatusController.php | 10 ++++++++++ PHPCI/Controller/HomeController.php | 9 +++++++++ PHPCI/Controller/ProjectController.php | 11 +++++++++++ PHPCI/Controller/SessionController.php | 12 ++++++++++-- PHPCI/Controller/UserController.php | 9 +++++++++ PHPCI/Controller/WebhookController.php | 10 ++++++++++ 8 files changed, 86 insertions(+), 2 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 2d4b37a9..9b7fec03 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -41,6 +41,16 @@ class Application extends b8\Application */ protected $projectStore; + /** + * Create the PHPCI web application. + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param UserStore $userStore + * @param ProjectStore $projectStore + * @param Container $container + */ public function __construct( Config $config, Request $request, @@ -161,6 +171,13 @@ class Application extends b8\Application return $this->controller; } + /** + * Check if the specified controller exist. + * + * @param array $route + * + * @return boolean + */ public function controllerExists($route) { return $this->container->has('application.controller.' . strtolower($route['controller'])); @@ -168,6 +185,7 @@ class Application extends b8\Application /** * Injects variables into the layout before rendering it. + * * @param View $layout */ protected function setLayoutVariables(View &$layout) diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index cbc0876e..6d47ec7a 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -41,6 +41,15 @@ class BuildController extends \PHPCI\Controller */ protected $buildService; + /** + * Create the Build controller + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param BuildStore $buildStore + * @param BuildService $buildService + */ public function __construct( Config $config, Request $request, diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index 0d3c881d..85cb4f49 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -44,6 +44,16 @@ class BuildStatusController extends \PHPCI\Controller */ protected $projectStore; + /** + * Create the BuildStatus controller. + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param BuildStore $buildStore + * @param ProjectStore $projectStore + * @param HttpClient $shieldsClient + */ public function __construct( Config $config, Request $request, diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index 55c79bd8..97831bbc 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -37,6 +37,15 @@ class HomeController extends \PHPCI\Controller */ protected $projectStore; + /** + * Create the Home controller. + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param BuildStore $buildStore + * @param ProjectStore $projectStore + */ public function __construct( Config $config, Request $request, diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 70a6e00b..9005b03b 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -54,6 +54,17 @@ class ProjectController extends PHPCI\Controller */ protected $buildService; + /** + * Create the Project controller. + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param BuildStore $buildStore + * @param ProjectStore $projectStore + * @param ProjectService $projectService + * @param BuildService $buildService + */ public function __construct( Config $config, Request $request, diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index 91b6cb0b..c38d59ee 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -30,6 +30,14 @@ class SessionController extends \PHPCI\Controller */ protected $userStore; + /** + * Create the Sesssion controller. + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param UserStore $userStore + */ public function __construct( Config $config, Request $request, @@ -44,8 +52,8 @@ class SessionController extends \PHPCI\Controller } /** - * Handles user login (form and processing) - */ + * Handles user login (form and processing) + */ public function login() { $isLoginFailure = false; diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index eed41830..3b5578b4 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -38,6 +38,15 @@ class UserController extends Controller */ protected $userService; + /** + * Create the User controller. + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param UserStore $userStore + * @param UserService $userService + */ public function __construct( Config $config, Request $request, diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index a1212f4f..cd94564c 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -48,6 +48,16 @@ class WebhookController extends \b8\Controller */ protected $buildService; + /** + * Create the Webhook controller. + * + * @param Config $config + * @param Request $request + * @param Response $response + * @param BuildStore $buildStore + * @param ProjectStore $projectStore + * @param BuildService $buildService + */ public function __construct( Config $config, Request $request, From 4fe62ea248dc077fa1fb3bb0cc2e84a563af3c92 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 17:39:52 +0200 Subject: [PATCH 28/33] Fixed PHPCS. --- PHPCI/Application.php | 19 +++++++++++++++---- PHPCI/Controller/BuildController.php | 3 +-- PHPCI/Controller/BuildStatusController.php | 3 +-- PHPCI/Controller/HomeController.php | 3 +-- PHPCI/Controller/ProjectController.php | 3 +-- PHPCI/Controller/SessionController.php | 3 +-- PHPCI/Controller/UserController.php | 3 +-- PHPCI/Controller/WebhookController.php | 3 +-- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 9b7fec03..9f2cc86e 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -58,8 +58,7 @@ class Application extends b8\Application UserStore $userStore, ProjectStore $projectStore, Container $container - ) - { + ) { $this->config = $config; $this->response = $response; $this->request = $request; @@ -165,7 +164,7 @@ class Application extends b8\Application public function getController() { if (empty($this->controller)) { - $this->controller = $this->container->get('application.controller.' . strtolower($this->route['controller'])); + $this->controller = $this->container->get($this->getControllerId($this->route)); } return $this->controller; @@ -180,7 +179,19 @@ class Application extends b8\Application */ public function controllerExists($route) { - return $this->container->has('application.controller.' . strtolower($route['controller'])); + return $this->container->has($this->getControllerId($route)); + } + + /** + * Create controller service Id based on specified route. + * + * @param array $route + * + * @return string + */ + protected function getControllerId($route) + { + return 'application.controller.' . strtolower($route['controller']); } /** diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index 6d47ec7a..80c84420 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -56,8 +56,7 @@ class BuildController extends \PHPCI\Controller Response $response, BuildStore $buildStore, BuildService $buildService - ) - { + ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index 85cb4f49..98e3280b 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -61,8 +61,7 @@ class BuildStatusController extends \PHPCI\Controller BuildStore $buildStore, ProjectStore $projectStore, HttpClient $shieldsClient - ) - { + ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index 97831bbc..31f51554 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -52,8 +52,7 @@ class HomeController extends \PHPCI\Controller Response $response, BuildStore $buildStore, ProjectStore $projectStore - ) - { + ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 9005b03b..a339e5d8 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -73,8 +73,7 @@ class ProjectController extends PHPCI\Controller ProjectStore $projectStore, ProjectService $projectService, BuildService $buildService - ) - { + ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index c38d59ee..0e401b58 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -43,8 +43,7 @@ class SessionController extends \PHPCI\Controller Request $request, Response $response, UserStore $userStore, - ) - { + ) { parent::__construct($config, $request, $response); $this->response->disableLayout(); diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index 3b5578b4..3e99beba 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -53,8 +53,7 @@ class UserController extends Controller Response $response, UserStore $userStore, UserService $userService - ) - { + ) { parent::__construct($config, $request, $response); $this->userStore = $userStore; diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index cd94564c..975b1203 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -65,8 +65,7 @@ class WebhookController extends \b8\Controller BuildStore $buildStore, ProjectStore $projectStore, BuildService $buildService - ) - { + ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; From 7693993df83f5a7bde8a0fe8e28aaa85be1c198c Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 17:44:52 +0200 Subject: [PATCH 29/33] Fixed PHPCI in plugins. --- PHPCI/Plugin/Codeception.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/PHPCI/Plugin/Codeception.php b/PHPCI/Plugin/Codeception.php index b906fb70..9d78d3bc 100644 --- a/PHPCI/Plugin/Codeception.php +++ b/PHPCI/Plugin/Codeception.php @@ -137,13 +137,11 @@ class Codeception implements \PHPCI\Plugin, \PHPCI\ZeroConfigPlugin $configPath = $this->phpci->buildPath . $configPath; $success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $configPath); - - $this->phpci->log( - 'Codeception XML path: '. $this->phpci->buildPath . $this->path . 'report.xml', - Loglevel::DEBUG - ); - $xml = file_get_contents($this->phpci->buildPath . $this->path . 'report.xml', false); - + $this->phpci->log( + 'Codeception XML path: '. $this->phpci->buildPath . $this->path . 'report.xml', + Loglevel::DEBUG + ); + $xml = file_get_contents($this->phpci->buildPath . $this->path . 'report.xml', false); $parser = new Parser($this->phpci, $xml); $output = $parser->parse(); From be651b3576ae354cf1fadb594be3dcfc7898cf3f Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 17:48:09 +0200 Subject: [PATCH 30/33] Fixed parameter. --- PHPCI/Controller/SessionController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index 0e401b58..93e2fa27 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -42,7 +42,7 @@ class SessionController extends \PHPCI\Controller Config $config, Request $request, Response $response, - UserStore $userStore, + UserStore $userStore ) { parent::__construct($config, $request, $response); From 6aba86e018dbe592799440f5d95cb132cf0cb3be Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 18:19:52 +0200 Subject: [PATCH 31/33] Improved docBlock --- PHPCI/Controller/ProjectController.php | 8 ++++++-- PHPCI/Controller/UserController.php | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index a339e5d8..6347f29f 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -144,8 +144,12 @@ class ProjectController extends PHPCI\Controller } /** - * Delete a project. - */ + * Delete a project. + * + * @param int $projectId + * + * @return Response + */ public function delete($projectId) { $this->requireAdmin(); diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index 3e99beba..0dafc984 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -292,8 +292,14 @@ class UserController extends Controller } /** - * Delete a user. - */ + * Delete a user. + * + * @param int $userId + * + * @return Response + * + * @throws NotFoundException + */ public function delete($userId) { $this->requireAdmin(); @@ -308,6 +314,7 @@ class UserController extends Controller $response = new b8\Http\Response\RedirectResponse(); $response->setHeader('Location', PHPCI_URL . 'user'); + return $response; } } From da17482a803521c5a5f57fdd3c0c4d8b5584cfae Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 19 Jul 2015 20:08:25 +0200 Subject: [PATCH 32/33] Move BuildFactory to factory.build service. --- PHPCI/BuildFactory.php | 19 +++++++++++++++---- PHPCI/Command/RunCommand.php | 17 ++++++++++++----- PHPCI/Controller/BuildController.php | 19 +++++++++++++------ PHPCI/Controller/BuildStatusController.php | 12 ++++++++++-- PHPCI/Controller/HomeController.php | 14 +++++++++++--- PHPCI/Controller/ProjectController.php | 12 ++++++++++-- PHPCI/Controller/WebhookController.php | 12 ++++++++++-- services.yml | 10 ++++++++++ 8 files changed, 91 insertions(+), 24 deletions(-) diff --git a/PHPCI/BuildFactory.php b/PHPCI/BuildFactory.php index ecc37c43..280bfe6b 100644 --- a/PHPCI/BuildFactory.php +++ b/PHPCI/BuildFactory.php @@ -11,6 +11,7 @@ namespace PHPCI; use b8\Store\Factory; use PHPCI\Model\Build; +use PHPCI\Store\BuildStore; /** * PHPCI Build Factory - Takes in a generic "Build" and returns a type-specific build model. @@ -18,20 +19,30 @@ use PHPCI\Model\Build; */ class BuildFactory { + /** + * @var BuildStore + */ + protected $buildStore; + + public function __construct(BuildStore $buildStore) + { + $this->buildStore = $buildStore; + } + /** * @param $buildId * @return Build * @throws \Exception */ - public static function getBuildById($buildId) + public function getBuildById($buildId) { - $build = Factory::getStore('Build')->getById($buildId); + $build = $this->buildStore->getById($buildId); if (empty($build)) { throw new \Exception('Build ID ' . $buildId . ' does not exist.'); } - return self::getBuild($build); + return $this->getBuild($build); } /** @@ -39,7 +50,7 @@ class BuildFactory * @param Build $base The build from which to get a more specific build type. * @return Build */ - public static function getBuild(Build $base) + public function getBuild(Build $base) { switch($base->getProject()->getType()) { diff --git a/PHPCI/Command/RunCommand.php b/PHPCI/Command/RunCommand.php index e4d0a3f2..8d86e86e 100644 --- a/PHPCI/Command/RunCommand.php +++ b/PHPCI/Command/RunCommand.php @@ -41,6 +41,11 @@ class RunCommand extends Command */ protected $logger; + /** + * @var BuildFactory + */ + protected $buildFactory; + /** * @var int */ @@ -52,12 +57,14 @@ class RunCommand extends Command protected $isFromDaemon = false; /** - * @param \Monolog\Logger $logger - * @param string $name + * @param BuildFactory $buildFactory + * @param Logger $logger */ - public function __construct(Logger $logger) + public function __construct(BuildFactory $buildFactory, Logger $logger) { parent::__construct(); + + $this->buildFactory = $buildFactory; $this->logger = $logger; } @@ -95,7 +102,7 @@ class RunCommand extends Command while (count($result['items'])) { $build = array_shift($result['items']); - $build = BuildFactory::getBuild($build); + $build = $this->buildFactory->getBuild($build); // Skip build (for now) if there's already a build running in that project: if (!$this->isFromDaemon && in_array($build->getProjectId(), $running)) { @@ -156,7 +163,7 @@ class RunCommand extends Command foreach ($running['items'] as $build) { /** @var \PHPCI\Model\Build $build */ - $build = BuildFactory::getBuild($build); + $build = $this->buildFactory->getBuild($build); $now = time(); $start = $build->getStarted()->getTimestamp(); diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index 80c84420..9ad8d793 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -41,6 +41,11 @@ class BuildController extends \PHPCI\Controller */ protected $buildService; + /** + * @var BuildFactory + */ + protected $buildFactory; + /** * Create the Build controller * @@ -55,12 +60,14 @@ class BuildController extends \PHPCI\Controller Request $request, Response $response, BuildStore $buildStore, - BuildService $buildService + BuildService $buildService, + BuildFactory $buildFactory ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; $this->buildService = $buildService; + $this->buildFactory = $buildFactory; } /** @@ -69,7 +76,7 @@ class BuildController extends \PHPCI\Controller public function view($buildId) { try { - $build = BuildFactory::getBuildById($buildId); + $build = $this->buildFactory->getBuildById($buildId); } catch (\Exception $ex) { $build = null; } @@ -127,7 +134,7 @@ class BuildController extends \PHPCI\Controller public function data($buildId) { $response = new JsonResponse(); - $build = BuildFactory::getBuildById($buildId); + $build = $this->buildFactory->getBuildById($buildId); if (!$build) { $response->setResponseCode(404); @@ -144,7 +151,7 @@ class BuildController extends \PHPCI\Controller */ public function meta($buildId) { - $build = BuildFactory::getBuildById($buildId); + $build = $this->buildFactory->getBuildById($buildId); $key = $this->getParam('key', null); $numBuilds = $this->getParam('num_builds', 1); $data = null; @@ -178,7 +185,7 @@ class BuildController extends \PHPCI\Controller */ public function rebuild($buildId) { - $copy = BuildFactory::getBuildById($buildId); + $copy = $this->buildFactory->getBuildById($buildId); if (empty($copy)) { throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); @@ -198,7 +205,7 @@ class BuildController extends \PHPCI\Controller { $this->requireAdmin(); - $build = BuildFactory::getBuildById($buildId); + $build = $this->buildFactory->getBuildById($buildId); if (empty($build)) { throw new NotFoundException(Lang::get('build_x_not_found', $buildId)); diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php index 98e3280b..d2ffcf63 100644 --- a/PHPCI/Controller/BuildStatusController.php +++ b/PHPCI/Controller/BuildStatusController.php @@ -44,6 +44,11 @@ class BuildStatusController extends \PHPCI\Controller */ protected $projectStore; + /** + * @var BuildFactory + */ + protected $buildFactory; + /** * Create the BuildStatus controller. * @@ -53,6 +58,7 @@ class BuildStatusController extends \PHPCI\Controller * @param BuildStore $buildStore * @param ProjectStore $projectStore * @param HttpClient $shieldsClient + * @param BuildFactory $buildFactory */ public function __construct( Config $config, @@ -60,13 +66,15 @@ class BuildStatusController extends \PHPCI\Controller Response $response, BuildStore $buildStore, ProjectStore $projectStore, - HttpClient $shieldsClient + HttpClient $shieldsClient, + BuildFactory $buildFactory ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; $this->projectStore = $projectStore; $this->shieldsClient = $shieldsClient; + $this->buildFactory = $buildFactory; } /** @@ -197,7 +205,7 @@ class BuildStatusController extends \PHPCI\Controller $builds = $this->buildStore->getWhere($criteria, 10, 0, array(), $order); foreach ($builds['items'] as &$build) { - $build = BuildFactory::getBuild($build); + $build = $this->buildFactory->getBuild($build); } return $builds['items']; diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index 31f51554..37970240 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -32,6 +32,11 @@ class HomeController extends \PHPCI\Controller */ protected $buildStore; + /** + * @var BuildFactory + */ + protected $buildFactory; + /** * @var ProjectStore */ @@ -45,18 +50,21 @@ class HomeController extends \PHPCI\Controller * @param Response $response * @param BuildStore $buildStore * @param ProjectStore $projectStore + * @param BuildFactory $buildFactory */ public function __construct( Config $config, Request $request, Response $response, BuildStore $buildStore, - ProjectStore $projectStore + ProjectStore $projectStore, + BuildFactory $buildFactory ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; $this->projectStore = $projectStore; + $this->buildFactory = $buildFactory; } /** @@ -77,7 +85,7 @@ class HomeController extends \PHPCI\Controller $builds = $this->buildStore->getLatestBuilds(null, 10); foreach ($builds as &$build) { - $build = BuildFactory::getBuild($build); + $build = $this->buildFactory->getBuild($build); } $this->view->builds = $builds; @@ -158,7 +166,7 @@ class HomeController extends \PHPCI\Controller $view = new b8\View('BuildsTable'); foreach ($builds['items'] as &$build) { - $build = BuildFactory::getBuild($build); + $build = $this->buildFactory->getBuild($build); } $view->builds = $builds['items']; diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 6347f29f..3de30be5 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -54,6 +54,11 @@ class ProjectController extends PHPCI\Controller */ protected $buildService; + /** + * @var BuildFactory + */ + protected $buildFactory; + /** * Create the Project controller. * @@ -64,6 +69,7 @@ class ProjectController extends PHPCI\Controller * @param ProjectStore $projectStore * @param ProjectService $projectService * @param BuildService $buildService + * @param BuildFactory $buildFactory */ public function __construct( Config $config, @@ -72,7 +78,8 @@ class ProjectController extends PHPCI\Controller BuildStore $buildStore, ProjectStore $projectStore, ProjectService $projectService, - BuildService $buildService + BuildService $buildService, + BuildFactory $buildFactory ) { parent::__construct($config, $request, $response); @@ -80,6 +87,7 @@ class ProjectController extends PHPCI\Controller $this->projectStore = $projectStore; $this->projectService = $projectService; $this->buildService = $buildService; + $this->buildFactory = $buildFactory; } /** @@ -195,7 +203,7 @@ class ProjectController extends PHPCI\Controller $view = new b8\View('BuildsTable'); foreach ($builds['items'] as &$build) { - $build = BuildFactory::getBuild($build); + $build = $this->buildFactory->getBuild($build); } $view->builds = $builds['items']; diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index 975b1203..5c87451f 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -48,6 +48,11 @@ class WebhookController extends \b8\Controller */ protected $buildService; + /** + * @var BuildFactory + */ + protected $buildFactory; + /** * Create the Webhook controller. * @@ -57,6 +62,7 @@ class WebhookController extends \b8\Controller * @param BuildStore $buildStore * @param ProjectStore $projectStore * @param BuildService $buildService + * @param BuildFactory $buildFactory */ public function __construct( Config $config, @@ -64,13 +70,15 @@ class WebhookController extends \b8\Controller Response $response, BuildStore $buildStore, ProjectStore $projectStore, - BuildService $buildService + BuildService $buildService, + BuildFactory $buildFactory ) { parent::__construct($config, $request, $response); $this->buildStore = $buildStore; $this->projectStore = $projectStore; $this->buildService = $buildService; + $this->buildFactory = $buildFactory; } /** Handle the action, Ensuring to return a JsonResponse. @@ -382,7 +390,7 @@ class WebhookController extends \b8\Controller // If not, create a new build job for it: $build = $this->buildService->createBuild($project, $commitId, $branch, $committer, $commitMessage, $extra); - $build = BuildFactory::getBuild($build); + $build = $this->buildFactory->getBuild($build); // Send a status postback if the build type provides one: $build->sendStatusPostback(); diff --git a/services.yml b/services.yml index 3ac11f28..638a57b0 100644 --- a/services.yml +++ b/services.yml @@ -25,6 +25,10 @@ services: factory: [%storage.factory%, getStore] arguments: - BuildMeta + factory.build: + class: PHPCI\BuildFactory + arguments: + - @storage.build http.request: class: b8\Http\Request arguments: [] @@ -59,6 +63,7 @@ services: - @http.response - @storage.build - @storage.project + - @factory.build application.controller.project: class: PHPCI\Controller\ProjectController arguments: @@ -69,6 +74,7 @@ services: - @storage.project - @service.project - @service.build + - @factory.build application.controller.build: class: PHPCI\Controller\BuildController arguments: @@ -77,6 +83,7 @@ services: - @http.response - @storage.build - @service.build + - @factory.build application.controller.buildstatus: class: PHPCI\Controller\BuildStatusController arguments: @@ -86,6 +93,7 @@ services: - @storage.build - @storage.project - @http_client.shields + - @factory.build application.controller.user: class: PHPCI\Controller\UserController arguments: @@ -124,6 +132,7 @@ services: - @storage.build - @storage.project - @service.build + - @factory.build service.build: class: PHPCI\Service\BuildService arguments: [@storage.build] @@ -164,6 +173,7 @@ services: console.command.run: class: PHPCI\Command\RunCommand arguments: + - @factory.build - @console.logger console.command.rebuild: class: PHPCI\Command\RebuildCommand From d22211c4b4ea8e65261be69907313d89f7a39399 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 19 Jul 2015 20:09:27 +0200 Subject: [PATCH 33/33] Improved docs. --- PHPCI/Builder.php | 10 ++++++++++ PHPCI/Helper/LoginIsDisabled.php | 14 ++++++++------ PHPCI/Helper/MailerFactory.php | 8 ++++++-- public/index.php | 1 + 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 39e8ca41..930777c5 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -99,6 +99,7 @@ class Builder implements LoggerAwareInterface /** * Set up the builder. + * * @param \PHPCI\Model\Build $build * @param LoggerInterface $logger */ @@ -130,6 +131,7 @@ class Builder implements LoggerAwareInterface /** * Set the config array, as read from phpci.yml + * * @param array|null $config * @throws \Exception */ @@ -144,6 +146,7 @@ class Builder implements LoggerAwareInterface /** * Access a variable from the phpci.yml file. + * * @param string * @return mixed */ @@ -160,6 +163,7 @@ class Builder implements LoggerAwareInterface /** * Access a variable from the config.yml + * * @param $key * @return mixed */ @@ -259,6 +263,7 @@ class Builder implements LoggerAwareInterface /** * Find a binary required by a plugin. + * * @param string $binary * @param bool $quiet * @@ -272,6 +277,7 @@ class Builder implements LoggerAwareInterface /** * Replace every occurrence of the interpolation vars in the given string * Example: "This is build %PHPCI_BUILD%" => "This is build 182" + * * @param string $input * @return string */ @@ -328,6 +334,7 @@ class Builder implements LoggerAwareInterface /** * Write to the build log. + * * @param $message * @param string $level * @param array $context @@ -339,6 +346,7 @@ class Builder implements LoggerAwareInterface /** * Add a success-coloured message to the log. + * * @param string */ public function logSuccess($message) @@ -348,6 +356,7 @@ class Builder implements LoggerAwareInterface /** * Add a failure-coloured message to the log. + * * @param string $message * @param \Exception $exception The exception that caused the error. */ @@ -359,6 +368,7 @@ class Builder implements LoggerAwareInterface * Returns a configured instance of the plugin factory. * * @param Build $build + * * @return PluginFactory */ private function buildPluginFactory(Build $build) diff --git a/PHPCI/Helper/LoginIsDisabled.php b/PHPCI/Helper/LoginIsDisabled.php index 437b95cd..5732c172 100644 --- a/PHPCI/Helper/LoginIsDisabled.php +++ b/PHPCI/Helper/LoginIsDisabled.php @@ -12,15 +12,17 @@ namespace PHPCI\Helper; use b8\Config; /** -* Login Is Disabled Helper - Checks if login is disalbed in the view -* @author Stephen Ball -* @package PHPCI -* @subpackage Web -*/ + * Login Is Disabled Helper - Checks if login is disalbed in the view + * + * @author Stephen Ball + * @package PHPCI + * @subpackage Web + */ class LoginIsDisabled { /** * Checks if + * * @param $method * @param array $params * @return mixed|null @@ -28,7 +30,7 @@ class LoginIsDisabled public function __call($method, $params = array()) { unset($method, $params); - + $config = Config::getInstance(); $state = (bool) $config->get('phpci.authentication_settings.state', false); diff --git a/PHPCI/Helper/MailerFactory.php b/PHPCI/Helper/MailerFactory.php index 641c06b9..37fed72a 100644 --- a/PHPCI/Helper/MailerFactory.php +++ b/PHPCI/Helper/MailerFactory.php @@ -11,6 +11,7 @@ namespace PHPCI\Helper; /** * Class MailerFactory helps to set up and configure a SwiftMailer object. + * * @package PHPCI\Helper */ class MailerFactory @@ -22,6 +23,7 @@ class MailerFactory /** * Set the mailer factory configuration. + * * @param array $config */ public function __construct($config = array()) @@ -34,7 +36,8 @@ class MailerFactory } /** - * Returns an instance of Swift_Mailer based on the config.s + * Returns an instance of Swift_Mailer based on the config. + * * @return \Swift_Mailer */ public function getSwiftMailerFromConfig() @@ -61,7 +64,9 @@ class MailerFactory /** * Return a specific configuration value by key. + * * @param $configName + * * @return null|string */ public function getMailConfig($configName) @@ -70,7 +75,6 @@ class MailerFactory return $this->emailConfig[$configName]; } else { // Check defaults - switch($configName) { case 'smtp_address': return "localhost"; diff --git a/public/index.php b/public/index.php index d83582f3..27986c77 100644 --- a/public/index.php +++ b/public/index.php @@ -12,6 +12,7 @@ session_start(); require_once(__DIR__ . '/../bootstrap.php'); +/** @var PHPCI\Application */ $app = $container->get('application'); print $app->handleRequest();