Esempio n. 1
0
 private static function dump($struct)
 {
     if (class_exists('Nette\\Diagnostics\\Dumper')) {
         return Nette\Diagnostics\Dumper::toText($struct);
     }
     return Nette\Diagnostics\Helpers::textDump($struct);
 }
Esempio n. 2
0
 private function renderHtml()
 {
     $res = '<style>code, pre {white-space:nowrap} a {text-decoration:none} pre {color:gray;display:inline} big {color:red}</style><code>';
     foreach ($this->list as $item) {
         $res .= Helpers::editorLink($item[0], $item[1]) . ' ' . str_replace(self::BOM, '<big>BOM</big>', Dumper::toHtml($item[2])) . "<br>\n";
     }
     return $res . '</code>';
 }
Esempio n. 3
0
 /**
  * @return string
  */
 public function getPanel()
 {
     if (!$this->calls) {
         return NULL;
     }
     ob_start();
     $esc = callback('Nette\\Templating\\Helpers::escapeHtml');
     $click = class_exists('Nette\\Diagnostics\\Dumper') ? function ($o, $c = FALSE) {
         return Nette\Diagnostics\Dumper::toHtml($o, array('collapse' => $c));
     } : callback('Nette\\Diagnostics\\Helpers::clickableDump');
     $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
     require __DIR__ . '/panel.phtml';
     return ob_get_clean();
 }
Esempio n. 4
0
 public function getPanel()
 {
     $template = parent::getTemplate();
     $template->setFile(__DIR__ . '/templates/panel.latte');
     $template->identity = $this->identity;
     $template->user = $this->user;
     $template->dumper = function ($variable, $collapsed = false) {
         if (class_exists('Nette\\Diagnostics\\Dumper')) {
             return Dumper::toHtml($variable, [Dumper::COLLAPSE => $collapsed]);
         }
         // Nette 2.0 back compatibility
         return \Nette\Diagnostics\Helpers::clickableDump($variable, $collapsed);
     };
     ob_start();
     if ($this->parent) {
         $template->render();
     }
     return ob_get_clean();
 }
Esempio n. 5
0
 /**
  * Returns syntax highlighted source code.
  * @param  string
  * @param  int
  * @param  int
  * @return string
  */
 public static function highlightPhp($source, $line, $lines = 15, $vars = array())
 {
     if (function_exists('ini_set')) {
         ini_set('highlight.comment', '#998; font-style: italic');
         ini_set('highlight.default', '#000');
         ini_set('highlight.html', '#06B');
         ini_set('highlight.keyword', '#D24; font-weight: bold');
         ini_set('highlight.string', '#080');
     }
     $source = str_replace(array("\r\n", "\r"), "\n", $source);
     $source = explode("\n", highlight_string($source, TRUE));
     $out = $source[0];
     // <code><span color=highlight.html>
     $source = str_replace('<br />', "\n", $source[1]);
     $out .= static::highlightLine($source, $line, $lines);
     $out = preg_replace_callback('#">\\$(\\w+)(&nbsp;)?</span>#', function ($m) use($vars) {
         return isset($vars[$m[1]]) ? '" title="' . str_replace('"', '&quot;', strip_tags(Dumper::toHtml($vars[$m[1]]))) . $m[0] : $m[0];
     }, $out);
     return "<pre class='php'><div>{$out}</div></pre>";
 }
Esempio n. 6
0
 /** @deprecated */
 public static function textDump($var)
 {
     trigger_error(__METHOD__ . '() is deprecated; use Nette\\Diagnostics\\Dumper::toText() instead.', E_USER_DEPRECATED);
     return Dumper::toText($var);
 }
Esempio n. 7
0
 /**
  * Dumps information about a variable in Nette Debug Bar.
  * @param  mixed  variable to dump
  * @param  string optional title
  * @param  array  dumper options
  * @return mixed  variable itself
  */
 public static function barDump($var, $title = NULL, array $options = NULL)
 {
     if (!self::$productionMode) {
         self::getBar()->getPanel(__CLASS__ . ':dumps')->data[] = array('title' => $title, 'dump' => Dumper::toHtml($var, (array) $options + array(Dumper::DEPTH => self::$maxDepth, Dumper::TRUNCATE => self::$maxLen, Dumper::LOCATION => self::$showLocation)));
     }
     return $var;
 }
Esempio n. 8
0
 public static function initializePanel(Nette\Application\Application $application)
 {
     Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(function ($e) use($application) {
         return $e ? NULL : array('tab' => 'Nette Application', 'panel' => '<h3>Requests</h3>' . Dumper::toHtml($application->getRequests()) . '<h3>Presenter</h3>' . Dumper::toHtml($application->getPresenter()));
     });
 }
Esempio n. 9
0
 /**
  * Log a message
  * @param Exception|string|array $message
  * @param null|string $identifier
  * @param null|int $priority
  * @param null|array $args
  * @throws InvalidArgumentException
  */
 public function message($message, $identifier = NULL, $priority = NULL, $args = NULL)
 {
     if (!$message) {
         throw new InvalidArgumentException('The message has to be specified.');
     }
     if ($priority == NULL) {
         $priority = $this->defaultLogLevel;
     }
     if ($priority < self::INFO || $priority > self::WARNING) {
         throw new InvalidArgumentException('Default Log Level must be one of the NasExt\\Logger\'s priority constants.');
     }
     $exception = NULL;
     $exceptionFilename = NULL;
     if ($message instanceof \Exception) {
         $exception = ($message instanceof FatalErrorException ? 'Fatal error: ' . $message->getMessage() : 'HTTP code' . $message->getCode() . ':: ' . get_class($message) . ": " . $message->getMessage()) . " in " . $message->getFile() . ":" . $message->getLine();
         $exceptionFilename = $this->generateExceptionFile($message);
         $message = $message->getMessage();
     }
     if (!is_string($args)) {
         $args = Json::encode($args);
     }
     if (!is_string($message)) {
         $message = Dumper::toText($message);
     }
     $this->loggerRepository->save($message, $exception, $exceptionFilename, $identifier, $priority, $args);
 }
Esempio n. 10
0
 /**
  * Returns syntax highlighted source code.
  * @param  string
  * @param  int
  * @param  int
  * @return string
  */
 public static function highlightPhp($source, $line, $lines = 15, $vars = array())
 {
     if (function_exists('ini_set')) {
         ini_set('highlight.comment', '#998; font-style: italic');
         ini_set('highlight.default', '#000');
         ini_set('highlight.html', '#06B');
         ini_set('highlight.keyword', '#D24; font-weight: bold');
         ini_set('highlight.string', '#080');
     }
     $source = str_replace(array("\r\n", "\r"), "\n", $source);
     $source = explode("\n", highlight_string($source, TRUE));
     $spans = 1;
     $out = $source[0];
     // <code><span color=highlight.html>
     $source = explode('<br />', $source[1]);
     array_unshift($source, NULL);
     $start = $i = max(1, $line - floor($lines * 2 / 3));
     while (--$i >= 1) {
         // find last highlighted block
         if (preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
             if ($m[1] !== '</span>') {
                 $spans++;
                 $out .= $m[1];
             }
             break;
         }
     }
     $source = array_slice($source, $start, $lines, TRUE);
     end($source);
     $numWidth = strlen((string) key($source));
     foreach ($source as $n => $s) {
         $spans += substr_count($s, '<span') - substr_count($s, '</span');
         $s = str_replace(array("\r", "\n"), array('', ''), $s);
         preg_match_all('#<[^>]+>#', $s, $tags);
         if ($n == $line) {
             $out .= sprintf("<span class='highlight'>%{$numWidth}s:    %s\n</span>%s", $n, strip_tags($s), implode('', $tags[0]));
         } else {
             $out .= sprintf("<span class='line'>%{$numWidth}s:</span>    %s\n", $n, $s);
         }
     }
     $out .= str_repeat('</span>', $spans) . '</code>';
     $out = preg_replace_callback('#">\\$(\\w+)(&nbsp;)?</span>#', function ($m) use($vars) {
         return isset($vars[$m[1]]) ? '" title="' . str_replace('"', '&quot;', strip_tags(Dumper::toHtml($vars[$m[1]]))) . $m[0] : $m[0];
     }, $out);
     return "<pre class='php'><div>{$out}</div></pre>";
 }
Esempio n. 11
0
 public static function dump($variable, $collapsed = false)
 {
     if (class_exists('Nette\\Diagnostics\\Dumper')) {
         return \Nette\Diagnostics\Dumper::toHtml($variable, [\Nette\Diagnostics\Dumper::COLLAPSE => $collapsed]);
     }
     // Nette 2.0 back compatibility
     return \Nette\Diagnostics\Helpers::clickableDump($variable, $collapsed);
 }
Esempio n. 12
0
 /**
  * @param  mixed
  * @return string
  */
 private function dumpHtml($var)
 {
     if (class_exists('Tracy\\Dumper')) {
         return Tracy\Dumper::toHtml($var, [Tracy\Dumper::COLLAPSE => TRUE]);
     } elseif (class_exists('Nette\\Diagnostics\\Dumper')) {
         return Nette\Diagnostics\Dumper::toHtml($var, [Nette\Diagnostics\Dumper::COLLAPSE => TRUE]);
     } else {
         return Nette\Diagnostics\Debugger::dump($var, TRUE);
     }
 }