public function run($segments = [], $quiet = false) { $name = array_shift($segments); if (empty($name)) { $name = CLI::prompt('View name'); } // Format to CI Standards $name = str_replace('.php', '', strtolower($name)); $destination = $this->determineOutputPath('views') . $name . '.php'; if (!$this->createFile($destination, "The {$name}.php view file.", $this->overwrite)) { CLI::error('Error creating view file.'); } return true; }
public function run($segments = [], $quiet = false) { $name = array_shift($segments); if (empty($name)) { $name = CLI::prompt('Seed name'); } // Format to CI Standards $name = str_replace('.php', '', strtolower($name)); if (substr($name, -4) == 'seed') { $name = substr($name, 0, strlen($name) - 4); } $name = ucfirst($name) . 'Seeder'; $data = ['seed_name' => $name, 'today' => date('Y-m-d H:ia')]; $destination = $this->determineOutputPath('database/seeds') . $name . '.php'; if (strpos($destination, 'modules') !== false) { $destination = str_replace('database/', '', $destination); } if (!$this->copyTemplate('seed', $destination, $data, $this->overwrite)) { CLI::error('Error creating seed file.'); } return true; }
/** * Loads the class file and calls the run() method * on the class. * * @param $class */ public function call($class) { if (empty($class)) { // Ask the user... $class = trim(CLI::prompt("Seeder name")); if (empty($class)) { return CLI::error("\tNo Seeder was specified."); } } $path = APPPATH . 'database/seeds/' . str_replace('.php', '', $class) . '.php'; if (!is_file($path)) { return CLI::error("\tUnable to find seed class: " . $class); } try { require $path; $seeder = new $class(); $seeder->run(); unset($seeder); } catch (\Exception $e) { show_error($e->getMessage(), $e->getCode()); } return Cli::write("\tSeeded: {$class}", 'green'); }
// Folder definitions define('BUILDBASE', __DIR__ . '/'); // Don't stop script exectuion on 404... function show_404($page = '', $log_error = TRUE) { } // Make sure we have access to CI() object. ob_start(); require BUILDBASE . '../index.php'; ob_end_clean(); //-------------------------------------------------------------------- // Determine the build script to run //-------------------------------------------------------------------- $release = CLI::segment(1); if (empty($release)) { $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";
/** * 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'); }
protected function collectOptions($name) { $options = CLI::getOptions(); // Model? $this->options['model'] = empty($options['model']) ? CLI::prompt('Model Name? (empty is fine)') : $options['model']; // Format per CI if (!empty($this->options['model']) && substr($this->options['model'], -6) !== '_model') { $this->options['model'] .= '_model'; } $this->options['model'] = !empty($this->options['model']) ? ucfirst($this->options['model']) : NULL; // If we're using a model, then force the use of a themed controller. if (!empty($this->options['model'])) { $options['themed'] = 'y'; } // Themed Controller? $this->options['themed'] = empty($options['themed']) ? CLI::prompt('Is a Themed Controller?', ['y', 'n']) : $options['themed']; $this->options['themed'] = $this->options['themed'] == 'y' ? TRUE : FALSE; if ($this->options['themed']) { $this->options['base_class'] = 'ThemedController'; } }
private function setupLogging() { $shouldWe = CLI::prompt('Enable Request Logging?', ['y', 'n']); if (strtolower($shouldWe) != 'y') { return; } $this->makeMigration('log_migration', 'Create_api_log_table'); // Update the config setting $content = "config['api.enable_logging'] = true;"; $this->injectIntoFile(APPPATH . 'config/api.php', $content, ['regex' => "/config\\['api.enable_logging']\\s+=\\s+[a-zA-Z]+;/u"]); }
/** * Displays the readme file for a generator if it exists. * * @param $command */ public function readme($command) { $dir = $this->locateGenerator($command); if (!is_file($dir . 'readme.txt')) { return CLI::error('Unable to locate the readme.txt file.'); } $lines = file($dir . 'readme.txt'); if (!is_array($lines) || !count($lines)) { return CLI::error('The readme file does not have anything to display.'); } $line_count = 0; // Total we're currently viewing. $max_rows = CLI::getHeight() - 3; foreach ($lines as $line) { $line_count++; if ($line_count >= $max_rows) { CLI::prompt("\nContinue..."); $line_count = 0; } echo CLI::wrap($line, 125); } CLI::new_line(2); }
public function collectOptions($name, $quiet = false) { $options = CLI::getOptions(); // Use existing db table? if (array_key_exists('fromdb', $options)) { $this->readTable($this->table); } else { $fields = !empty($options['fields']) ? $options['fields'] : null; if (empty($fields) && $quiet) { return; } $fields = empty($fields) ? CLI::prompt('Fields? (name:type)') : $options['fields']; $this->fields = $this->parseFields($fields); } }
protected function collectOptions($model_name, $options = []) { $this->load->helper('inflector'); // Table Name? if (empty($this->options['table_name'])) { $this->options['table_name'] = empty($options['table']) ? CLI::prompt('Table name', plural(strtolower(str_replace('_model', '', $model_name)))) : $options['table']; } $this->options['fields'] = $this->table_info($this->options['table_name'], $options); // Primary Key if (empty($this->options['primary_key'])) { $this->options['primary_key'] = empty($options['primary_key']) ? CLI::prompt('Primary Key', 'id') : $options['primary_key']; } $this->options['protected'] = [$this->options['primary_key']]; // Set Created? if (empty($options['set_created'])) { $ans = CLI::prompt('Set Created date?', ['y', 'n']); if ($ans == 'n') { $this->options['set_created'] = FALSE; } } // Set Modified? if (empty($options['set_modified'])) { $ans = CLI::prompt('Set Modified date?', ['y', 'n']); if ($ans == 'n') { $this->options['set_modified'] = FALSE; } } // Date Format $this->options['date_format'] = empty($options['date_format']) ? CLI::prompt('Date Format?', ['datetime', 'date', 'int']) : $options['date_format']; // Log User? if (empty($options['log_user'])) { $ans = CLI::prompt('Log User actions?', ['y', 'n']); if ($ans == 'y') { $this->options['log_user'] = TRUE; } } // Soft Deletes if (empty($options['soft_delete'])) { $ans = CLI::prompt('Use Soft Deletes?', ['y', 'n']); if ($ans == 'n') { $this->options['soft_delete'] = false; } } }