public function testRedOnWhite() { $s = CommandLineColor::red_on_white('This is my red string'); `echo "{$s}"`; }
public static function echo_operation($op) { if (defined("NIMBLE_IS_TESTING")) { return; } echo CommandLineColor::underline_white('Generating:') . ' ' . CommandLineColor::red($op) . "\n"; }
/** * Migrates the database down to the version specified if no version is given it migrates to version 0 * @param string $to_version */ public static function down($to_version = 0) { $current = static::current_version(); $table = static::migration_table_name(); $data = static::load_files(static::$dir); $data = array_reverse($data, true); foreach ($data as $version => $class) { if ((int) $version < (int) $to_version) { continue; } if ((int) $current < (int) $version) { continue; } print CommandLineColor::underline('Running') . " " . CommandLineColor::underline_blue($class) . " - " . CommandLineColor::yellow($version) . "\n"; $klass = new $class(); $klass->down(); static::delete_version($version); } }
#! /usr/bin/env php <?php require_once dirname(__FILE__) . '/../command_line_color.php'; $s = CommandLineColor::bold_red_on_white('This is my red string'); echo $s; echo "\n"; echo CommandLineColor::underline_white_on_red('WHOA!');
/** * Method execute_query * use self::execute_query('SELECT * FROM `foo` WHERE `foo`.id = 1', false) * @param sql String * @param all Boolean - true = multiresults | false = single result */ public static function execute_query($sql, $all = true, $cache = true) { //fetch query cache if it exsists if ($cache && static::is_query_cached($sql)) { NimbleLogger::log(CommandLineColor::underline_red('CACHED:') . $sql); return static::fetch_query_data_from_cache($sql); } else { //execute query and set cache pointer $result = static::execute($sql); $key = ''; if ($cache) { $key = static::generate_hash_key($sql); } $return = $all ? static::to_objects($result, $key) : static::to_object(static::class_name(), $result->fetch_assoc()); if ($cache && $result->num_rows() <= static::$max_rows_for_cache) { static::cache($sql, $return); } if ($result) { $result->free(); } return $return; } }
/** * Dump out application routes to a human readable format. * @param boolean $cli True if being called from the command line. * @return string The application's routes in a human readable format. */ public static function dumpRoutes($cli = false) { $klass = Nimble::getInstance(); $out = array(); foreach ($klass->routes as $route) { $pattern = self::clean_route($route->rule); $pattern = empty($pattern) ? 'root path' : $pattern; $string = ''; if (!empty($route->short_url)) { $string .= ' ' . CommandLineColor::underline('Short Url:') . ' ' . CommandLineColor::yellow($route->short_url) . ' '; } $string .= CommandLineColor::underline("Controller:") . ' ' . CommandLineColor::yellow($route->controller) . ' ' . CommandLineColor::underline('Action:') . ' ' . CommandLineColor::magenta($route->method) . ' ' . CommandLineColor::underline('Method:') . ' ' . CommandLineColor::green($route->http_method) . ' ' . CommandLineColor::underline('Pattern:') . ' ' . CommandLineColor::bold_red($pattern); array_push($out, $string); } $return = "\n"; $return .= join("\n", $out); $return .= "\n"; return $cli ? $return : htmlspecialchars($return); }