Skip to content

Commit ce6943d

Browse files
author
Dan Cryer
committed
Updating PHPCI to use YAML-based config files.
1 parent 6e3df00 commit ce6943d

3 files changed

Lines changed: 48 additions & 35 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ config.php
88
.project
99
.buildpath
1010
.htaccess
11+
PHPCI/config.yml

PHPCI/Command/InstallCommand.php

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,32 @@ protected function configure()
3838
protected function execute(InputInterface $input, OutputInterface $output)
3939
{
4040
// Gather initial data from the user:
41-
$dbHost = $this->ask('Enter your MySQL host: ');
42-
$dbName = $this->ask('Enter the database name PHPCI should use: ');
43-
$dbUser = $this->ask('Enter your MySQL username: ');
44-
$dbPass = $this->ask('Enter your MySQL password: ', true);
45-
$ciUrl = $this->ask('Your PHPCI URL (without trailing slash): ');
46-
$ghId = $this->ask('(Optional) Github Application ID: ', true);
47-
$ghSecret = $this->ask('(Optional) Github Application Secret: ', true);
41+
$conf = array();
42+
$conf['b8']['database']['servers']['read'] = $this->ask('Enter your MySQL host: ');
43+
$conf['b8']['database']['servers']['write'] = $conf['b8']['database']['servers']['read'];
44+
$conf['b8']['database']['name'] = $this->ask('Enter the database name PHPCI should use: ');
45+
$conf['b8']['database']['username'] = $this->ask('Enter your MySQL username: ');
46+
$conf['b8']['database']['password'] = $this->ask('Enter your MySQL password: ', true);
47+
$conf['phpci']['url'] = $this->ask('Your PHPCI URL (without trailing slash): ');
48+
$conf['phpci']['github']['id'] = $this->ask('(Optional) Github Application ID: ', true);
49+
$conf['phpci']['github']['secret'] = $this->ask('(Optional) Github Application Secret: ', true);
50+
51+
$dbUser = $conf['b8']['database']['username'];
52+
$dbPass = $conf['b8']['database']['password'];
53+
$dbHost = $conf['b8']['database']['servers']['write'];
54+
$dbName = $conf['b8']['database']['name'];
4855

4956
// Create the database if it doesn't exist:
5057
$cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost .
5158
' -e "CREATE DATABASE IF NOT EXISTS ' . $dbName . '"';
5259

5360
shell_exec($cmd);
5461

55-
$str = "<?php
62+
$dumper = new \Symfony\Component\Yaml\Dumper();
63+
$yaml = $dumper->dump($conf);
5664

57-
if(!defined('PHPCI_DB_HOST')) {
58-
define('PHPCI_DB_HOST', '{$dbHost}');
59-
}
60-
61-
b8\Database::setDetails('{$dbName}', '{$dbUser}', '{$dbPass}');
62-
b8\Database::setWriteServers(array('{$dbHost}'));
63-
b8\Database::setReadServers(array('{$dbHost}'));
64-
65-
\$config = b8\Config::getInstance();
66-
\$config->set('install_url', '{$ciUrl}');
67-
";
68-
69-
// Has the user entered Github app details? If so add those to config:
70-
if (!empty($ghId) && !empty($ghSecret)) {
71-
$str .= PHP_EOL .
72-
"\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" .
73-
PHP_EOL;
74-
}
65+
file_put_contents(PHPCI_DIR . 'PHPCI/config.yml', $yaml);
7566

76-
// Write the config file and then re-bootstrap:
77-
file_put_contents(PHPCI_DIR . 'config.php', $str);
7867
require(PHPCI_DIR . 'bootstrap.php');
7968

8069
// Update the database:

bootstrap.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,43 @@
3636
require_once(APPLICATION_PATH . 'vendor/autoload.php');
3737

3838
// Load configuration if present:
39-
$config = new b8\Config();
39+
$conf = array();
40+
$conf['b8']['app']['namespace'] = 'PHPCI';
41+
$conf['b8']['app']['default_controller'] = 'Index';
42+
$conf['b8']['view']['path'] = dirname(__FILE__) . '/PHPCI/View/';
43+
44+
$config = new b8\Config($conf);
4045
$request = new b8\Http\Request();
4146
$registry = new b8\Registry($config, $request);
4247

4348
if (file_exists(APPLICATION_PATH . 'config.php')) {
4449
require(APPLICATION_PATH . 'config.php');
4550

51+
$conf = $config->get(null);
52+
unset($conf['b8']['app']);
53+
unset($conf['b8']['view']);
54+
55+
$conf['phpci']['url'] = $conf['install_url'];
56+
57+
if (isset($conf['github_app'])) {
58+
$conf['phpci']['github'] = $conf['github_app'];
59+
}
60+
61+
unset($conf['install_url']);
62+
unset($conf['github_app']);
63+
64+
$dumper = new Symfony\Component\Yaml\Dumper();
65+
$yaml = $dumper->dump($conf);
66+
67+
file_put_contents(APPLICATION_PATH . 'PHPCI/config.yml', $yaml);
68+
unlink(APPLICATION_PATH . 'config.php');
69+
}
70+
71+
if (file_exists(APPLICATION_PATH . 'PHPCI/config.yml')) {
72+
$config->loadYaml(APPLICATION_PATH . 'PHPCI/config.yml');
73+
4674
// Define our PHPCI_URL, if not already defined:
4775
if (!defined('PHPCI_URL')) {
48-
define('PHPCI_URL', $config->get('install_url', '') . '/');
76+
define('PHPCI_URL', $config->get('phpci.url', '') . '/');
4977
}
5078
}
51-
52-
// Set up the registry:
53-
$config->set('app_namespace', 'PHPCI');
54-
$config->set('default_controller', 'Index');
55-
$config->set('view_path', dirname(__FILE__) . '/PHPCI/View/');

0 commit comments

Comments
 (0)