First draft of DIC initialization with config.
This commit is contained in:
parent
65aba6b3c6
commit
ebf5a5dd7b
8 changed files with 119 additions and 37 deletions
|
|
@ -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']);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue