本文整理匯總了PHP中Minion_CLI::color方法的典型用法代碼示例。如果您正苦於以下問題:PHP Minion_CLI::color方法的具體用法?PHP Minion_CLI::color怎麽用?PHP Minion_CLI::color使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Minion_CLI
的用法示例。
在下文中一共展示了Minion_CLI::color方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: modify_file
public static function modify_file($file, $content, $force = FALSE, $unlink = FALSE)
{
if ($unlink) {
$file_already_exists = is_file($file);
if ($file_already_exists) {
unlink($file);
Minion_CLI::write(Minion_CLI::color('Removed file ' . Debug::path($file), 'light_green'));
} else {
Minion_CLI::write(Minion_CLI::color('File does not exist ' . Debug::path($file), 'brown'));
}
} elseif ($force) {
$file_already_exists = is_file($file);
if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, TRUE);
}
file_put_contents($file, $content);
if ($file_already_exists) {
Minion_CLI::write(Minion_CLI::color('Overwritten file ' . Debug::path($file), 'brown'));
} else {
Minion_CLI::write(Minion_CLI::color('Generated file ' . Debug::path($file), 'light_green'));
}
} else {
if (is_file($file)) {
Minion_CLI::write(Minion_CLI::color('File already exists ' . Debug::path($file), 'brown'));
} else {
if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, TRUE);
}
file_put_contents($file, $content);
Minion_CLI::write(Minion_CLI::color('Generated file ' . Debug::path($file), 'light_green'));
}
}
}
示例2: _execute
/**
* Task to run pending migrations
*
* @return null
*/
protected function _execute(array $params)
{
$migrations = new MigrationManager();
Database::$default = $params['db'];
$this->db = Database::instance();
$db_config = Kohana::$config->load('database')->{$params['db']};
if (!ORM::factory('Migration')->is_installed()) {
/**
* Get platform from database config
*/
$platform = strtolower($db_config['type']);
if ('mysqli' == $platform) {
$platform = 'mysql';
}
/**
* Get SQL from file for selected platform
*/
$file = realpath(substr(__DIR__, 0, strlen(__DIR__) - strlen('classes/Task/Db')) . 'sql/' . $platform . '.sql');
$handle = fopen($file, 'rb');
$sql_create = fread($handle, filesize($file));
$this->db->query(0, $sql_create);
$msg = Minion_CLI::color("-----------------------------\n", 'green');
$msg .= Minion_CLI::color("| Migration table create!!! |\n", 'green');
$msg .= Minion_CLI::color("-----------------------------\n", 'green');
Minion_CLI::write($msg);
}
$migrations->migrate($params['db'], $params['step']);
}
示例3: _execute
protected function _execute(array $params)
{
$model = $params['model'];
$orm = ORM::factory($model);
$orm->send_search_mapping();
Minion_CLI::write('Search mapping for model ' . Minion_CLI::color($model, 'blue') . ' updated!');
}
示例4: _execute
protected function _execute(array $options)
{
$db = $this->db_params($options['database']);
$file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path") . DIRECTORY_SEPARATOR . 'schema.sql';
$command = strtr("mysqldump -u:username :password -h :hostname --skip-comments --add-drop-database --add-drop-table --no-data :database | sed 's/AUTO_INCREMENT=[0-9]*\\b//' > :file ", array(':username' => $db['username'], ':password' => $db['password'] ? '-p' . $db['password'] : '', ':database' => $db['database'], ':hostname' => $db['hostname'], ':file' => $file));
Minion_CLI::write(Minion_CLI::color('Saving structure of database "' . $db['database'] . '" to ' . Debug::path($file), 'green'));
system($command);
}
示例5: _execute
protected function _execute(array $options)
{
$db = $this->db_params($options['database']);
$file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path") . DIRECTORY_SEPARATOR . 'schema.sql';
if ($options['force'] === NULL or 'yes' === Minion_CLI::read("This will destroy database " . $db['database'] . " Are you sure? [yes/NO]")) {
$command = strtr("mysql -u:username :password -h :hostname :database < :file ", array(':username' => $db['username'], ':password' => $db['password'] ? '-p' . $db['password'] : '', ':database' => $db['database'], ':hostname' => $db['hostname'], ':file' => $file));
Minion_CLI::write(Minion_CLI::color('Loading data from ' . Debug::path($file) . ' to ' . $db['database'], 'green'));
system($command);
} else {
Minion_CLI::write(Minion_CLI::color('Nothing done', 'brown'));
}
}
示例6: _execute
protected function _execute(array $options)
{
if ($options['force'] === NULL or 'yes' === Minion_CLI::read('This will destroy all data in the current database. Are you sure? [yes/NO]')) {
Minion_CLI::write('Dropping Tables', 'green');
$migrations = new Migrations(array('log' => 'Minion_CLI::write'));
$migrations->clear_all();
$options['task'] = 'db:migrate';
Minion_Task::factory($options)->execute();
} else {
Minion_CLI::write(Minion_CLI::color('Nothing done', 'brown'));
}
}
示例7: _execute
/**
* Execute the task and copy the required files
*
* @param array $params the command options
*
* @return void
*/
protected function _execute(array $params)
{
// Identify the vendor and destination path
$vendor_path = $params['vendor-path'];
$public_path = $params['public-path'];
// Publish the twitter bootstrap js at DOCROOT/assets/js/twbs
$this->copy_files($vendor_path . '/twbs/bootstrap/js', '/\\.js$/', $public_path . '/js/twbs');
Minion_CLI::write(Minion_CLI::color('Published bootstrap javascripts to ' . $public_path . '/js/twbs', 'green'));
// Publish the font-awesome font files as DOCROOT/assets/font
$this->copy_files($vendor_path . '/fortawesome/font-awesome/font', '/^fontawesome/i', $public_path . '/font');
Minion_CLI::write(Minion_CLI::color('Published font-awesome font to ' . $public_path . '/font', 'green'));
}
示例8: _resource
private function _resource(Resource $resource, array $route_params, $is_parent = FALSE)
{
$resource->param($route_params);
$output = '';
if (isset($route_params['id'])) {
$output = (string) $resource->object();
} elseif ($resource->option('singular')) {
if ($model = $resource->option('model')) {
$output = 'Singular model: ' . Minion_CLI::color(Jam::class_name($model), 'light_red');
}
} else {
$output = 'Collection of: ' . Minion_CLI::color(Jam::class_name($resource->option('model')), 'light_red');
}
if ($is_parent) {
$output = 'Parent: ' . $output;
}
Minion_CLI::write($output);
}
示例9: _execute
protected function _execute(array $params)
{
$model = $params['model'];
$limit = $params['limit'];
$times = $params['times'];
$offset = $params['offset'];
$elasticsearch = ElasticSearch::instance();
$orm = ORM::factory($model);
$type = $orm->_search_type();
$total = $orm->count_all();
// Write the header
Minion_CLI::write('#########################################' . str_repeat('#', strlen($model)) . '##');
Minion_CLI::write('# Bulk updating search indexes in model: ' . Minion_CLI::color($model, 'blue') . ' #');
Minion_CLI::write('#########################################' . str_repeat('#', strlen($model)) . '##');
Minion_CLI::write();
Minion_CLI::write('Importing ' . $limit . ' items at a time, beginning at offset ' . $offset . ', ' . $times . ' times');
Minion_CLI::write();
while ($times !== 0) {
$results = ORM::factory($model)->limit($limit)->offset($offset)->find_all();
// Break the loop if there are no more results in the database.
if ($results->count() <= 0) {
break;
}
$documents = array();
foreach ($results as $result) {
$documents[] = $result->get_search_document();
}
$elasticsearch->add_documents($type, $documents);
$current = $offset + $results->count();
Minion_CLI::write('Imported: ' . $current . '/' . $total);
$offset += $limit;
$times -= 1;
}
// Write the footer
Minion_CLI::write();
Minion_CLI::write('##########################');
Minion_CLI::write('# Bulk update completed! #');
Minion_CLI::write('##########################');
}
示例10: _method
private function _method($method)
{
return Minion_CLI::color(str_pad(implode(', ', array_map('strtoupper', (array) $method)), 20, ' ', STR_PAD_RIGHT), 'purple');
}
示例11: rollback
/**
* Rollback last executed migration.
*
*/
public function rollback($group = 'default', $step = 1)
{
Database::$default = $group;
//Get last executed migration
if (strtolower($step) === 'all') {
$migrations = ORM::factory('Migration')->order_by('hash', 'DESC')->find_all();
} else {
$migrations = ORM::factory('Migration')->order_by('hash', 'DESC')->limit((int) $step)->find_all();
}
if (!count($migrations)) {
$this->message("There's no migration to rollback");
return;
}
$total_time = 0;
foreach ($migrations as $key => $item) {
$msg = "Migration '" . $item->name . "' with hash: " . $item->hash . ' was succefully "rollbacked"';
$this->message($msg);
$interval = microtime(true);
try {
$migration_object = $this->load_migration($item->hash, $group);
$migration_object->down();
$interval = microtime(true) - $interval;
$total_time += $interval;
$this->message(Minion_CLI::color("----------- with {$interval} s -----------\n", 'green'));
$item->delete();
} catch (Exception $e) {
$this->message_error($e->getMessage());
break;
}
}
$this->message(Minion_CLI::color("\n----------- TOTAL TIME IS {$total_time} s -----------", 'green'));
}
示例12: execute
public function execute(array $options)
{
$migrations = new Migrations(array('log' => 'Minion_CLI::write'));
$migration = $migrations->generate_new_migration_file($options['name'], $options['template']);
Minion_CLI::write(Minion_CLI::color($migration, 'green') . Minion_CLI::color(' Migration File Generated', 'brown'));
}
示例13: write_replace
/**
* Outputs a string to the cli, replacing the previous line.
*
* @param string|array $text the text to output, or array of lines
*/
public static function write_replace($text = '', $foreground = null, $background = null)
{
if ($foreground or $background) {
$text = Minion_CLI::color($text, $foreground, $background);
}
fwrite(STDOUT, "\r[K" . $text);
}
示例14: _execute
/**
* Execute the task and compile the LESS files
*
* @param array $params the passed command options
*
* @throws Exception
* @return void
*/
protected function _execute(array $params)
{
// Prepare the options for recess
$recess_opts = array();
// Create the list of valid assets/less paths found in the CFS and format them as recess arguments
$paths = Kohana::include_paths();
foreach ($paths as $path) {
$path .= 'assets/less';
if (file_exists($path)) {
$recess_opts[] = '--includePath ' . escapeshellarg($path);
}
}
// Add paths for fontawesome and twitter bootstrap
// Note that these are deliberately set at organisation level to namespace the less files below
$recess_opts[] = '--includePath ' . escapeshellarg(realpath($params['vendor-path'] . '/fortawesome'));
$recess_opts[] = '--includePath ' . escapeshellarg(realpath($params['vendor-path'] . '/twbs'));
// Determine whether to lint or compile, and whether the output should be compressed
if ($params['lint-only']) {
$output = '';
} else {
$recess_opts[] = '--compile';
// Find the path for the output file
$output = ' > ' . escapeshellarg($params['public-path'] . '/css/' . $params['css-output'] . '.css');
if (!$params['no-compress']) {
$recess_opts[] = '--compress';
}
}
// Find the input file to use
$input = Kohana::find_file('assets/less', $params['less-input'], 'less');
if (!$input) {
throw new Exception("Could not find a valid input file source for {$params['less-input']}");
}
// Build and log the recess command
$command = 'recess ' . implode(' ', $recess_opts) . ' ' . escapeshellarg($input) . $output;
Minion_CLI::write(Minion_CLI::color('Preparing to execute recess with following command', 'green'));
Minion_CLI::write(Minion_CLI::color('> ' . $command, 'green'));
$loop = $params['loop-after'] > 0;
do {
Minion_CLI::write(Minion_CLI::color('Building CSS', 'light_gray'));
// Execute and check the result
system($command, $exit_code);
if ($exit_code != 0) {
throw new Exception("Command '" . $command . '" failed with exit code ' . $exit_code);
}
Minion_CLI::write(Minion_CLI::color('Compiled ' . $input . ' to ' . $output, 'green'));
if ($loop) {
sleep($params['loop-after']);
}
} while ($loop);
}
示例15: foreach
$level = -1;
foreach (Debug::trace($trace) as $i => $step) {
$level++;
$file = $step['file'] ? Debug::path($step['file']) . '[' . $step['line'] . ']' : '{PHP internal call}';
echo Minion_CLI::color(str_pad("#" . $level, 3), 'black', 'yellow') . " " . Minion_CLI::color($step['function'], 'yellow') . " - " . Minion_CLI::color($file, 'cyan') . \PHP_EOL;
if (!$step['args']) {
continue;
}
$max_name_len = max(array_map(function ($key) {
return strlen($key);
}, array_keys($step['args'])));
$indent = str_repeat(" ", $max_name_len + 5);
$wrap_at = $cols - strlen($indent);
foreach ($step['args'] as $name => $arg) {
$name = str_pad(is_numeric($name) ? "#" . $name : "\$" . $name, $max_name_len + 1);
echo " " . Minion_CLI::color($name, 'purple') . " ";
// FATAL have already converted args to strings
$arg = $code === 'Fatal Error' ? $arg : html_entity_decode(strip_tags(Debug::dump($arg)), ENT_QUOTES, 'UTF-8');
$arg = explode(\PHP_EOL, wordwrap($arg, $wrap_at, \PHP_EOL, TRUE));
// Don't allow ridiculously long output if the method took a lot of args or a big array
if (count($arg) > 20) {
$truncated_count = count($arg) - 20;
$arg = array_slice($arg, 0, 20);
$arg[] = '<<<--- ' . $truncated_count . ' lines truncated --->>>';
}
$arg = implode(\PHP_EOL . $indent, $arg);
echo $arg . \PHP_EOL;
}
if ($level >= 5) {
break;
}