/**
  * Output an error
  *
  * @param string $message
  */
 public function error($message)
 {
     if ($this->quiet) {
         return;
     }
     if (Director::is_cli()) {
         $text = SS_Cli::text(date('Y-m-d H:i:s') . ': ' . $message, 'red') . "\n";
         file_put_contents('php://stderr', $text, FILE_APPEND);
     } else {
         $this->message($message);
     }
 }
 public function index()
 {
     if (!Director::is_cli()) {
         return "The SilverStripe Interactive Command-line doesn't work in a web browser." . " Use 'sake interactive' from the command-line to run.";
     }
     /* Try using PHP_Shell if it exists */
     @(include 'php-shell-cmd.php');
     /* Fall back to our simpler interface */
     if (empty($__shell)) {
         set_error_handler(array($this, 'error_handler'));
         echo "SilverStripe Interactive Command-line (REPL interface). Type help for hints.\n\n";
         while (true) {
             echo SS_Cli::text("?> ", "cyan");
             echo SS_Cli::start_colour("yellow");
             $command = trim(fgets(STDIN, 4096));
             echo SS_Cli::end_colour();
             if ($command == 'help' || $command == '?') {
                 print "help or ? to exit\n";
                 print "quit or \\q to exit\n";
                 print "install PHP_Shell for a more advanced interface with" . " auto-completion and readline support\n\n";
                 continue;
             }
             if ($command == 'quit' || $command == '\\q') {
                 break;
             }
             // Simple command processing
             if (substr($command, -1) == ';') {
                 $command = substr($command, 0, -1);
             }
             $is_print = preg_match('/^\\s*print/i', $command);
             $is_return = preg_match('/^\\s*return/i', $command);
             if (!$is_print && !$is_return) {
                 $command = "return ({$command})";
             }
             $command .= ";";
             try {
                 $result = eval($command);
                 if (!$is_print) {
                     print_r($result);
                 }
                 echo "\n";
             } catch (Exception $__repl_exception) {
                 echo SS_Cli::start_colour("red");
                 printf('%s (code: %d) got thrown' . PHP_EOL, get_class($__repl_exception), $__repl_exception->getCode());
                 print $__repl_exception;
                 echo "\n";
             }
         }
     }
 }
 public function writeVariable($val, $caller)
 {
     echo PHP_EOL;
     echo SS_Cli::text(str_repeat('=', self::config()->columns), 'green');
     echo PHP_EOL;
     echo SS_Cli::text($this->formatCaller($caller), 'blue', null, true);
     echo PHP_EOL . PHP_EOL;
     if (is_string($val)) {
         print_r(wordwrap($val, self::config()->columns));
     } else {
         print_r($val);
     }
     echo PHP_EOL;
     echo SS_Cli::text(str_repeat('=', self::config()->columns), 'green');
     echo PHP_EOL;
 }
 /**
  * Formats simple html-like markup into coloured text
  * Supports:
  *   - <b>bold text</b>
  *   - <success>Green text</success>
  *   - <error>Red text</error>
  *   - <caution>Yellow text</caution>
  *   - <info>Cyan text</info>
  *   
  * @param  string $text
  * @return string
  */
 public static function format($text)
 {
     $text = preg_replace_callback('/<b>(.+?)<\\/b>/', function ($matches) {
         return SS_Cli::text($matches[1], null, null, true);
     }, $text);
     $text = preg_replace_callback('/<success>(.+?)<\\/success>/', function ($matches) {
         return SS_Cli::text($matches[1], 'green', null, true);
     }, $text);
     $text = preg_replace_callback('/<error>(.+?)<\\/error>/', function ($matches) {
         return SS_Cli::text($matches[1], 'red', null, true);
     }, $text);
     $text = preg_replace_callback('/<caution>(.+?)<\\/caution>/', function ($matches) {
         return SS_Cli::text($matches[1], 'yellow', null, true);
     }, $text);
     $text = preg_replace_callback('/<info>(.+?)<\\/info>/', function ($matches) {
         return SS_Cli::text($matches[1], 'cyan', null, true);
     }, $text);
     return $text;
 }
 /**
  * Write information about the error to the screen
  */
 public function writeError($httpRequest, $errno, $errstr, $errfile, $errline, $errcontext)
 {
     $errorType = self::$error_types[$errno];
     echo SS_Cli::text("ERROR [" . $errorType['title'] . "]: {$errstr}\nIN {$httpRequest}\n", "red", null, true);
     echo SS_Cli::text("Line {$errline} in {$errfile}\n\n", "red");
 }
 protected function writeTest($test)
 {
     if ($test['status'] != TEST_SUCCESS) {
         $filteredTrace = array();
         $ignoredClasses = array('TestRunner');
         foreach ($test['trace'] as $item) {
             if (isset($item['file']) && strpos($item['file'], 'PHPUnit/Framework') === false && (!isset($item['class']) || !in_array($item['class'], $ignoredClasses))) {
                 $filteredTrace[] = $item;
             }
             if (isset($item['class']) && isset($item['function']) && $item['class'] == 'PHPUnit_Framework_TestSuite' && $item['function'] == 'run') {
                 break;
             }
         }
         $color = $test['status'] == 2 ? 'yellow' : 'red';
         echo "\n" . SS_Cli::text($test['name'] . "\n" . $test['message'] . "\n", $color, null);
         echo SS_Backtrace::get_rendered_backtrace($filteredTrace, true);
         echo "--------------------\n";
     }
 }
Пример #7
0
 public function renderVariable($val, $caller)
 {
     $output = PHP_EOL;
     $output .= SS_Cli::text(str_repeat('=', self::config()->columns), 'green');
     $output .= PHP_EOL;
     $output .= SS_Cli::text($this->formatCaller($caller), 'blue', null, true);
     $output .= PHP_EOL . PHP_EOL;
     if (is_string($val)) {
         $output .= wordwrap($val, self::config()->columns);
     } else {
         $output .= var_export($val, true);
     }
     $output .= PHP_EOL;
     $output .= SS_Cli::text(str_repeat('=', self::config()->columns), 'green');
     $output .= PHP_EOL;
     return $output;
 }
Пример #8
0
 protected function writeTest($test)
 {
     if ($test['status'] != 1) {
         $filteredTrace = array();
         $ignoredClasses = array('TestRunner');
         foreach ($test['trace'] as $item) {
             if (isset($item['file']) && strpos($item['file'], 'PHPUnit/Framework') === false && (!isset($item['class']) || !in_array($item['class'], $ignoredClasses))) {
                 $filteredTrace[] = $item;
             }
             if (isset($item['class']) && isset($item['function']) && $item['class'] == 'PHPUnit_Framework_TestSuite' && $item['function'] == 'run') {
                 break;
             }
         }
         echo "\n\n" . SS_Cli::text($this->testNameToPhrase($test['name']) . "\n" . $test['message'] . "\n", 'red', null, true);
         echo SS_Cli::text("In line {$test['exception']['line']} of {$test['exception']['file']}" . "\n\n", 'red');
         echo SS_Backtrace::get_rendered_backtrace($filteredTrace, true);
         echo "\n--------------------\n";
     }
 }