Esempio n. 1
0
 public function run($segments = [], $quiet = false)
 {
     $name = array_shift($segments);
     // If a table already exists then we don't need a migration
     $this->load->database();
     if ($this->db->table_exists($name)) {
         $this->table_exists = true;
     }
     // If we didn't attach any fields, then we
     // need to generate the barebones here.
     $this->fields = CLI::option('fields');
     // If we don't have any fields, and no model
     // exists, then we need to provide some default fields.
     if (empty($this->fields)) {
         if (!$this->table_exists) {
             $this->fields = "id:int id:id title:string created_on:datetime modified_on:datetime";
         }
     }
     // Perform the steps.
     if (!$this->table_exists) {
         $this->makeMigration($name);
     }
     $this->makeSeed($name);
     $this->makeModel($name);
     $this->makeController($name);
     $this->readme();
 }
Esempio n. 2
0
 /**
  * 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();
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 /**
  * 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'));
 }
Esempio n. 5
0
 /**
  * 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');
 }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
 /**
  * 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');
 }
Esempio n. 8
0
 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;
         }
     }
 }
Esempio n. 9
0
 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);
     }
 }
Esempio n. 10
0
    $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');
Esempio n. 11
0
 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);
     }
 }
Esempio n. 12
0
    /**
     * 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');
    }
Esempio n. 13
0
 /**
  * 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);
     }
 }
Esempio n. 14
0
 /**
  * Grabs the fields from the CLI options and gets them ready for
  * use within the views.
  */
 protected function prepareFields()
 {
     $fields = CLI::option('fields');
     if (empty($fields)) {
         // If we have a model, we can get our fields from there
         if (!empty($this->options['model'])) {
             $fields = $this->getFieldsFromModel($this->options['model']);
             if (empty($fields)) {
                 return NULL;
             }
         } else {
             return NULL;
         }
     }
     $fields = explode(' ', $fields);
     $new_fields = [];
     foreach ($fields as $field) {
         $pop = [NULL, NULL, NULL];
         list($field, $type, $size) = array_merge(explode(':', $field), $pop);
         $type = strtolower($type);
         // Ignore list
         if (in_array($field, ['created_on', 'modified_on'])) {
             continue;
         }
         // Strings
         if (in_array($type, ['char', 'varchar', 'string'])) {
             $new_fields[] = ['name' => $field, 'type' => 'text'];
         } else {
             if ($type == 'text') {
                 $new_fields[] = ['name' => $field, 'type' => 'textarea'];
             } else {
                 if (in_array($type, ['tinyint', 'int', 'bigint', 'mediumint', 'float', 'double', 'number'])) {
                     $new_fields[] = ['name' => $field, 'type' => 'number'];
                 } else {
                     if (in_array($type, ['date', 'datetime', 'time'])) {
                         $new_fields[] = ['name' => $field, 'type' => $type];
                     }
                 }
             }
         }
     }
     return $new_fields;
 }
Esempio n. 15
0
 /**
  * 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;
 }
Esempio n. 16
0
<?php

defined('BASEPATH') or exit('No direct script access allowed');
echo \Myth\CLI::error("\n\t{$heading}");
echo \Myth\CLI::write("{$message}\n");
Esempio n. 17
0
 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();
 }
Esempio n. 18
0
 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');
 }
Esempio n. 19
0
<?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();
Esempio n. 20
0
<?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());