/** * Runs the different tasks */ public function run() { // Clean up all temporary files/folders CLI::write("\tClean up temp files..."); $this->cleanTempFiles(); CLI::write("\tClean up test folders..."); $this->cleanTestsFolder(); CLI::write("\tRemoving application modules..."); $this->cleanFolder($this->dest_path . '/application/modules', ['index.html', '.htaccess']); CLI::write("\tGenerating default encryption key for config file..."); $this->generateEncryptionKey(); }
/** * Tests the server to determine an appropriate value for the * password hash_cost value. * * By default it will find a value based on a target of 50ms of * processing time, which is suitable for interactive logins. * * @param int $target_time The number of milliseconds to target. */ public function index($target_time = 50) { // Convert the milliseconds to seconds. $target_time = $target_time / 1000; CLI::write('Testing for password hash value with a target time of ' . $target_time . ' seconds...'); // Taken from the PHP manual $cost = 8; do { $cost++; $start = microtime(true); password_hash("test", PASSWORD_BCRYPT, ["cost" => $cost]); $end = microtime(true); } while ($end - $start < $target_time); CLI::write("Hash value should be set to: " . CLI::color($cost, 'green')); }
/** * Runs the different tasks */ public function run() { $step = 1; // Copy the entire codebase to the new folder so we // can have something to work with and not wreck our code. CLI::write("\tCopying files..."); $this->copyFolder($this->source_path, $this->dest_path); // Clean up all temporary files/folders CLI::write("\tClean up temp files..."); $this->cleanTempFiles(); CLI::write("\tClean up test folders..."); $this->cleanTestsFolder(); CLI::write("\tRemoving application modules..."); $this->cleanFolder($this->dest_path . '/application/modules', ['index.html', '.htaccess']); CLI::write("\tCompressing files..."); $this->compressFolder($this->dest_path, $this->dest_path . '/Sprint_' . date('Y-m-d') . '.zip'); }
protected function sayDescriptions($descriptions) { $names = array_keys($descriptions); $syntaxes = array_column($descriptions, 0); $descs = array_column($descriptions, 1); // Pad each item to the same length $names = $this->padArray($names); $syntaxes = $this->padArray($syntaxes); for ($i = 0; $i < count($names); $i++) { $out = CLI::color($names[$i], 'yellow'); // The rest of the items stay default color. if (isset($syntaxes[$i])) { $out .= $syntaxes[$i]; } if (isset($descs[$i])) { $out .= CLI::wrap($descs[$i], 125, strlen($names[$i]) + strlen($syntaxes[$i])); } CLI::write($out); } }
$release = CLI::prompt("Which script", array_keys($config['builds'])); } if (!array_key_exists($release, $config['builds'])) { CLI::error('Invalid build specified: ' . $release); exit(1); } //-------------------------------------------------------------------- // Instantiate the class and run it //-------------------------------------------------------------------- $class_name = $config['builds'][$release]; if (!file_exists(BUILDBASE . "scripts/{$class_name}.php")) { CLI::error('Unable to find build script: ' . $class_name . '.php'); exit(1); } require BUILDBASE . "lib/BaseBuilder.php"; require BUILDBASE . "scripts/{$class_name}.php"; $builder = new $class_name($config['destinations'][$release], get_instance()); if (!is_object($builder)) { CLI::error('Unable to make new class: ' . $class_name); exit(1); } // run it! CLI::write("Running builder `{$release}` ({$class_name})...", 'yellow'); $builder->run(); //-------------------------------------------------------------------- // Show closing comments //-------------------------------------------------------------------- $end_time = microtime(true); $elapsed_time = number_format($end_time - $start_time, 4); CLI::write('Done in ' . $elapsed_time . ' seconds', 'green');
/** * Creates a new migration file ready to be used. * * @param $name */ public function newMigration($name = null, $type = 'app') { if (empty($name)) { $name = CLI::prompt('Migration name? '); if (empty($name)) { return CLI::error("\tYou must provide a migration name.", 'red'); } } $this->load->library('migration'); $path = $this->migration->determine_migration_path($type); // Does the alias path exist in our config? if (!$path) { return CLI::error("\tThe migration path for '{$type}' does not exist.'"); } // Does the path really exist? if (!is_dir($path)) { return CLI::error("\tThe path for '{$type}' is not a directory."); } // Is the folder writeable? if (!is_writeable($path)) { return CLI::error("\tThe folder for '{$type}' migrations is not writeable."); } $file = $this->migration->make_name($name); $path = rtrim($path, '/') . '/' . $file; $contents = <<<EOT <?php /** * Migration: {clean_name} * * Created by: SprintPHP * Created on: {date} */ class Migration_{name} extends CI_Migration { public function up () { } //-------------------------------------------------------------------- public function down () { } //-------------------------------------------------------------------- } EOT; $contents = str_replace('{name}', $name, $contents); $contents = str_replace('{date}', date('Y-m-d H:i:s a'), $contents); $contents = str_replace('{clean_name}', ucwords(str_replace('_', ' ', $name)), $contents); $this->load->helper('file'); if (write_file($path, $contents)) { return CLI::write("\tNew migration created: " . CLI::color($file, 'yellow'), 'green'); } return CLI::error("\tUnkown error trying to create migration: {$file}", 'red'); }
/** * Lists out all available tasks, names only. */ private function listTaskNames() { $suspended = Settings::get('suspended_tasks', 'cron'); if (empty($suspended)) { $suspended = []; } $tasks = \Myth\Cron\CronManager::listAll(); echo CLI::write("\nAvailable Tasks:"); foreach ($tasks as $alias => $task) { $color = 'yellow'; $extra = ''; if (in_array($alias, $suspended)) { $color = 'blue'; $extra = "[Suspended]"; } echo CLI::write("\t{$extra} {$alias}", $color); } }
/** * Outputs the contents of the file in the template's source path. */ public function readme($file = 'readme.txt') { $name = str_replace('Generator', '', get_class($this)); $path = $this->locateGenerator($name); if (!file_exists($path . $file)) { CLI::error(sprintf(lang('forge.cant_find_readme'), $file)); } $contents = file_get_contents($path . $file); CLI::new_line(2); CLI::write(CLI::wrap($contents), 'green'); CLI::new_line(); }
<?php defined('BASEPATH') or exit('No direct script access allowed'); echo \Myth\CLI::error("\n\t{$heading}"); echo \Myth\CLI::write("{$message}\n");
/** * Handles actually installing the tables and correct authentication * type. */ private function install() { CLI::write("Available Auth Types: " . CLI::color('basic, digest, none', 'yellow')); $this->auth_type = trim(CLI::prompt('Auth type')); switch ($this->auth_type) { case 'basic': $this->setupBasic(); $this->readme('readme_basic.txt'); break; case 'digest': $this->setupDigest(); $this->readme('readme_digest.txt'); break; } $this->setupLogging(); }
/** * Overrides CLIController's version to support searching our * collections for the help description. * * @param null $method */ public function longDescribeMethod($method = null) { $collections = config_item('forge.collections'); if (!is_array($collections) || !count($collections)) { return CLI::error('No generator collections found.'); } // We loop through each collection scanning // for any generator folders that have a // 'forge.php' file. For each one found // we build out another section in our help commands foreach ($collections as $alias => $path) { $path = rtrim($path, '/ ') . '/'; $folders = scandir($path); if (!($i = array_search(ucfirst($method), $folders))) { continue; } $dir = $path . $folders[$i] . '/'; if (!is_file($dir . '/forge.php')) { CLI::error("The {$method} command does not have any cli help available."); } include $dir . '/forge.php'; // Don't have valid arrays to work with? Move along... if (!isset($long_description)) { log_message('debug', '[Forge] Invalid forge.php file at: ' . $dir . '/forge.php'); continue; } if (empty($long_description)) { return CLI::error("The {$method} command does not have an cli help available."); } CLI::new_line(); CLI::write(CLI::color(ucfirst($method) . ' Help', 'yellow')); return CLI::write(CLI::wrap($long_description, CLI::getWidth())); } // Still here? CLI::error("No help found for command: {$method}"); }
<?php defined('BASEPATH') or exit('No direct script access allowed'); echo \Myth\CLI::error("\n\t404 ERROR: {$heading}"); echo \Myth\CLI::write("{$message}\n"); echo \Myth\CLI::write(\Myth\CLI::cli_string());
<?php defined('BASEPATH') or exit('No direct script access allowed'); ?> <?php echo \Myth\CLI::error("\n\tA PHP Error was encountered"); ?> <?php echo \Myth\CLI::write("\tSeverity: {$severity}"); echo \Myth\CLI::write("\tMessage: {$message}"); echo \Myth\CLI::write("\tFilename: {$filepath}"); echo \Myth\CLI::write("\tLine Number: {$line}"); ?> <?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE) { echo \Myth\CLI::write("\n\tBacktrace"); foreach (debug_backtrace() as $error) { if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0) { echo \Myth\CLI::write("\t\t- {$error['function']}() - Line {$error['line']} in {$error['file']}"); } } } echo \Myth\CLI::new_line();