Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace yii\helpers; use Yii; use yii\console\Markdown as ConsoleMarkdown; use yi..

Decoded Output download

<?php
 namespace yii\helpers; use Yii; use yii\console\Markdown as ConsoleMarkdown; use yii\base\Model; class BaseConsole { const FG_BLACK = 30; const FG_RED = 31; const FG_GREEN = 32; const FG_YELLOW = 33; const FG_BLUE = 34; const FG_PURPLE = 35; const FG_CYAN = 36; const FG_GREY = 37; const BG_BLACK = 40; const BG_RED = 41; const BG_GREEN = 42; const BG_YELLOW = 43; const BG_BLUE = 44; const BG_PURPLE = 45; const BG_CYAN = 46; const BG_GREY = 47; const RESET = 0; const NORMAL = 0; const BOLD = 1; const ITALIC = 3; const UNDERLINE = 4; const BLINK = 5; const NEGATIVE = 7; const CONCEALED = 8; const CROSSED_OUT = 9; const FRAMED = 51; const ENCIRCLED = 52; const OVERLINED = 53; public static function moveCursorUp($rows = 1) { echo "\x1b[" . (int) $rows . "A"; } public static function moveCursorDown($rows = 1) { echo "\33[" . (int) $rows . "B"; } public static function moveCursorForward($steps = 1) { echo "\33[" . (int) $steps . "C"; } public static function moveCursorBackward($steps = 1) { echo "\33[" . (int) $steps . "D"; } public static function moveCursorNextLine($lines = 1) { echo "\x1b[" . (int) $lines . "E"; } public static function moveCursorPrevLine($lines = 1) { echo "\33[" . (int) $lines . "F"; } public static function moveCursorTo($column, $row = null) { if ($row === null) { echo "\x1b[" . (int) $column . "G"; } else { echo "\33[" . (int) $row . ";" . (int) $column . "H"; } } public static function scrollUp($lines = 1) { echo "\33[" . (int) $lines . "S"; } public static function scrollDown($lines = 1) { echo "\33[" . (int) $lines . "T"; } public static function saveCursorPosition() { echo "\33[s"; } public static function restoreCursorPosition() { echo "\x1b[u"; } public static function hideCursor() { echo "\33[?25l"; } public static function showCursor() { echo "\x1b[?25h"; } public static function clearScreen() { echo "\33[2J"; } public static function clearScreenBeforeCursor() { echo "\33[1J"; } public static function clearScreenAfterCursor() { echo "\33[0J"; } public static function clearLine() { echo "\33[2K"; } public static function clearLineBeforeCursor() { echo "\33[1K"; } public static function clearLineAfterCursor() { echo "\x1b[0K"; } public static function ansiFormatCode($format) { return "\x1b[" . implode(";", $format) . "m"; } public static function beginAnsiFormat($format) { echo "\33[" . implode(";", $format) . "m"; } public static function endAnsiFormat() { echo "\33[0m"; } public static function ansiFormat($string, $format = array()) { $code = implode(";", $format); return "\33[0m" . ($code !== '' ? "\33[" . $code . "m" : '') . $string . "\x1b[0m"; } public static function xtermFgColor($colorCode) { return "38;5;" . $colorCode; } public static function xtermBgColor($colorCode) { return "48;5;" . $colorCode; } public static function stripAnsiFormat($string) { return preg_replace(self::ansiCodesPattern(), '', (string) $string); } public static function ansiStrlen($string) { return mb_strlen(static::stripAnsiFormat($string)); } public static function ansiStrwidth($string) { return mb_strwidth(static::stripAnsiFormat($string), Yii::$app->charset); } public static function ansiColorizedSubstr($string, $start, $length) { if ($start < 0 || $length <= 0) { return ''; } $textItems = preg_split(self::ansiCodesPattern(), (string) $string); preg_match_all(self::ansiCodesPattern(), (string) $string, $colors); $colors = count($colors) ? $colors[0] : array(); array_unshift($colors, ''); $result = ''; $curPos = 0; $inRange = false; foreach ($textItems as $k => $textItem) { $color = $colors[$k]; if ($curPos <= $start && $start < $curPos + Console::ansiStrwidth($textItem)) { $text = mb_substr($textItem, $start - $curPos, null, Yii::$app->charset); $inRange = true; } else { $text = $textItem; } if ($inRange) { $result .= $color . $text; $diff = $length - Console::ansiStrwidth($result); if ($diff <= 0) { if ($diff < 0) { $result = mb_substr($result, 0, $diff, Yii::$app->charset); } $defaultColor = static::renderColoredString("%n"); if ($color && $color != $defaultColor) { $result .= $defaultColor; } break; } } $curPos += mb_strlen($textItem, Yii::$app->charset); } return $result; } private static function ansiCodesPattern() { return "/\033\[[\d;?]*\w/"; } public static function ansiToHtml($string, $styleMap = array()) { $styleMap = array(self::FG_BLACK => array("color" => "black"), self::FG_BLUE => array("color" => "blue"), self::FG_CYAN => array("color" => "aqua"), self::FG_GREEN => array("color" => "lime"), self::FG_GREY => array("color" => "silver"), self::FG_PURPLE => array("color" => "rebeccapurple"), self::FG_RED => array("color" => "red"), self::FG_YELLOW => array("color" => "yellow"), self::BG_BLACK => array("background-color" => "black"), self::BG_BLUE => array("background-color" => "blue"), self::BG_CYAN => array("background-color" => "aqua"), self::BG_GREEN => array("background-color" => "lime"), self::BG_GREY => array("background-color" => "silver"), self::BG_PURPLE => array("background-color" => "rebeccapurple"), self::BG_RED => array("background-color" => "red"), self::BG_YELLOW => array("background-color" => "yellow"), self::BOLD => array("font-weight" => "bold"), self::ITALIC => array("font-style" => "italic"), self::UNDERLINE => array("text-decoration" => array("underline")), self::OVERLINED => array("text-decoration" => array("overline")), self::CROSSED_OUT => array("text-decoration" => array("line-through")), self::BLINK => array("text-decoration" => array("blink")), self::CONCEALED => array("visibility" => "hidden")) + $styleMap; $tags = 0; $result = preg_replace_callback("/\033\[([\d;]+)m/", function ($ansi) use(&$tags, $styleMap) { $style = array(); $reset = false; $negative = false; foreach (explode(";", $ansi[1]) as $controlCode) { if ($controlCode == 0) { $style = array(); $reset = true; } elseif ($controlCode == self::NEGATIVE) { $negative = true; } elseif (isset($styleMap[$controlCode])) { $style[] = $styleMap[$controlCode]; } } $return = ''; while ($reset && $tags > 0) { $return .= "</span>"; $tags--; } if (empty($style)) { return $return; } $currentStyle = array(); foreach ($style as $content) { $currentStyle = ArrayHelper::merge($currentStyle, $content); } if ($negative) { if (isset($currentStyle["color"])) { $fgColor = $currentStyle["color"]; unset($currentStyle["color"]); } if (isset($currentStyle["background-color"])) { $bgColor = $currentStyle["background-color"]; unset($currentStyle["background-color"]); } if (isset($fgColor)) { $currentStyle["background-color"] = $fgColor; } if (isset($bgColor)) { $currentStyle["color"] = $bgColor; } } $styleString = ''; foreach ($currentStyle as $name => $value) { if (is_array($value)) { $value = implode(" ", $value); } $styleString .= "{$name}: {$value};"; } $tags++; return "{$return}<span style="{$styleString}">"; }, $string); while ($tags > 0) { $result .= "</span>"; $tags--; } return $result; } public static function markdownToAnsi($markdown) { $parser = new ConsoleMarkdown(); return $parser->parse($markdown); } public static function renderColoredString($string, $colored = true) { static $conversions = array("%y" => array(self::FG_YELLOW), "%g" => array(self::FG_GREEN), "%b" => array(self::FG_BLUE), "%r" => array(self::FG_RED), "%p" => array(self::FG_PURPLE), "%m" => array(self::FG_PURPLE), "%c" => array(self::FG_CYAN), "%w" => array(self::FG_GREY), "%k" => array(self::FG_BLACK), "%n" => array(0), "%Y" => array(self::FG_YELLOW, self::BOLD), "%G" => array(self::FG_GREEN, self::BOLD), "%B" => array(self::FG_BLUE, self::BOLD), "%R" => array(self::FG_RED, self::BOLD), "%P" => array(self::FG_PURPLE, self::BOLD), "%M" => array(self::FG_PURPLE, self::BOLD), "%C" => array(self::FG_CYAN, self::BOLD), "%W" => array(self::FG_GREY, self::BOLD), "%K" => array(self::FG_BLACK, self::BOLD), "%N" => array(0, self::BOLD), "%3" => array(self::BG_YELLOW), "%2" => array(self::BG_GREEN), "%4" => array(self::BG_BLUE), "%1" => array(self::BG_RED), "%5" => array(self::BG_PURPLE), "%6" => array(self::BG_CYAN), "%7" => array(self::BG_GREY), "%0" => array(self::BG_BLACK), "%F" => array(self::BLINK), "%U" => array(self::UNDERLINE), "%8" => array(self::NEGATIVE), "%9" => array(self::BOLD), "%_" => array(self::BOLD)); if ($colored) { $string = str_replace("%%", "% ", $string); foreach ($conversions as $key => $value) { $string = str_replace($key, static::ansiFormatCode($value), $string); } $string = str_replace("% ", "%", $string); } else { $string = preg_replace("/%((%)|.)/", "$2", $string); } return $string; } public static function escape($string) { return str_replace("%", "%%", $string); } public static function streamSupportsAnsiColors($stream) { return DIRECTORY_SEPARATOR === "\" ? getenv("ANSICON") !== false || getenv("ConEmuANSI") === "ON" : function_exists("posix_isatty") && @posix_isatty($stream); } public static function isRunningOnWindows() { return DIRECTORY_SEPARATOR === "\"; } public static function getScreenSize($refresh = false) { static $size; static $execDisabled; if ($size !== null && ($execDisabled || !$refresh)) { return $size; } if ($execDisabled === null) { $execDisabled = !function_exists("ini_get") || preg_match("/(\bexec\b)/i", ini_get("disable_functions")); if ($execDisabled) { return $size = false; } } if (static::isRunningOnWindows()) { $output = array(); exec("mode con", $output); if (isset($output[1]) && strpos($output[1], "CON") !== false) { return $size = array((int) preg_replace("~\D~", '', $output[4]), (int) preg_replace("~\D~", '', $output[3])); } } else { $stty = array(); if (exec("stty -a 2>&1", $stty)) { $stty = implode(" ", $stty); if (preg_match("/rows\s+(\d+);\s*columns\s+(\d+);/mi", $stty, $matches)) { return $size = array((int) $matches[2], (int) $matches[1]); } if (preg_match("/(\d+)\s+rows;\s*(\d+)\s+columns;/mi", $stty, $matches)) { return $size = array((int) $matches[2], (int) $matches[1]); } } if (($width = (int) exec("tput cols 2>&1")) > 0 && ($height = (int) exec("tput lines 2>&1")) > 0) { return $size = array($width, $height); } if (($width = (int) getenv("COLUMNS")) > 0 && ($height = (int) getenv("LINES")) > 0) { return $size = array($width, $height); } } return $size = false; } public static function wrapText($text, $indent = 0, $refresh = false) { $size = static::getScreenSize($refresh); if ($size === false || $size[0] <= $indent) { return $text; } $pad = str_repeat(" ", $indent); $lines = explode("\xa", wordwrap($text, $size[0] - $indent, "
")); $first = true; foreach ($lines as $i => $line) { if ($first) { $first = false; continue; } $lines[$i] = $pad . $line; } return implode("
", $lines); } public static function stdin($raw = false) { return $raw ? fgets(\STDIN) : rtrim(fgets(\STDIN), PHP_EOL); } public static function stdout($string) { return fwrite(\STDOUT, $string); } public static function stderr($string) { return fwrite(\STDERR, $string); } public static function input($prompt = null) { if (isset($prompt)) { static::stdout($prompt); } return static::stdin(); } public static function output($string = null) { return static::stdout($string . PHP_EOL); } public static function error($string = null) { return static::stderr($string . PHP_EOL); } public static function prompt($text, $options = array()) { $options = ArrayHelper::merge(array("required" => false, "default" => null, "pattern" => null, "validator" => null, "error" => "Invalid input."), $options); $error = null; top: $input = $options["default"] ? static::input("{$text} [" . $options["default"] . "] ") : static::input("{$text} "); if ($input === '') { if (isset($options["default"])) { $input = $options["default"]; } elseif ($options["required"]) { static::output($options["error"]); goto top; } } elseif ($options["pattern"] && !preg_match($options["pattern"], $input)) { static::output($options["error"]); goto top; } elseif ($options["validator"] && !call_user_func_array($options["validator"], array($input, &$error))) { static::output(isset($error) ? $error : $options["error"]); goto top; } return $input; } public static function confirm($message, $default = false) { while (true) { static::stdout($message . " (yes|no) [" . ($default ? "yes" : "no") . "]:"); $input = trim(static::stdin()); if (empty($input)) { return $default; } if (!strcasecmp($input, "y") || !strcasecmp($input, "yes")) { return true; } if (!strcasecmp($input, "n") || !strcasecmp($input, "no")) { return false; } } } public static function select($prompt, $options = array(), $default = null) { top: static::stdout("{$prompt} (" . implode(",", array_keys($options)) . ",?)" . ($default !== null ? "[" . $default . "]" : '') . ": "); $input = static::stdin(); if ($input === "?") { foreach ($options as $key => $value) { static::output(" {$key} - {$value}"); } static::output(" ? - Show help"); goto top; } elseif ($default !== null && $input === '') { return $default; } elseif (!array_key_exists($input, $options)) { goto top; } return $input; } private static $_progressStart; private static $_progressWidth; private static $_progressPrefix; private static $_progressEta; private static $_progressEtaLastDone = 0; private static $_progressEtaLastUpdate; public static function startProgress($done, $total, $prefix = '', $width = null) { self::$_progressStart = time(); self::$_progressWidth = $width; self::$_progressPrefix = $prefix; self::$_progressEta = null; self::$_progressEtaLastDone = 0; self::$_progressEtaLastUpdate = time(); static::updateProgress($done, $total); } public static function updateProgress($done, $total, $prefix = null) { if ($prefix === null) { $prefix = self::$_progressPrefix; } else { self::$_progressPrefix = $prefix; } $width = static::getProgressbarWidth($prefix); $percent = $total == 0 ? 1 : $done / $total; $info = sprintf("%d%% (%d/%d)", $percent * 100, $done, $total); self::setETA($done, $total); $info .= self::$_progressEta === null ? " ETA: n/a" : sprintf(" ETA: %d sec.", self::$_progressEta); $extraChars = static::isRunningOnWindows() ? 4 : 3; $width -= $extraChars + static::ansiStrlen($info); if ($width < 5) { static::stdout("
{$prefix}{$info}   "); } else { if ($percent < 0) { $percent = 0; } elseif ($percent > 1) { $percent = 1; } $bar = floor($percent * $width); $status = str_repeat("=", $bar); if ($bar < $width) { $status .= ">"; $status .= str_repeat(" ", $width - $bar - 1); } static::stdout("\xd{$prefix}" . "[{$status}] {$info}"); } flush(); } private static function getProgressbarWidth($prefix) { $width = self::$_progressWidth; if ($width === false) { return 0; } $screenSize = static::getScreenSize(true); if ($screenSize === false && $width < 1) { return 0; } if ($width === null) { $width = $screenSize[0]; } elseif ($width > 0 && $width < 1) { $width = floor($screenSize[0] * $width); } $width -= static::ansiStrlen($prefix); return $width; } private static function setETA($done, $total) { if ($done > $total || $done == 0) { self::$_progressEta = null; self::$_progressEtaLastUpdate = time(); return; } if ($done < $total && (time() - self::$_progressEtaLastUpdate > 1 && $done > self::$_progressEtaLastDone)) { $rate = (time() - (self::$_progressEtaLastUpdate ?: self::$_progressStart)) / ($done - self::$_progressEtaLastDone); self::$_progressEta = $rate * ($total - $done); self::$_progressEtaLastUpdate = time(); self::$_progressEtaLastDone = $done; } } public static function endProgress($remove = false, $keepPrefix = true) { if ($remove === false) { static::stdout(PHP_EOL); } else { if (static::streamSupportsAnsiColors(STDOUT)) { static::clearLine(); } static::stdout("
" . ($keepPrefix ? self::$_progressPrefix : '') . (is_string($remove) ? $remove : '')); } flush(); self::$_progressStart = null; self::$_progressWidth = null; self::$_progressPrefix = ''; self::$_progressEta = null; self::$_progressEtaLastDone = 0; self::$_progressEtaLastUpdate = null; } public static function errorSummary($models, $options = array()) { $showAllErrors = ArrayHelper::remove($options, "showAllErrors", false); $lines = self::collectErrors($models, $showAllErrors); return implode(PHP_EOL, $lines); } private static function collectErrors($models, $showAllErrors) { $lines = array(); if (!is_array($models)) { $models = array($models); } foreach ($models as $model) { $lines = array_unique(array_merge($lines, $model->getErrorSummary($showAllErrors))); } return $lines; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace yii\helpers; use Yii; use yii\console\Markdown as ConsoleMarkdown; use yii\base\Model; class BaseConsole { const FG_BLACK = 30; const FG_RED = 31; const FG_GREEN = 32; const FG_YELLOW = 33; const FG_BLUE = 34; const FG_PURPLE = 35; const FG_CYAN = 36; const FG_GREY = 37; const BG_BLACK = 40; const BG_RED = 41; const BG_GREEN = 42; const BG_YELLOW = 43; const BG_BLUE = 44; const BG_PURPLE = 45; const BG_CYAN = 46; const BG_GREY = 47; const RESET = 0; const NORMAL = 0; const BOLD = 1; const ITALIC = 3; const UNDERLINE = 4; const BLINK = 5; const NEGATIVE = 7; const CONCEALED = 8; const CROSSED_OUT = 9; const FRAMED = 51; const ENCIRCLED = 52; const OVERLINED = 53; public static function moveCursorUp($rows = 1) { echo "\x1b\x5b" . (int) $rows . "\101"; } public static function moveCursorDown($rows = 1) { echo "\33\133" . (int) $rows . "\x42"; } public static function moveCursorForward($steps = 1) { echo "\33\x5b" . (int) $steps . "\103"; } public static function moveCursorBackward($steps = 1) { echo "\33\x5b" . (int) $steps . "\104"; } public static function moveCursorNextLine($lines = 1) { echo "\x1b\x5b" . (int) $lines . "\x45"; } public static function moveCursorPrevLine($lines = 1) { echo "\33\x5b" . (int) $lines . "\106"; } public static function moveCursorTo($column, $row = null) { if ($row === null) { echo "\x1b\133" . (int) $column . "\x47"; } else { echo "\33\133" . (int) $row . "\73" . (int) $column . "\x48"; } } public static function scrollUp($lines = 1) { echo "\33\x5b" . (int) $lines . "\x53"; } public static function scrollDown($lines = 1) { echo "\33\133" . (int) $lines . "\124"; } public static function saveCursorPosition() { echo "\33\x5b\163"; } public static function restoreCursorPosition() { echo "\x1b\x5b\x75"; } public static function hideCursor() { echo "\33\x5b\x3f\62\x35\x6c"; } public static function showCursor() { echo "\x1b\133\77\62\x35\x68"; } public static function clearScreen() { echo "\33\x5b\x32\x4a"; } public static function clearScreenBeforeCursor() { echo "\33\133\61\112"; } public static function clearScreenAfterCursor() { echo "\33\133\x30\112"; } public static function clearLine() { echo "\33\133\62\x4b"; } public static function clearLineBeforeCursor() { echo "\33\133\61\x4b"; } public static function clearLineAfterCursor() { echo "\x1b\x5b\x30\x4b"; } public static function ansiFormatCode($format) { return "\x1b\x5b" . implode("\73", $format) . "\155"; } public static function beginAnsiFormat($format) { echo "\33\x5b" . implode("\x3b", $format) . "\155"; } public static function endAnsiFormat() { echo "\33\x5b\x30\155"; } public static function ansiFormat($string, $format = array()) { $code = implode("\x3b", $format); return "\33\133\x30\155" . ($code !== '' ? "\33\x5b" . $code . "\155" : '') . $string . "\x1b\x5b\x30\x6d"; } public static function xtermFgColor($colorCode) { return "\63\x38\x3b\65\73" . $colorCode; } public static function xtermBgColor($colorCode) { return "\64\70\x3b\x35\x3b" . $colorCode; } public static function stripAnsiFormat($string) { return preg_replace(self::ansiCodesPattern(), '', (string) $string); } public static function ansiStrlen($string) { return mb_strlen(static::stripAnsiFormat($string)); } public static function ansiStrwidth($string) { return mb_strwidth(static::stripAnsiFormat($string), Yii::$app->charset); } public static function ansiColorizedSubstr($string, $start, $length) { if ($start < 0 || $length <= 0) { return ''; } $textItems = preg_split(self::ansiCodesPattern(), (string) $string); preg_match_all(self::ansiCodesPattern(), (string) $string, $colors); $colors = count($colors) ? $colors[0] : array(); array_unshift($colors, ''); $result = ''; $curPos = 0; $inRange = false; foreach ($textItems as $k => $textItem) { $color = $colors[$k]; if ($curPos <= $start && $start < $curPos + Console::ansiStrwidth($textItem)) { $text = mb_substr($textItem, $start - $curPos, null, Yii::$app->charset); $inRange = true; } else { $text = $textItem; } if ($inRange) { $result .= $color . $text; $diff = $length - Console::ansiStrwidth($result); if ($diff <= 0) { if ($diff < 0) { $result = mb_substr($result, 0, $diff, Yii::$app->charset); } $defaultColor = static::renderColoredString("\45\x6e"); if ($color && $color != $defaultColor) { $result .= $defaultColor; } break; } } $curPos += mb_strlen($textItem, Yii::$app->charset); } return $result; } private static function ansiCodesPattern() { return "\x2f\134\x30\63\63\x5c\133\133\134\x64\73\77\x5d\x2a\x5c\x77\x2f"; } public static function ansiToHtml($string, $styleMap = array()) { $styleMap = array(self::FG_BLACK => array("\x63\157\x6c\157\x72" => "\x62\x6c\141\143\153"), self::FG_BLUE => array("\143\x6f\x6c\x6f\162" => "\x62\154\x75\145"), self::FG_CYAN => array("\143\x6f\154\157\x72" => "\x61\161\165\x61"), self::FG_GREEN => array("\143\x6f\x6c\157\x72" => "\154\x69\x6d\145"), self::FG_GREY => array("\143\x6f\x6c\x6f\162" => "\x73\151\154\166\x65\162"), self::FG_PURPLE => array("\143\157\x6c\x6f\x72" => "\162\145\142\x65\143\143\x61\160\165\162\x70\x6c\145"), self::FG_RED => array("\143\157\154\x6f\162" => "\x72\x65\144"), self::FG_YELLOW => array("\143\157\x6c\x6f\x72" => "\x79\145\154\154\157\x77"), self::BG_BLACK => array("\x62\x61\143\153\x67\x72\x6f\165\156\144\55\x63\x6f\x6c\157\x72" => "\142\154\141\143\x6b"), self::BG_BLUE => array("\x62\x61\x63\x6b\x67\162\157\165\x6e\144\x2d\x63\157\154\x6f\x72" => "\x62\x6c\165\145"), self::BG_CYAN => array("\142\x61\x63\x6b\x67\x72\157\x75\x6e\x64\55\x63\157\154\x6f\x72" => "\x61\x71\165\x61"), self::BG_GREEN => array("\x62\141\143\153\x67\x72\157\x75\x6e\144\55\x63\x6f\x6c\x6f\162" => "\154\151\x6d\145"), self::BG_GREY => array("\x62\141\x63\x6b\147\x72\x6f\x75\156\x64\x2d\143\157\x6c\x6f\x72" => "\x73\151\154\166\145\x72"), self::BG_PURPLE => array("\x62\141\143\x6b\147\x72\157\x75\x6e\x64\55\x63\x6f\x6c\157\162" => "\x72\x65\142\145\143\x63\x61\160\x75\162\x70\154\x65"), self::BG_RED => array("\142\x61\143\153\147\x72\x6f\165\x6e\144\x2d\x63\157\154\x6f\162" => "\162\145\144"), self::BG_YELLOW => array("\x62\x61\143\x6b\x67\x72\157\165\x6e\144\x2d\143\157\x6c\157\162" => "\x79\145\x6c\x6c\x6f\x77"), self::BOLD => array("\146\157\156\x74\x2d\167\x65\151\147\x68\164" => "\x62\157\x6c\x64"), self::ITALIC => array("\146\x6f\x6e\x74\55\163\x74\171\x6c\145" => "\151\164\141\154\151\143"), self::UNDERLINE => array("\x74\145\170\x74\55\x64\x65\143\157\x72\x61\x74\151\x6f\156" => array("\x75\156\x64\145\162\x6c\x69\156\x65")), self::OVERLINED => array("\164\145\x78\164\55\144\145\143\x6f\162\x61\164\151\157\156" => array("\x6f\x76\x65\x72\x6c\x69\x6e\x65")), self::CROSSED_OUT => array("\x74\145\170\164\x2d\x64\145\x63\x6f\x72\x61\164\x69\x6f\156" => array("\x6c\151\x6e\x65\x2d\x74\x68\x72\x6f\x75\x67\150")), self::BLINK => array("\164\145\x78\164\55\144\x65\x63\x6f\162\141\x74\x69\157\x6e" => array("\142\x6c\151\156\153")), self::CONCEALED => array("\166\151\x73\151\142\151\x6c\151\164\x79" => "\150\x69\x64\144\x65\156")) + $styleMap; $tags = 0; $result = preg_replace_callback("\x2f\x5c\x30\63\x33\134\133\x28\x5b\x5c\144\73\135\53\x29\x6d\x2f", function ($ansi) use(&$tags, $styleMap) { $style = array(); $reset = false; $negative = false; foreach (explode("\73", $ansi[1]) as $controlCode) { if ($controlCode == 0) { $style = array(); $reset = true; } elseif ($controlCode == self::NEGATIVE) { $negative = true; } elseif (isset($styleMap[$controlCode])) { $style[] = $styleMap[$controlCode]; } } $return = ''; while ($reset && $tags > 0) { $return .= "\74\x2f\x73\x70\x61\156\x3e"; $tags--; } if (empty($style)) { return $return; } $currentStyle = array(); foreach ($style as $content) { $currentStyle = ArrayHelper::merge($currentStyle, $content); } if ($negative) { if (isset($currentStyle["\143\x6f\x6c\x6f\162"])) { $fgColor = $currentStyle["\143\157\154\157\162"]; unset($currentStyle["\x63\157\x6c\x6f\162"]); } if (isset($currentStyle["\142\x61\143\x6b\147\162\157\x75\x6e\144\x2d\x63\157\x6c\x6f\162"])) { $bgColor = $currentStyle["\142\141\143\153\x67\162\157\165\156\x64\55\143\157\x6c\157\162"]; unset($currentStyle["\x62\141\x63\153\147\x72\157\165\156\x64\x2d\143\x6f\154\157\162"]); } if (isset($fgColor)) { $currentStyle["\142\141\143\x6b\147\x72\157\165\x6e\x64\x2d\143\x6f\154\157\162"] = $fgColor; } if (isset($bgColor)) { $currentStyle["\143\157\154\x6f\x72"] = $bgColor; } } $styleString = ''; foreach ($currentStyle as $name => $value) { if (is_array($value)) { $value = implode("\x20", $value); } $styleString .= "{$name}\x3a\40{$value}\73"; } $tags++; return "{$return}\74\163\x70\x61\156\x20\x73\164\x79\154\145\x3d\42{$styleString}\x22\76"; }, $string); while ($tags > 0) { $result .= "\x3c\57\163\x70\x61\156\76"; $tags--; } return $result; } public static function markdownToAnsi($markdown) { $parser = new ConsoleMarkdown(); return $parser->parse($markdown); } public static function renderColoredString($string, $colored = true) { static $conversions = array("\x25\x79" => array(self::FG_YELLOW), "\x25\x67" => array(self::FG_GREEN), "\x25\x62" => array(self::FG_BLUE), "\x25\162" => array(self::FG_RED), "\x25\160" => array(self::FG_PURPLE), "\45\x6d" => array(self::FG_PURPLE), "\x25\143" => array(self::FG_CYAN), "\x25\167" => array(self::FG_GREY), "\x25\x6b" => array(self::FG_BLACK), "\x25\156" => array(0), "\45\131" => array(self::FG_YELLOW, self::BOLD), "\x25\107" => array(self::FG_GREEN, self::BOLD), "\x25\102" => array(self::FG_BLUE, self::BOLD), "\x25\122" => array(self::FG_RED, self::BOLD), "\x25\x50" => array(self::FG_PURPLE, self::BOLD), "\x25\115" => array(self::FG_PURPLE, self::BOLD), "\45\103" => array(self::FG_CYAN, self::BOLD), "\x25\127" => array(self::FG_GREY, self::BOLD), "\x25\x4b" => array(self::FG_BLACK, self::BOLD), "\45\x4e" => array(0, self::BOLD), "\x25\x33" => array(self::BG_YELLOW), "\x25\x32" => array(self::BG_GREEN), "\x25\64" => array(self::BG_BLUE), "\x25\x31" => array(self::BG_RED), "\45\65" => array(self::BG_PURPLE), "\x25\66" => array(self::BG_CYAN), "\45\67" => array(self::BG_GREY), "\45\x30" => array(self::BG_BLACK), "\x25\106" => array(self::BLINK), "\45\x55" => array(self::UNDERLINE), "\45\70" => array(self::NEGATIVE), "\x25\x39" => array(self::BOLD), "\x25\x5f" => array(self::BOLD)); if ($colored) { $string = str_replace("\x25\45", "\x25\x20", $string); foreach ($conversions as $key => $value) { $string = str_replace($key, static::ansiFormatCode($value), $string); } $string = str_replace("\x25\40", "\45", $string); } else { $string = preg_replace("\x2f\x25\50\x28\45\51\174\56\x29\x2f", "\44\62", $string); } return $string; } public static function escape($string) { return str_replace("\45", "\x25\45", $string); } public static function streamSupportsAnsiColors($stream) { return DIRECTORY_SEPARATOR === "\134" ? getenv("\101\x4e\x53\111\x43\x4f\x4e") !== false || getenv("\x43\x6f\156\x45\x6d\165\101\116\123\111") === "\117\x4e" : function_exists("\x70\157\163\151\170\x5f\151\163\141\164\x74\x79") && @posix_isatty($stream); } public static function isRunningOnWindows() { return DIRECTORY_SEPARATOR === "\x5c"; } public static function getScreenSize($refresh = false) { static $size; static $execDisabled; if ($size !== null && ($execDisabled || !$refresh)) { return $size; } if ($execDisabled === null) { $execDisabled = !function_exists("\151\156\151\137\x67\x65\x74") || preg_match("\x2f\50\134\x62\x65\170\x65\143\x5c\142\51\57\x69", ini_get("\144\151\x73\x61\x62\x6c\x65\137\146\165\x6e\143\164\x69\x6f\x6e\163")); if ($execDisabled) { return $size = false; } } if (static::isRunningOnWindows()) { $output = array(); exec("\x6d\x6f\x64\145\x20\x63\x6f\156", $output); if (isset($output[1]) && strpos($output[1], "\103\x4f\x4e") !== false) { return $size = array((int) preg_replace("\176\x5c\104\x7e", '', $output[4]), (int) preg_replace("\x7e\x5c\104\x7e", '', $output[3])); } } else { $stty = array(); if (exec("\163\x74\164\171\x20\x2d\x61\40\62\76\46\61", $stty)) { $stty = implode("\x20", $stty); if (preg_match("\x2f\x72\x6f\x77\x73\x5c\x73\x2b\x28\x5c\144\53\x29\x3b\134\163\52\x63\x6f\154\165\155\x6e\163\134\x73\53\x28\x5c\144\x2b\51\73\x2f\155\151", $stty, $matches)) { return $size = array((int) $matches[2], (int) $matches[1]); } if (preg_match("\57\x28\x5c\144\53\51\134\x73\x2b\x72\157\x77\x73\73\x5c\163\52\50\134\144\53\51\x5c\x73\x2b\x63\x6f\154\165\155\x6e\x73\73\x2f\155\151", $stty, $matches)) { return $size = array((int) $matches[2], (int) $matches[1]); } } if (($width = (int) exec("\164\160\x75\164\40\x63\x6f\154\x73\40\x32\x3e\46\61")) > 0 && ($height = (int) exec("\x74\x70\x75\164\40\x6c\x69\x6e\x65\163\x20\x32\76\46\61")) > 0) { return $size = array($width, $height); } if (($width = (int) getenv("\x43\x4f\114\125\115\116\x53")) > 0 && ($height = (int) getenv("\x4c\111\x4e\105\123")) > 0) { return $size = array($width, $height); } } return $size = false; } public static function wrapText($text, $indent = 0, $refresh = false) { $size = static::getScreenSize($refresh); if ($size === false || $size[0] <= $indent) { return $text; } $pad = str_repeat("\x20", $indent); $lines = explode("\xa", wordwrap($text, $size[0] - $indent, "\12")); $first = true; foreach ($lines as $i => $line) { if ($first) { $first = false; continue; } $lines[$i] = $pad . $line; } return implode("\12", $lines); } public static function stdin($raw = false) { return $raw ? fgets(\STDIN) : rtrim(fgets(\STDIN), PHP_EOL); } public static function stdout($string) { return fwrite(\STDOUT, $string); } public static function stderr($string) { return fwrite(\STDERR, $string); } public static function input($prompt = null) { if (isset($prompt)) { static::stdout($prompt); } return static::stdin(); } public static function output($string = null) { return static::stdout($string . PHP_EOL); } public static function error($string = null) { return static::stderr($string . PHP_EOL); } public static function prompt($text, $options = array()) { $options = ArrayHelper::merge(array("\x72\x65\161\x75\x69\162\145\x64" => false, "\144\x65\x66\x61\165\x6c\164" => null, "\160\x61\164\x74\x65\162\156" => null, "\x76\x61\154\x69\144\x61\164\157\x72" => null, "\145\162\162\157\x72" => "\111\156\x76\x61\x6c\151\144\40\x69\x6e\160\165\164\x2e"), $options); $error = null; top: $input = $options["\144\145\146\x61\x75\x6c\164"] ? static::input("{$text}\x20\x5b" . $options["\x64\145\x66\x61\165\x6c\164"] . "\135\x20") : static::input("{$text}\40"); if ($input === '') { if (isset($options["\x64\145\x66\141\x75\154\164"])) { $input = $options["\x64\145\x66\141\x75\x6c\164"]; } elseif ($options["\162\x65\161\165\x69\162\x65\144"]) { static::output($options["\x65\162\x72\157\162"]); goto top; } } elseif ($options["\160\141\x74\x74\x65\x72\156"] && !preg_match($options["\160\141\x74\x74\x65\162\156"], $input)) { static::output($options["\145\162\x72\157\162"]); goto top; } elseif ($options["\x76\141\x6c\151\x64\x61\x74\157\162"] && !call_user_func_array($options["\166\141\x6c\x69\x64\141\x74\x6f\x72"], array($input, &$error))) { static::output(isset($error) ? $error : $options["\145\162\x72\157\162"]); goto top; } return $input; } public static function confirm($message, $default = false) { while (true) { static::stdout($message . "\x20\50\171\x65\x73\174\156\157\x29\x20\x5b" . ($default ? "\x79\145\x73" : "\x6e\157") . "\135\72"); $input = trim(static::stdin()); if (empty($input)) { return $default; } if (!strcasecmp($input, "\x79") || !strcasecmp($input, "\171\145\163")) { return true; } if (!strcasecmp($input, "\156") || !strcasecmp($input, "\156\x6f")) { return false; } } } public static function select($prompt, $options = array(), $default = null) { top: static::stdout("{$prompt}\40\x28" . implode("\54", array_keys($options)) . "\54\77\x29" . ($default !== null ? "\x5b" . $default . "\135" : '') . "\72\40"); $input = static::stdin(); if ($input === "\77") { foreach ($options as $key => $value) { static::output("\x20{$key}\40\55\x20{$value}"); } static::output("\40\x3f\x20\55\x20\123\150\157\x77\x20\150\x65\x6c\x70"); goto top; } elseif ($default !== null && $input === '') { return $default; } elseif (!array_key_exists($input, $options)) { goto top; } return $input; } private static $_progressStart; private static $_progressWidth; private static $_progressPrefix; private static $_progressEta; private static $_progressEtaLastDone = 0; private static $_progressEtaLastUpdate; public static function startProgress($done, $total, $prefix = '', $width = null) { self::$_progressStart = time(); self::$_progressWidth = $width; self::$_progressPrefix = $prefix; self::$_progressEta = null; self::$_progressEtaLastDone = 0; self::$_progressEtaLastUpdate = time(); static::updateProgress($done, $total); } public static function updateProgress($done, $total, $prefix = null) { if ($prefix === null) { $prefix = self::$_progressPrefix; } else { self::$_progressPrefix = $prefix; } $width = static::getProgressbarWidth($prefix); $percent = $total == 0 ? 1 : $done / $total; $info = sprintf("\45\144\x25\x25\40\x28\x25\x64\57\x25\x64\x29", $percent * 100, $done, $total); self::setETA($done, $total); $info .= self::$_progressEta === null ? "\x20\105\124\101\72\x20\156\x2f\141" : sprintf("\40\x45\124\x41\72\40\45\x64\x20\x73\145\x63\56", self::$_progressEta); $extraChars = static::isRunningOnWindows() ? 4 : 3; $width -= $extraChars + static::ansiStrlen($info); if ($width < 5) { static::stdout("\15{$prefix}{$info}\40\x20\x20"); } else { if ($percent < 0) { $percent = 0; } elseif ($percent > 1) { $percent = 1; } $bar = floor($percent * $width); $status = str_repeat("\75", $bar); if ($bar < $width) { $status .= "\x3e"; $status .= str_repeat("\40", $width - $bar - 1); } static::stdout("\xd{$prefix}" . "\133{$status}\x5d\x20{$info}"); } flush(); } private static function getProgressbarWidth($prefix) { $width = self::$_progressWidth; if ($width === false) { return 0; } $screenSize = static::getScreenSize(true); if ($screenSize === false && $width < 1) { return 0; } if ($width === null) { $width = $screenSize[0]; } elseif ($width > 0 && $width < 1) { $width = floor($screenSize[0] * $width); } $width -= static::ansiStrlen($prefix); return $width; } private static function setETA($done, $total) { if ($done > $total || $done == 0) { self::$_progressEta = null; self::$_progressEtaLastUpdate = time(); return; } if ($done < $total && (time() - self::$_progressEtaLastUpdate > 1 && $done > self::$_progressEtaLastDone)) { $rate = (time() - (self::$_progressEtaLastUpdate ?: self::$_progressStart)) / ($done - self::$_progressEtaLastDone); self::$_progressEta = $rate * ($total - $done); self::$_progressEtaLastUpdate = time(); self::$_progressEtaLastDone = $done; } } public static function endProgress($remove = false, $keepPrefix = true) { if ($remove === false) { static::stdout(PHP_EOL); } else { if (static::streamSupportsAnsiColors(STDOUT)) { static::clearLine(); } static::stdout("\15" . ($keepPrefix ? self::$_progressPrefix : '') . (is_string($remove) ? $remove : '')); } flush(); self::$_progressStart = null; self::$_progressWidth = null; self::$_progressPrefix = ''; self::$_progressEta = null; self::$_progressEtaLastDone = 0; self::$_progressEtaLastUpdate = null; } public static function errorSummary($models, $options = array()) { $showAllErrors = ArrayHelper::remove($options, "\163\x68\157\x77\x41\154\x6c\x45\162\162\157\x72\x73", false); $lines = self::collectErrors($models, $showAllErrors); return implode(PHP_EOL, $lines); } private static function collectErrors($models, $showAllErrors) { $lines = array(); if (!is_array($models)) { $models = array($models); } foreach ($models as $model) { $lines = array_unique(array_merge($lines, $model->getErrorSummary($showAllErrors))); } return $lines; } }

Function Calls

None

Variables

None

Stats

MD5 2270a6b1e1c8c47ee95267858f73a2f6
Eval Count 0
Decode Time 145 ms