/** * Install the project based on the available config files * * @param string $installFile * @return void */ public static function install($installFile) { // Display instructions to continue $dbTables = array(); self::instructions(); $input = self::cliInput(); if ($input == 'n') { echo I18n::factory()->__('Aborted.') . PHP_EOL . PHP_EOL; exit(0); } // Get the install config. $installDir = realpath(dirname($installFile)); $install = (include $installFile); // Check if a project folder already exists. if (file_exists($install->project->name)) { echo wordwrap(I18n::factory()->__('Project folder exists. This may overwrite any project files you may already have under that project folder.'), 70, PHP_EOL) . PHP_EOL; $input = self::cliInput(); } else { $input = 'y'; } // If 'No', abort if ($input == 'n') { echo I18n::factory()->__('Aborted.') . PHP_EOL . PHP_EOL; exit(0); // Else, continue } else { $db = false; $databases = array(); // Test for a database creds and schema, and ask // to test and install the database. if (isset($install->databases)) { $databases = $install->databases->asArray(); echo I18n::factory()->__('Database credentials and schema detected.') . PHP_EOL; $input = self::cliInput(I18n::factory()->__('Test and install the database(s)?') . ' (Y/N) '); $db = $input == 'n' ? false : true; } // Handle any databases if ($db) { // Get current error reporting setting and set // error reporting to E_ERROR to suppress warnings $oldError = ini_get('error_reporting'); error_reporting(E_ERROR); // Test the databases echo I18n::factory()->__('Testing the database(s)...') . PHP_EOL; foreach ($databases as $dbname => $db) { echo I18n::factory()->__('Testing') . ' \'' . $dbname . '\'...' . PHP_EOL; if (!isset($db['type']) || !isset($db['database'])) { echo I18n::factory()->__('The database type and database name must be set for the database ') . '\'' . $dbname . '\'.' . PHP_EOL . PHP_EOL; exit(0); } $check = Install\Dbs::check($db); if (null !== $check) { echo $check . PHP_EOL . PHP_EOL; exit(0); } else { echo I18n::factory()->__('Database') . ' \'' . $dbname . '\' passed.' . PHP_EOL; echo I18n::factory()->__('Installing database') . ' \'' . $dbname . '\'...' . PHP_EOL; $tables = Install\Dbs::install($dbname, $db, $installDir, $install); if (count($tables) > 0) { $dbTables = array_merge($dbTables, $tables); } } } // Return error reporting to its original state error_reporting($oldError); } // Install base folder and file structure Install\Base::install($install); // Install project files Install\Projects::install($install, $installDir); // Install table class files if (count($dbTables) > 0) { Install\Tables::install($install, $dbTables); } // Install controller class files if (isset($install->controllers)) { Install\Controllers::install($install, $installDir); } // Install form class files if (isset($install->forms)) { Install\Forms::install($install); } // Install model class files if (isset($install->models)) { Install\Models::install($install); } // Create 'bootstrap.php' file Install\Bootstrap::install($install); echo I18n::factory()->__('Project install complete.') . PHP_EOL . PHP_EOL; } }