public function run($segments = [], $quiet = false) { $name = array_shift($segments); if (empty($name)) { $name = CLI::prompt('Migration name'); } // Format to CI Standards $name = str_replace('.php', '', strtolower($name)); $this->detectAction($name); $this->collectOptions($name, $quiet); $data = ['name' => $name, 'clean_name' => ucwords(str_replace('_', ' ', $name)), 'today' => date('Y-m-d H:ia'), 'fields' => trim($this->stringify($this->fields), ', '), 'raw_fields' => $this->fields, 'action' => $this->action, 'table' => $this->table, 'primary_key' => $this->primary_key, 'column' => $this->column]; if (!empty($this->column) && array_key_exists($this->column, $this->fields)) { $data['column_string'] = trim($this->stringify($this->fields[$this->column]), ', '); } $this->load->library('migration'); // todo Allow different migration "types" $type = 'app'; if (!empty($this->module)) { $type = 'mod:' . $this->module; } $destination = $this->migration->determine_migration_path($type, true); $file = $this->migration->make_name($name); $destination = rtrim($destination, '/') . '/' . $file; if (!$this->copyTemplate('migration', $destination, $data, true)) { CLI::error('Error creating seed file.'); } return true; }
public function run($segments = [], $quiet = FALSE) { $name = array_shift($segments); if (empty($name)) { $name = CLI::prompt('Controller name'); } // Format to CI Standards $name = ucfirst($name); if ($quiet === FALSE) { $this->collectOptions($name); } else { $this->quietSetOptions($name); } $data = ['controller_name' => $name, 'today' => date('Y-m-d H:ia')]; $data = array_merge($data, $this->options); if ($data['themed'] == 'y' || $data['themed'] === true) { $data['base_class'] = 'ThemedController'; } $destination = $this->determineOutputPath('controllers') . $name . '.php'; if (!$this->copyTemplate('controller', $destination, $data, $this->overwrite)) { CLI::error('Error creating new files'); } if (CLI::option('create_views') && $this->options['themed'] == 'y') { $this->createViews($name); } return TRUE; }
public function run($segments = [], $quiet = false) { $name = array_shift($segments); $options = CLI::getOptions(); $this->options['table_name'] = array_shift($segments); if (empty($name)) { $name = CLI::prompt('Model name'); } // Format to CI Standards if (substr($name, -6) !== '_model') { $name .= '_model'; } $name = ucfirst($name); if ($quiet === false) { $this->collectOptions($name, $options); } else { $this->quietSetOptions($name, $options); } $data = ['model_name' => $name, 'today' => date('Y-m-d H:ia')]; $data = array_merge($data, $this->options); $destination = $this->determineOutputPath('models') . $name . '.php'; if (!$this->copyTemplate('model', $destination, $data, $this->overwrite)) { CLI::error('Error creating new files'); } return TRUE; }
public function __construct($destination, $ci = null) { parent::__construct($ci); $this->source_path = realpath(BUILDBASE . '../'); if (empty($this->source_path)) { CLI::error('Unable to determine the source path.'); exit(1); } $this->dest_path = $this->source_path; }
public function __construct($destination) { $this->source_path = realpath(BUILDBASE . '../'); if (empty($this->source_path)) { CLI::error('Unable to determine the source path.'); exit(1); } $this->dest_path = BUILDBASE . $destination; $this->dest_path = rtrim($this->dest_path, '/ ') . '/' . date('Y-m-d'); }
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'); }
/** * 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'); }
/** * Resumes the running of tasks after the system has been disabled * with the `disable` command. */ public function enable() { if (!Settings::save('is_disabled', 'n', 'cron')) { return CLI::error('Unknown problem saving the setting. ' . CLI::color('Cron jobs will NOT run!', 'yellow')); } CLI::write('Done'); }
/** * Scans through the collections for the folder for this generator. * * @param $name * * @return null|string */ protected function locateGenerator($name) { $collections = config_item('forge.collections'); if (!is_array($collections) || !count($collections)) { return CLI::error(lang('forge.no_collections')); } foreach ($collections as $alias => $path) { $path = rtrim($path, '/ ') . '/'; $folders = scandir($path); if (!($i = array_search(ucfirst($name), $folders))) { continue; } $this->gen_path = $path . $folders[$i] . '/'; return $this->gen_path; } return null; }
<?php defined('BASEPATH') or exit('No direct script access allowed'); echo \Myth\CLI::error("\n\t{$heading}"); echo \Myth\CLI::write("{$message}\n");
public function compressFolder($source, $destination, $include_dir = false) { if (!extension_loaded('zip')) { CLI::error('ZipArchive extension is required.'); exit(1); } if (!file_exists($source)) { CLI::error('Source folder not found for zipping.'); exit(1); } if (file_exists($destination)) { unlink($destination); } $zip = new ZipArchive(); if (!$zip->open($destination, ZIPARCHIVE::CREATE)) { CLI::error('Unknown error opening zip file.'); exit(1); } $source = str_replace('\\', '/', realpath($source)); if (is_dir($source) === true) { $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); if ($include_dir) { $arr = explode("/", $source); $maindir = $arr[count($arr) - 1]; $source = ""; for ($i = 0; $i < count($arr) - 1; $i++) { $source .= '/' . $arr[$i]; } $source = substr($source, 1); $zip->addEmptyDir($maindir); } foreach ($files as $file) { $file = str_replace('\\', '/', $file); // Ignore "." and ".." folders if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..', '.DS_Store'))) { continue; } $file = realpath($file); if (is_dir($file) === true) { $zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); } else { if (is_file($file) === true) { $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file)); } } } } else { if (is_file($source) === true) { $zip->addFromString(basename($source), file_get_contents($source)); } } return $zip->close(); }
<?php defined('BASEPATH') or exit('No direct script access allowed'); ?> <?php echo \Myth\CLI::error("\n\tAn uncaught Exception was encountered"); ?> <?php echo \Myth\CLI::write("\\Type: {get_class({$exception})}"); echo \Myth\CLI::write("\\Message: {$message}"); echo \Myth\CLI::write("\\Filename: {$exception->getFile()}"); echo \Myth\CLI::write("\\ine Number: {$exception->getLine()}"); ?> <?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE) { echo \Myth\CLI::write("\n\tBacktrace"); foreach ($exception->getTrace() 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();
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"; $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');
<?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'); echo \Myth\CLI::error("\n\tDatabase Error: {$heading}"); echo \Myth\CLI::write("{$message}\n");
<?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();
public function longDescribeMethod($method = null) { if (empty($this->long_descriptions[$method])) { return CLI::error(lang('cli.no_help')); } CLI::write("\t{$this->long_descriptions[$method]}", 'yellow'); }
private function makeMigration($tpl, $name) { // Create the migration $this->load->library('migration'); $destination = $this->migration->determine_migration_path('app', true); $file = $this->migration->make_name($name); $destination = rtrim($destination, '/') . '/' . $file; if (!$this->copyTemplate($tpl, $destination, [], true)) { CLI::error('Error creating migration file.'); } $this->setAuthType('digest'); }