public static function getVersion() { if (self::$versionRetrieved) { return self::$version; } self::$versionRetrieved = true; $location = app_path() . DIRECTORY_SEPARATOR . "version"; if (!is_readable($location)) { return null; } $lines = file($location); if ($lines === false || count($lines) < 1) { return null; } $version = trim($lines[0]); self::$version = $version; return $version; }
public static function barDump($var, $title = NULL) { if (!self::$productionMode) { $dump = array(); foreach (is_array($var) ? $var : array('' => $var) as $key => $val) { $dump[$key] = DebugHelpers::clickableDump($val); } self::$dumpPanel->data[] = array('title' => $title, 'dump' => $dump); } return $var; }
App::error(function (Exception $exception, $code) { Log::error($exception); }); App::error(function (Illuminate\Session\TokenMismatchException $exception) { return Response::make("CSRF error.", 500); }); /* |-------------------------------------------------------------------------- | Maintenance Mode Handler |-------------------------------------------------------------------------- | | The "down" Artisan command gives you the ability to put an application | into maintenance mode. Here, you will define what is displayed back | to the user if maintenance mode is in effect for the application. | */ App::down(function () { return DebugHelpers::generateMaintenanceModeResponse(); }); /* |-------------------------------------------------------------------------- | Require The Filters File |-------------------------------------------------------------------------- | | Next we will load the filters file for the application. This gives us | a nice separate location to store our route and application filter | definitions instead of putting them all in the main routes file. | */ require app_path() . '/filters.php'; require app_path() . '/events.php';
public static function renderPanel($id, $data) { switch ($id) { case 'dumps': ?> <style>#nette-debug-dumps h2{font:11pt/1.5 sans-serif;margin:0;padding:2px 8px;background:#3484d2;color:white}#nette-debug-dumps table{width:100%}#nette-debug #nette-debug-dumps a{color:#333;background:transparent}#nette-debug-dumps a abbr{font-family:sans-serif;color:#999}#nette-debug-dumps pre.nette-dump span{color:#c16549}</style> <h1>Dumped variables</h1> <div class="nette-inner"> <?php foreach ($data as $item) { ?> <?php if ($item['title']) { ?> <h2><?php echo htmlspecialchars($item['title']); ?> </h2> <?php } ?> <table> <?php $i = 0; ?> <?php foreach ($item['dump'] as $key => $dump) { ?> <tr class="<?php echo $i++ % 2 ? 'nette-alt' : ''; ?> "> <th><?php echo htmlspecialchars($key); ?> </th> <td><?php echo $dump; ?> </td> </tr> <?php } ?> </table> <?php } ?> </div> <?php return; case 'errors': ?> <h1>Errors</h1> <?php $relative = isset($_SERVER['SCRIPT_FILENAME']) ? strtr(dirname(dirname($_SERVER['SCRIPT_FILENAME'])), '/', DIRECTORY_SEPARATOR) : NULL; ?> <div class="nette-inner"> <table> <?php $i = 0; foreach ($data as $item => $count) { list($message, $file, $line) = explode('|', $item); ?> <tr class="<?php echo $i++ % 2 ? 'nette-alt' : ''; ?> "> <td class="nette-right"><?php echo $count ? "{$count}×" : ''; ?> </td> <td><pre><?php echo htmlspecialchars($message), ' in ', Debug::$editor ? '<a href="' . DebugHelpers::editorLink($file, $line) . '">' : '', htmlspecialchars($relative ? str_replace($relative, "...", $file) : $file), ':', $line, Debug::$editor ? '</a>' : ''; ?> </pre></td> </tr> <?php } ?> </table> </div><?php } }
public function getPanel() { $this->disabled = TRUE; $s = ''; $h = 'htmlSpecialChars'; foreach ($this->queries as $i => $query) { list($sql, $params, $time, $rows, $connection, $source) = $query; $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && preg_match('#\\s*\\(?\\s*SELECT\\s#iA', $sql)) { try { $cmd = is_string($this->explain) ? $this->explain : 'EXPLAIN'; $explain = $connection->queryArgs("{$cmd} {$sql}", $params)->fetchAll(); } catch (PDOException $e) { } } $s .= '<tr><td>' . sprintf('%0.3f', $time * 1000); if ($explain) { static $counter; $counter++; $s .= "<br /><a href='#' class='nette-toggler' rel='#nette-DbConnectionPanel-row-{$counter}'>explain ►</a>"; } $s .= '</td><td class="nette-DbConnectionPanel-sql">' . DatabaseHelpers::dumpSql(self::$maxLength ? Strings::truncate($sql, self::$maxLength) : $sql); if ($explain) { $s .= "<table id='nette-DbConnectionPanel-row-{$counter}' class='nette-collapsed'><tr>"; foreach ($explain[0] as $col => $foo) { $s .= "<th>{$h($col)}</th>"; } $s .= "</tr>"; foreach ($explain as $row) { $s .= "<tr>"; foreach ($row as $col) { $s .= "<td>{$h($col)}</td>"; } $s .= "</tr>"; } $s .= "</table>"; } if ($source) { $s .= DebugHelpers::editorLink($source[0], $source[1])->class('nette-DbConnectionPanel-source'); } $s .= '</td><td>'; foreach ($params as $param) { $s .= Debugger::dump($param, TRUE); } $s .= '</td><td>' . $rows . '</td></tr>'; } return empty($this->queries) ? '' : '<style> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important } #nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style> <h1>Queries: ' . count($this->queries) . ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . '</h1> <div class="nette-inner nette-DbConnectionPanel"> <table> <tr><th>Time ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . ' </table> </div>'; }
/** * Generate a HexBlock from the current position in the file stream. * * The pointer will be returned to the initial position when done, essentially leaving the file stream untouched. * * @param resource|string $data a resource handle or a string. * @param int $bytes number of bytes to print. -1 will dump the entirety of the file. * @param bool $encodeHTML Encode the special characters that may occur on the right panel. * * @return string The generated Hex Block. */ public static function createBlock($data, $bytes, $encodeHTML = true) { $out = ""; /** @var resource $handle */ $handle = null; $isLocalHandle = false; if (is_string($data)) { $handle = DebugHelpers::str2resource($data); $isLocalHandle = true; } else { if (is_resource($data)) { $handle = $data; } else { return $out; } } $stat = fstat($handle); $length = $stat['size']; $pos = ftell($handle); if ($bytes === -1) { $bytes = $length - $pos; } $endPos = $pos + $bytes; $realPos = $pos & 0xfffffff0; fseek($handle, $realPos, SEEK_SET); $isRangeOverreached = $pos + $bytes > $length; $rDigits = strlen(dechex($isRangeOverreached ? $length : $pos + $bytes)); $rDigits += $rDigits % 2; if ($rDigits < 2) { $rDigits = 2; } $lDigits = strlen(dechex($bytes)); $lDigits += $lDigits % 2; if ($lDigits < 2) { $lDigits = 2; } $out .= "Start: 0x" . str_pad(strtoupper(dechex($pos)), $rDigits, "0", STR_PAD_LEFT); $out .= "; Length: " . $bytes . " (0x" . str_pad(strtoupper(dechex($bytes)), $lDigits, "0", STR_PAD_LEFT) . ")\n"; if ($isRangeOverreached) { $or = $pos + $bytes - $length; $out .= "* Requested length overreach by " . $or . " bytes, only " . ($bytes - $or) . " available in stream.\n"; if ($bytes - $or <= 0) { fseek($handle, $pos, SEEK_SET); return $out; } } while (ftell($handle) < $endPos && !(feof($handle) || ftell($handle) === $length)) { $lsp = ftell($handle); $out .= str_pad(strtoupper(dechex($lsp)), $rDigits, "0", STR_PAD_LEFT) . ": "; $rp = "| "; for ($j = 0; $j < 16; $j++) { if ($j == 8) { $rp .= " "; $out .= " "; } if ($lsp + $j < $pos) { $rp .= "-"; $out .= "-- "; fread($handle, 1); } elseif ($lsp + $j >= $endPos || (feof($handle) || ftell($handle) === $length)) { $rp .= "-"; $out .= "-- "; } else { $d = fread($handle, 1); $out .= bin2hex($d) . " "; $od = ord($d); if ($od < 0x20 || $od >= 0x7f) { $d = '.'; } $rp .= $encodeHTML ? htmlspecialchars($d) : $d; } } $out .= $rp . "\n"; } $out .= "\n"; if ($isLocalHandle) { fclose($handle); } else { fseek($handle, $pos, SEEK_SET); } return $out; }