Esempio n. 1
0
 /**
  * Print backtrace link
  *
  * <code>
  * Panda_Debug::trace();
  * </code>
  *
  * @param string $return         return string if true
  * @param array  $debugBackTrace array:trace data false:trace from here
  *
  * @return void
  */
 public static function trace($return = false, $debugBackTrace = false)
 {
     assert(is_bool($return));
     assert(is_bool($debugBackTrace) || is_array($debugBackTrace));
     $debugBackTrace = $debugBackTrace ? $debugBackTrace : debug_backtrace();
     $id = md5(print_r($debugBackTrace, true));
     foreach ($debugBackTrace as &$row) {
         if (!isset($row['file']) && isset($row['class'])) {
             $ref = new ReflectionMethod($row['class'], $row['function']);
             $row['file'] = $ref->getFileName();
             $row['line'] = $ref->getStartLine();
             $row['end'] = $ref->getEndLine();
         }
     }
     $pageLogPath = Panda::getTempDir() . "/trace-{$id}.log";
     file_put_contents($pageLogPath, serialize($debugBackTrace));
     $style = "padding:3px;margin:0px 4px;font-size:12px;color:white;background-color:black;font:arial white";
     $name = "{$debugBackTrace[0]['file']} in {$debugBackTrace[0]['line']}";
     $link = '<a href="/__panda/trace/?id=' . $id . '" title="' . $name . '" target="_panda_trace_' . $id . '" style="';
     $link .= $style . '">trace</a>';
     if ($return === true) {
         return $link;
     }
     echo $link;
 }
Esempio n. 2
0
 /**
  * Init
  *
  * @return void
  */
 private function _init()
 {
     // init
     $traceFile = Panda::getTempDir() . '/trace-' . $_GET['id'] . '.log';
     if (!file_exists($traceFile)) {
         error_reporting(E_ALL);
         trigger_error('invalid trace file. ' . $traceFile, E_USER_ERROR);
     }
     // store trace data
     $this->_traceLog = @unserialize(file_get_contents($traceFile));
     if (!$this->_traceLog) {
         die("<p>trace is not available...</p>");
     }
     // store refection data if exists
     $refDataFile = "{$traceFile}.ref.log";
     if (file_exists($refDataFile)) {
         $this->_ref = unserialize(file_get_contents($refDataFile));
     }
     $this->_traceLevels = array_keys($this->_traceLog);
     $this->_levelNum = count($this->_traceLevels);
     $this->_editor = isset($_GET['editor']) ? $_GET['editor'] : self::EDITOR_NONE;
 }