First draft of DIC initialization with config.
This commit is contained in:
parent
65aba6b3c6
commit
ebf5a5dd7b
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
namespace PHPCI;
|
||||
|
||||
use b8\Config;
|
||||
use b8\Exception\HttpException\ForbiddenException;
|
||||
use b8\Http\Request;
|
||||
use b8\Http\Response;
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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": {
|
||||
|
|
56
composer.lock
generated
56
composer.lock
generated
|
@ -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": {
|
||||
|
|
|
@ -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();
|
||||
|
|
16
services.yml
Normal file
16
services.yml
Normal file
|
@ -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]
|
6
vars.php
6
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']);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue