Example #1
0
    /**
     * Generates a nice error message by formatting the stacktrace with some fancy colors
     * and showing which requirement failed.
     *
     * @author Yorick Peterse
     * @param  Array $error Array containing the error data such as the requirement and the stacktrace
     * @return Void
     */
    private static function format_error($error)
    {
        // First we need to tell the user what requirement failed
        puts(Colors::yellow("      Requirement \"{$error['requirement']}\" failed"));
        // Format the stacktrace
        foreach ($error['stacktrace'] as $index => $stack) {
            if ($stack['function'] == '{closure}') {
                $stack['function'] = 'Closure';
            }
            // Get the function/class combination
            if (isset($stack['class']) and !empty($stack['class'])) {
                $call = "{$stack['class']}->{$stack['function']}" . '()';
            } else {
                $call = $stack['function'] . '()';
            }
            $call = Colors::blue($call);
            $message = <<<MESSAGE
      {$index}. Call: {$call}
         File: {$stack['file']}
         Line: {$stack['line']}
MESSAGE;
            puts($message);
        }
        puts();
    }