/** * Dumps information about a variable in readable format. * * @param mixed $var to dump * @param null $title * @return void */ public static function sdump($var, $title = null) { if (!Debugger::$productionMode) { self::initialize(); $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT); $item = Helpers::findTrace($trace, 'sdump', $index) ?: Helpers::findTrace($trace, __CLASS__ . '::sdump', $index); if (isset($item['file'], $item['line']) && is_file($item['file'])) { $lines = file($item['file']); preg_match('#sdump\\((.*)\\)#', $lines[$item['line'] - 1], $matches); $params = isset($matches[1]) ? htmlspecialchars($matches[1]) : false; if ($params) { preg_match('#array\\((.*)\\)#', $params, $matches2); $params = isset($matches2[1]) ? $matches2[1] : $params; $params = explode(',', $params); } $dumpParams = isset($matches[0]) ? "{$matches['0']};" : ''; $location = Debugger::$showLocation ? "<br>" . Helpers::editorLink($item['file'], $item['line']) : false; } $tiMethod = $trace[$index + 1]; $dumpTitle = isset($tiMethod['class']) ? $tiMethod['class'] . $tiMethod['type'] . $tiMethod['function'] . '(); ' : $tiMethod['function'] . $title; $dumpObject = self::$dumpObject && isset($tiMethod['object']) ? Dumper::toHtml($tiMethod['object']) : ''; $dump = (isset($dumpParams) ? "<b>{$dumpParams}</b> " : '') . (isset($location) ? $location : '') . $dumpObject; if (self::$traceMode) { for ($i = 0; $i <= $index; $i++) { array_shift($trace); } $dump .= "<br/>" . self::showTraceSimple($trace); } $dump .= Dumper::toHtml($var); self::$dumps = array('title' => $dumpTitle, 'dump' => $dump); self::addToDumpPanel($dump, $dumpTitle); } }
/** * e.g. SQL explain * * @return NULL|Html|string */ public function getInfo() { $info = $this->response; unset($info['hits']['hits']); $html = Dumper::toHtml($info, [Dumper::COLLAPSE => TRUE, Dumper::TRUNCATE => 50]); return Html::el()->setHtml($html); }
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>'; }
/** * @internal * @param \Exception|NULL $e * @return string[]|NULL */ public static function render(\Exception $e = NULL) { if (!$e instanceof \Nella\Tracy\DebugInfoException) { return NULL; // skip } return ['tab' => 'Exception Debug Info', 'panel' => \Tracy\Dumper::toHtml($e->__debugInfo())]; }
/** * @param array * @return string */ protected function processQuery(array $query) { $s = ''; list($sql, $params, $time) = $query; $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000); $s .= '</td><td class="nette-Doctrine2Panel-sql">' . Helpers::dumpSql($sql); $s .= '</td><td>' . Dumper::toHtml($params) . '</tr>'; return $s; }
/** * @return Html|string */ public function getResult() { $data = iterator_to_array($this->result); foreach ($data as &$row) { $row = $this->rowToArray($row); } $html = Dumper::toHtml($data, [Dumper::COLLAPSE => TRUE]); return Html::el()->setHtml($html); }
public static function initializePanel(Nette\Application\Application $application) { Tracy\Debugger::getBlueScreen()->addPanel(function ($e) use ($application) { return $e ? NULL : array( 'tab' => 'Nette Application', 'panel' => '<h3>Requests</h3>' . Tracy\Dumper::toHtml($application->getRequests()) . '<h3>Presenter</h3>' . Tracy\Dumper::toHtml($application->getPresenter()), ); }); }
/** * @return string */ public function getPanel() { if (empty($this->evaluatedFeatures)) { return NULL; } $evaluatedFeatures = $this->evaluatedFeatures; $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = TRUE, $d = 4) { return \Tracy\Dumper::toHtml($o, array('collapse' => $c, 'depth' => $d)); } : callback('\\Tracy\\Helpers::clickableDump'); ob_start(); require __DIR__ . '/panel.phtml'; return ob_get_clean(); }
/** * Renders HTML code for custom panel. * @return string */ function getPanel() { if (!$this->messages) { return NULL; } ob_start(); $esc = callback('Nette\\Templating\\Helpers::escapeHtml'); $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) { return \Tracy\Dumper::toHtml($o, array('collapse' => $c)); } : callback('\\Tracy\\Helpers::clickableDump'); require __DIR__ . '/panel.phtml'; return ob_get_clean(); }
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) { $stack = array(); foreach (array_slice($item[3], 1) as $t) { $t += array('class' => '', 'type' => '', 'function' => ''); $stack[] = "{$t['class']}{$t['type']}{$t['function']}()" . (isset($t['file'], $t['line']) ? ' in ' . basename($t['file']) . ":{$t['line']}" : ''); } $res .= Helpers::editorLink($item[0], $item[1]) . ' ' . '<span title="' . htmlspecialchars(implode("\n", $stack), ENT_IGNORE | ENT_QUOTES, 'UTF-8') . '">' . str_replace(self::BOM, '<big>BOM</big>', Dumper::toHtml($item[2])) . "</span><br>\n"; } return $res . '</code>'; }
/** * Renders HTML code for custom panel. * @return string */ public function getPanel() { if (!$this->resources) { return null; } $esc = \Nette\Utils\Callback::closure('Latte\\Runtime\\Filters::escapeHtml'); $click = function ($o, $c = false) { return \Tracy\Dumper::toHtml($o, ['collapse' => $c]); }; ob_start(); include __DIR__ . '/panel.phtml'; return ob_get_clean(); }
/** * @param \Kdyby\Curl\Response $response * * @return string */ public static function allResponses($response) { if (!$response instanceof Curl\Response) { return NULL; } $click = function ($o, $c = TRUE) { return Dumper::toHtml($o, array('collapse' => $c)); }; $responses = array($click($response, TRUE)); while ($response = $response->getPrevious()) { $responses[] = $click($response, TRUE); } return implode('', $responses); }
/** * @return string */ public function getPanel() { if (!$this->calls) { return NULL; } ob_start(); $esc = array('Nette\\Templating\\Helpers', 'escapeHtml'); $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) { return \Tracy\Dumper::toHtml($o, array('collapse' => $c)); } : array('\\Tracy\\Helpers', 'clickableDump'); $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none'; require __DIR__ . '/panel.phtml'; return ob_get_clean(); }
/** * @return string */ public function getPanel() { if (!$this->calls) { return NULL; } ob_start(); $esc = function ($s) { return htmlSpecialChars($s, ENT_QUOTES, 'UTF-8'); }; $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) { return \Tracy\Dumper::toHtml($o, array('collapse' => $c)); } : Callback::closure('\\Tracy\\Helpers::clickableDump'); $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none'; require __DIR__ . '/panel.phtml'; return ob_get_clean(); }
/** * @return string */ public function getPanel() { if (!$this->calls) { return NULL; } ob_start(); if (class_exists('Latte\\Runtime\\Filters')) { $esc = Nette\Utils\Callback::closure('Latte\\Runtime\\Filters::escapeHtml'); } else { $esc = 'Nette\\Templating\\Helpers::escapeHtml'; } $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) { return \Tracy\Dumper::toHtml($o, array('collapse' => $c)); } : '\\Tracy\\Helpers::clickableDump'; $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none'; require __DIR__ . '/panel.phtml'; return ob_get_clean(); }
/** * 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+)( )?</span>#', function ($m) use($vars) { return isset($vars[$m[1]]) ? '" title="' . str_replace('"', '"', strip_tags(Dumper::toHtml($vars[$m[1]]))) . $m[0] : $m[0]; }, $out); return "<pre class='php'><div>{$out}</div></pre>"; }
/** * @return string */ public function getPanel() { $isRunning = function ($type, $name) { if (strncasecmp(PHP_OS, 'WIN', 3) == 0) { return FALSE; // sry, I don't know how to do this } $command = sprintf('ps aux |grep %s |grep %s', $type === 'consumer' ? 'rabbitmq:consumer' : 'rabbitmq:rpc-server', escapeshellarg($name)); if (!@exec($command, $output)) { return FALSE; } $instances = 0; foreach ($output as $line) { if (stripos($line, '|grep') === FALSE) { $instances += 1; } } return $instances; }; $workers = []; $runningWorkers = $configuredWorkers = 0; foreach ($this->serviceMap as $type => $services) { foreach ($services as $name => $serviceId) { $workers[$key = $type . '/' . $name] = $isRunning($type, $name); $runningWorkers += (int) $workers[$key]; $configuredWorkers++; } } ob_start(); $esc = class_exists('Nette\\Templating\\Helpers') ? ['Nette\\Templating\\Helpers', 'escapeHtml'] : ['Latte\\Runtime\\Filters', 'escapeHtml']; $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) { return \Tracy\Dumper::toHtml($o, ['collapse' => $c]); } : ['Tracy\\Helpers', 'clickableDump']; require __DIR__ . '/panel.phtml'; return ob_get_clean(); }
public static function clickableDump($var) { trigger_error(__METHOD__ . '() is deprecated; use Tracy\\Dumper::toHtml() instead.', E_USER_DEPRECATED); return Tracy\Dumper::toHtml($var); }
/** * (HTML) content of panel based on object * * @author Martin Hlaváč * @link http://www.ktstudio.cz/ * * @param mixed $object * @param string $title * @return string */ public function getObjectPanel($object, $title = null) { $output = null; if (self::issetAndNotEmpty($title)) { $output .= "<h1>{$title}</h1>"; } $output .= "<div class=\"nette-inner\">"; $output .= Dumper::toHtml($object, array(Dumper::COLLAPSE => false)); $output .= "</div>"; return $output; }
public static function renderException($e) { if (!$e instanceof HttpException) { return; } $data = $e->getBody(); try { $data = Json::decode($data); if (isset($data->error->trace)) { $data->error->trace = explode("\n", $data->error->trace); } } catch (JsonException $e) { } $message = NULL; if (is_string($data)) { $dump = '<pre>' . htmlspecialchars($data) . "</pre>"; } else { $dump = Dumper::toHtml($data); $message = isset($data->error->msg) ? $data->error->msg : NULL; } return ['tab' => 'SOLR', 'panel' => ($message ? "<h2>{$message}</h2>" : '') . '<h3>Code: ' . $e->getCode() . '</h3><br>' . $dump]; }
/** * Dumps information about a variable in Tracy Debug Bar. * @tracySkipLocation * @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) { static $panel; if (!$panel) { self::getBar()->addPanel($panel = new DefaultBarPanel('dumps')); } $panel->data[] = ['title' => $title, 'dump' => Dumper::toHtml($var, (array) $options + [Dumper::DEPTH => self::$maxDepth, Dumper::TRUNCATE => self::$maxLen, Dumper::LOCATION => self::$showLocation])]; } return $var; }
/** * Renders HTML code for custom panel. * @return string */ function getPanel() { ob_start(); echo Dumper::toHtml($this->appRequest); return ob_get_clean(); }
/** * e.g. SQL explain * * @return NULL|Html|string * @throws \DibiException * @throws \Exception */ public function getInfo() { if (!$this->event->sql) { return NULL; } $query = 'EXPLAIN (FORMAT JSON) ' . $this->event->sql; $explain = $this->event->connection->nativeQuery($query); $data = json_decode($explain->fetchSingle(), TRUE); return Html::el()->setHtml(Dumper::toHtml($data, [Dumper::COLLAPSE => TRUE])); }
/** * @param \Exception|\Throwable $e * @param \Nette\DI\Container $dic * @return array */ public function renderEntityManagerException($e) { if (!in_array($e, $this->whitelistExceptions, TRUE)) { return NULL; // ignore } if (strpos(get_class($e), 'Doctrine\\ORM\\') !== FALSE && Helpers::findTrace($e->getTrace(), 'Doctrine\\ORM\\EntityManager::flush')) { $UoW = $this->unitOfWorkSnapshot ?: $this->em->getUnitOfWork(); $panel = '<div class="inner"><p><b>IdentityMap</b></p>' . Dumper::toHtml($UoW->getIdentityMap(), [Dumper::COLLAPSE => TRUE]) . '</div>'; if ($scheduled = $UoW->getScheduledEntityInsertions()) { $panel .= '<div class="inner"><p><b>Scheduled entity insertions</b></p>' . Dumper::toHtml($scheduled, [Dumper::COLLAPSE => TRUE]) . '</div>'; } if ($scheduled = $UoW->getScheduledEntityDeletions()) { $panel .= '<div class="inner"><p><b>Scheduled entity deletions</b></p>' . Dumper::toHtml($scheduled, [Dumper::COLLAPSE => TRUE]) . '</div>'; } if ($scheduled = $UoW->getScheduledEntityUpdates()) { $panel .= '<div class="inner"><p><b>Scheduled entity updates</b></p>' . Dumper::toHtml($scheduled, [Dumper::COLLAPSE => TRUE]) . '</div>'; } return ['tab' => 'Doctrine\\ORM\\UnitOfWork', 'panel' => $panel]; } }
public static function dumpToHtml($object) { return \Tracy\Dumper::toHtml($object, [\Tracy\Dumper::DEPTH => 3]); }
/** * @param \Exception|\Throwable $e * @return array|NULL */ public static function renderException($e = NULL) { if (!$e instanceof ExceptionInterface) { return NULL; } $panel = NULL; if ($e instanceof Elastica\Exception\ResponseException) { $panel .= '<h3>Request</h3>'; $panel .= Dumper::toHtml($e->getRequest()); $panel .= '<h3>Response</h3>'; $panel .= Dumper::toHtml($e->getResponse()); } elseif ($e instanceof Elastica\Exception\Bulk\ResponseException) { $panel .= '<h3>Failures</h3>'; $panel .= Dumper::toHtml($e->getFailures()); } /*elseif ($e->getQuery() !== NULL) { $panel .= '<h3>Query</h3>' . '<pre class="nette-dump"><span class="php-string">' . $e->getQuery()->getQuery() . '</span></pre>'; } */ return $panel ? array('tab' => 'ElasticSearch', 'panel' => $panel) : NULL; }
/** * e.g. SQL explain * * @return NULL|\Nette\Utils\Html|string */ public function getInfo() { switch ($this->type) { case 'mysql': $info = array(array('id' => '1', 'select_type' => 'SIMPLE', 'table' => 'user', 'partitions' => 'NULL', 'type' => 'ALL', 'possible_keys' => 'NULL', 'key' => 'NULL', 'key_len' => 'NULL', 'ref' => 'NULL', 'rows' => '2154', 'Extra' => 'NULL')); break; case 'postgres': $info = json_decode('[ { "Plan": { "Node Type": "Index Scan","Scan Direction": "Forward","Index Name": "videos_pkey","Relation Name": "videos","Alias": "e","Startup Cost": 0.16,"Total Cost": 13.69,"Plan Rows": 10,"Plan Width": 167,"Index Cond": "(id = ANY (\'{330,82,56,55,311,270,277,290,322,331}\'::integer[]))" } } ]', TRUE); break; case 'neo4j': $r = mt_rand(1, 100); $html = '<table><tbody><tr><th>eid</th></tr><tr><td><code>' . $r . '</code></td></tr></tbody></table>'; return \Nette\Utils\Html::el()->setHtml($html); default: return NULL; } $html = \Tracy\Dumper::toHtml($info, array(\Tracy\Dumper::COLLAPSE => TRUE)); return \Nette\Utils\Html::el()->setHtml($html); }
/** * Dumps information about a variable in Tracy Debug Bar. * @tracySkipLocation * @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; }
private static function dumpToHtml($structure) { return Dumper::toHtml($structure, array(Dumper::COLLAPSE => TRUE, Dumper::DEPTH => 2)); }
/** * @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); } }