From 3eb1648e13f21c45986c8cd258041b30bd7153e3 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 31 May 2015 10:33:27 +0200 Subject: [PATCH] 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')); }