Fixing the console app so that it installs and runs composer if not present.

This commit is contained in:
Dan Cryer 2013-05-15 22:29:09 +01:00
parent 68c6f14cec
commit 1a92d1c619
3 changed files with 35 additions and 24 deletions

View file

@ -34,7 +34,9 @@ class InstallCommand extends Command
$str = "<?php
define('PHPCI_DB_HOST', '{$dbHost}');
if(!defined('PHPCI_DB_HOST')) {
define('PHPCI_DB_HOST', '{$dbHost}');
}
b8\Database::setDetails('{$dbName}', '{$dbUser}', '{$dbPass}');
b8\Database::setWriteServers(array('{$dbHost}'));
@ -52,18 +54,6 @@ b8\Database::setReadServers(array('{$dbHost}'));
file_put_contents(PHPCI_DIR . 'config.php', $str);
if(!file_exists(PHPCI_DIR . 'composer.phar'))
{
print 'INSTALLING: Composer' . PHP_EOL;
file_put_contents(PHPCI_DIR . 'composerinstaller.php', file_get_contents('https://getcomposer.org/installer'));
shell_exec('php ' . PHPCI_DIR . 'composerinstaller.php');
unlink(PHPCI_DIR . 'composerinstaller.php');
}
print 'RUNNING: Composer' . PHP_EOL;
shell_exec('php '.PHPCI_DIR.'composer.phar install');
require(PHPCI_DIR . 'bootstrap.php');
$gen = new \b8\Database\Generator(\b8\Database::getConnection(), 'PHPCI', './PHPCI/Model/Base/');

View file

@ -1,7 +1,9 @@
<?php
// Let PHP take a guess as to the default timezone, if the user hasn't set one:
date_default_timezone_set(@date_default_timezone_get());
// Set up a basic autoloader for PHPCI:
spl_autoload_register(function ($class)
{
$file = str_replace(array('\\', '_'), '/', $class);
@ -20,15 +22,21 @@ spl_autoload_register(function ($class)
}
}, true, true);
define('APPLICATION_PATH', dirname(__FILE__) . '/');
require_once('vendor/autoload.php');
if(file_exists(APPLICATION_PATH . 'config.php'))
{
require('config.php');
// Define our APPLICATION_PATH, if not already defined:
if(!defined('APPLICATION_PATH')) {
define('APPLICATION_PATH', dirname(__FILE__) . '/');
}
// Load Composer autoloader:
require_once(APPLICATION_PATH . 'vendor/autoload.php');
// Load configuration if present:
if(file_exists(APPLICATION_PATH . 'config.php'))
{
require(APPLICATION_PATH . 'config.php');
}
// Set up the registry:
b8\Registry::getInstance()->set('app_namespace', 'PHPCI');
b8\Registry::getInstance()->set('DefaultController', 'Index');
b8\Registry::getInstance()->set('ViewPath', dirname(__FILE__) . '/PHPCI/View/');

21
console
View file

@ -1,15 +1,28 @@
#!/usr/bin/env php
<?php
require_once('bootstrap.php');
define('PHPCI_BIN_DIR', dirname(__FILE__) . '/vendor/bin/');
define('PHPCI_DIR', dirname(__FILE__) . '/');
// If this is the first time ./console has been run, we probably don't have Composer or any of our dependencies yet.
// So we need to install and run Composer.
if(!file_exists(PHPCI_DIR . 'vendor/autoload.php') || !file_exists(PHPCI_DIR . 'composer.phar')) {
print 'INSTALLING: Composer' . PHP_EOL;
file_put_contents(PHPCI_DIR . 'composerinstaller.php', file_get_contents('https://getcomposer.org/installer'));
shell_exec('php ' . PHPCI_DIR . 'composerinstaller.php');
unlink(PHPCI_DIR . 'composerinstaller.php');
print 'RUNNING: Composer' . PHP_EOL;
shell_exec('php '.PHPCI_DIR.'composer.phar install');
}
require('bootstrap.php');
use PHPCI\Command\RunCommand;
use PHPCI\Command\GenerateCommand;
use PHPCI\Command\InstallCommand;
use Symfony\Component\Console\Application;
define('PHPCI_BIN_DIR', dirname(__FILE__) . '/vendor/bin/');
define('PHPCI_DIR', dirname(__FILE__) . '/');
$application = new Application();
$application->add(new RunCommand);
$application->add(new InstallCommand);