public function toString() { $this->_colorizer = new Zend_Tool_Framework_Client_Console_ResponseDecorator_Colorizer(); $string = array(); $string[] = array(array('LINE', 'bgRed')); $string[] = array(array($this->_data['errstr'], array('hiWhite', 'bgRed')), array('SPACER', 'bgRed'), array(' | ' . $this->_error2string($this->_data['errno']), 'bgRed')); $string[] = array(array('LINE', 'bgRed')); $insertCodeOffset = null; if (isset($this->_data['backtrace'])) { $table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, ''); $index = 1; for ($i = 0; $i < sizeof($this->_data['backtrace']); $i++) { $frame = $this->_data['backtrace'][$i]; $row = array(); if ($i == 0) { // We are dealing with an exception if (is_string($this->_data['errno'])) { $table->addRow(array(' | ' . $this->_normalizeFilePath($this->_data['errfile']), '@ ' . $this->_data['errline'])); } else { // We are dealing with an error if ($frame['class'] == 'FirePHP_Error_Handler') { $i++; if (!isset($frame['file']) && !isset($frame['line'])) { $frame = $this->_data['backtrace'][$i]; } $row[] = ' | ' . $this->_normalizeFilePath($frame['file']); $row[] = '@ ' . $frame['line']; } else { throw new Exception('Could not determine where to insert code!'); } } } if (!$row) { if (!isset($frame['file'])) { // This is a call_user_func*() call frame if (sizeof($this->_data['backtrace']) >= $i + 1) { $frameNext = $this->_data['backtrace'][$i + 1]; $row[] = ' | ' . $this->_normalizeFilePath($frameNext['file']); $row[] = '@ ' . $frameNext['line']; $row[] = '- call_user_func*(\'' . $frame['class'] . '\',\'' . $frame['function'] . '\')'; $i++; } } else { $row[] = ' | ' . $this->_normalizeFilePath($frame['file']); $row[] = '@ ' . $frame['line']; $row[] = '- ' . (isset($frame['type']) ? $frame['class'] . $frame['type'] . $frame['function'] : $frame['function']) . '(' . $this->_renderArgs($frame['args']) . ')'; } } $table->addRow($row); $index++; } $insertCodeOffset = sizeof($string) + 1; foreach (explode("\n", $table->getTable()) as $line) { if ($line = rtrim($line)) { $string[] = rtrim($line); } } } if (isset($this->_data['errfile']) && isset($this->_data['errline'])) { $code = array(); $code[] = ' |'; $start = $this->_data['errline'] - 5; if ($start < 0) { $start = 0; } // TODO: Make number of lines configurable $end = $start + 10; $lines = file($this->_data['errfile']); if ($end >= sizeof($lines)) { $end = sizeof($lines) - 1; } for ($i = $start; $i <= $end; $i++) { $errorLine = $i + 1 == $this->_data['errline']; $lines[$i] = str_replace("\t", ' ', rtrim($lines[$i])); $code[] = str_pad($i + 1, 4, ' ', STR_PAD_LEFT) . ($errorLine ? '|>' : '| ') . $lines[$i]; // See if we have annotated arguments on previous lines and insert them if ($errorLine && ($vars = FirePHP_Annotator::getVariables())) { for ($j = sizeof($code) - 1; $j >= sizeof($code) - 4; $j--) { if (($pos = strpos($code[$j], 'FirePHP_Annotator::setVariables(')) !== false) { $varLines = array(); $varLines[] = ''; foreach ($vars as $name => $value) { $varLines[] = ' :' . str_repeat(' ', $pos - 1) . $name . ' = ' . $this->_renderVar($value, 70); } $varLines[] = ''; array_splice($code, $j + 1, 0, $varLines); break; } } } } $code[] = ' |'; if ($insertCodeOffset !== null) { array_splice($string, $insertCodeOffset, 0, $code); } else { array_splice($string, sizeof($string), 0, $code); } } $string[] = array(array('LINE', 'bgRed')); $string[] = array('RIGHT', array('Generated by FirePHP: http://www.firephp.org/', 'cyan')); $this->_markupOutput($string); return implode("\n", $string); }
protected function _parseAnnotationTag($tag) { if (!preg_match_all('/^([^)\\s]*?)\\s*=\\s*(.*?)$/si', $tag->getDescription(), $m)) { FirePHP_Annotator::setVariables(array('tag' => $tag)); throw new Exception('Tag format not valid!'); } return array($m[1][0], $m[2][0]); }