Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement debugger for the main page that is loaded - next job is to …

…handle AJAX requests
  • Loading branch information...
commit 3c97aa92e2b56a568fa3d5c4f3b6366e2f686799 1 parent 32e76ca
@lsproc lsproc authored
View
1  .gitignore
@@ -1,3 +1,4 @@
public/.htaccess
application/cache
application/configuration/caspar.yml
+.DS_Store
View
173 application/resources/css/cspdebugger.css
@@ -0,0 +1,173 @@
+#csp-dbg-main, #csp-dbg-open {
+ font-family: sans-serif;
+ font-size: 12px;
+}
+
+#csp-dbg-main p {
+ margin: 0;
+ padding-bottom: 10px;
+}
+
+#csp-dbg-open {
+ position: absolute;
+ bottom: 0;
+ right: 0;
+ padding: 4px;
+ background: black;
+ color: white;
+ text-align: center;
+ background: #45484d; /* Old browsers */
+ background: -moz-linear-gradient(top, #45484d 0%, #000000 100%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#45484d), color-stop(100%,#000000)); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, #45484d 0%,#000000 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, #45484d 0%,#000000 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, #45484d 0%,#000000 100%); /* IE10+ */
+ background: linear-gradient(top, #45484d 0%,#000000 100%); /* W3C */
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#45484d', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
+ -webkit-box-shadow: 0px 0px 10px rgba(50, 50, 50, 0.75);
+ -moz-box-shadow: 0px 0px 10px rgba(50, 50, 50, 0.75);
+ box-shadow: 0px 0px 10px rgba(50, 50, 50, 0.75);
+}
+
+#csp-dbg-open-btn {
+ padding: 6px;
+ border: 1px solid transparent;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+ opacity: 0.8;
+}
+
+#csp-dbg-open-btn:hover {
+ padding: 6px;
+ border: 1px solid #005596;
+ cursor: pointer;
+ background: #3f4c6b; /* Old browsers */
+ background: -moz-linear-gradient(top, #3f4c6b 0%, #282f44 100%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3f4c6b), color-stop(100%,#282f44)); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, #3f4c6b 0%,#282f44 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, #3f4c6b 0%,#282f44 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, #3f4c6b 0%,#282f44 100%); /* IE10+ */
+ background: linear-gradient(top, #3f4c6b 0%,#282f44 100%); /* W3C */
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3f4c6b', endColorstr='#282f44',GradientType=0 ); /* IE6-9 */
+}
+
+#csp-dbg-main {
+ background-color: rgba(0, 0, 0, 0.5);
+ height: 100%;
+ width: 100%;
+ top: 0;
+ left: 0;
+ position: absolute;
+}
+
+#csp-dbg-title {
+ font-size: 30px;
+ color: white;
+ background: #45484d; /* Old browsers */
+ background: -moz-linear-gradient(top, #45484d 0%, #000000 100%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#45484d), color-stop(100%,#000000)); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, #45484d 0%,#000000 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, #45484d 0%,#000000 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, #45484d 0%,#000000 100%); /* IE10+ */
+ background: linear-gradient(top, #45484d 0%,#000000 100%); /* W3C */
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#45484d', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
+ padding: 15px;
+}
+
+.csp-dbg-title-close, .csp-dbg-entry-open, .csp-dbg-entry-close {
+ float: right;
+ cursor: pointer;
+}
+
+.csp-dbg-entry-row {
+ background: #333333; /* Old browsers */
+ border-top: 1px solid #555555;
+ border-bottom: 1px solid black;
+ color: white;
+ font-size: 20px;
+ padding: 10px;
+}
+
+#csp-dbg-row-ver {
+ font-size: 12px;
+ font-style: italic;
+}
+
+.csp-dbg-entry-row-content {
+ background: white;
+ padding: 20px;
+}
+
+.csp-dbg-tab-panels .csp-dbg-tab-panel {
+ border: 1px solid black;
+ border-top: none;
+ padding: 10px;
+}
+
+.csp-dbg-tab-bar {
+ border-bottom: 1px solid black;
+ margin: 0;
+ padding: 0;
+ padding-bottom: 7px;
+}
+
+.csp-dbg-tab-bar li {
+ display: inline;
+ height: 50px;
+ background: #CCCCCC;
+ padding: 7px;
+ margin: 0;
+ border: 1px solid black;
+ cursor: pointer;
+}
+
+.csp-dbg-tab-bar li.csp-dbg-row-content-tab-selected {
+ border-bottom: 1px solid white;
+ background: white;
+}
+
+#csp-dbg-next-row-id {
+ display: none;
+}
+
+.csp-dbg-log-level {
+ font-weight: bold;
+}
+
+.csp-dbg-log-source {
+ font-weight: bold;
+}
+
+.csp-dbg-log-time, .csp-dbg-query-title-time, .csp-dbg-timing-time {
+ color: #AAA;
+ font-style: italic;
+}
+
+.csp-dbg-query-title-id, .csp-dbg-variable-title-id, .csp-dbg-timing-id, .csp-dbg-json-field {
+ font-weight: bold;
+}
+
+.csp-dbg-query-body, .csp-dbg-variable-content, .csp-dbg-json-value {
+ padding-top: 5px;
+ margin: 0;
+ padding-bottom: 5px;
+ margin-bottom: 10px;
+ border-bottom: 1px dotted #AAA;
+}
+
+.csp-dbg-json {
+ width: 100%;
+}
+
+.csp-dbg-trace-file {
+ color: #55F;
+}
+
+.csp-dbg-trace-file-unknown {
+ color: #AAA;
+}
+
+.csp-dbg-trace-function {
+ font-weight: bold;
+}
View
1  application/templates/layout.php
@@ -22,5 +22,6 @@
</head>
<body>
<?php echo $content; ?>
+ <?php \caspar\core\Debugger::display(); ?>
</body>
</html>
View
13 caspar/core/Caspar.class.php
@@ -132,6 +132,13 @@ class Caspar
static protected $_routing;
/**
+ * The debugger object
+ *
+ * @var Debugger
+ */
+ static protected $_debugger = null;
+
+ /**
* Messages passed on from the previous request
*
* @var array
@@ -1011,6 +1018,7 @@ public static function loadConfiguration()
self::autoloadNamespace('al13_debug', \CASPAR_LIB_PATH . DS . 'al13_debug' . DS);
require \CASPAR_LIB_PATH . 'al13_debug' . DS . 'bootstrap.php';
self::getResponse()->addStylesheet('css/debugger.css');
+ self::$_debugger = new Debugger();
} else {
self::$_debug_mode = false;
}
@@ -1173,5 +1181,10 @@ public static function getSalt()
return self::$_configuration['core']['salt'];
}
+ public static function getDebugger()
+ {
+ return self::$_debugger;
+ }
+
}
View
91 caspar/core/Debugger.class.php
@@ -0,0 +1,91 @@
+<?php
+
+ namespace caspar\core;
+
+ /**
+ * Caspar debugger
+ *
+ * @author Daniel Andre Eikeland <zegenie@gmail.com>, Philip Kent <philip.kent@me.com>
+ * @version 1.0
+ * @license http://www.opensource.org/licenses/mozilla1.1.php Mozilla Public License 1.1 (MPL 1.1)
+ * @package caspar
+ * @subpackage core
+ */
+
+ /**
+ * Caspar debugger
+ *
+ * @package caspar
+ * @subpackage core
+ */
+ class Debugger
+ {
+ protected $_storedvars = array();
+ protected $_jsonoutput = array();
+
+ public static function display() {
+ $csp_debugger = \caspar\core\Caspar::getDebugger();
+ require CASPAR_PATH . 'templates' . DS . 'debugger.php';
+ }
+
+ public function __construct() {
+ }
+
+ public function getRouting() {
+ return \caspar\core\Caspar::getRouting();
+ }
+
+ public function getExecutionTime() {
+ return \caspar\core\Caspar::getLoadTime();
+ }
+
+ public function getLog() {
+ return \caspar\core\Logging::getEntries();
+ }
+
+ public function getPartials() {
+ return \caspar\core\Caspar::getVisitedPartials();
+ }
+
+ public function isAjaxRequest() {
+ return false;
+ }
+
+ public function setJsonOutput($output) {
+ $this->_jsonoutput = json_decode($output);
+ }
+
+ public function getJsonOutput() {
+ return $this->_jsonoutput;
+ }
+
+ public function isDatabaseLoaded() {
+ return false;
+ }
+
+ public function getDatabaseQueries() {
+ return array();
+ }
+
+ public function storeVariable($name, $data, $file, $line) {
+ if (array_key_exists($name, $this->_storedvars)) {
+ throw new Exception('A variable by this name has already been stored');
+ }
+
+ $this->_storedvars[$name] = array('value' => $data, 'file' => $file, 'line' => $line);
+ }
+
+ public function unstoreVariable($name) {
+ unset($this->_storedvars[$name]);
+ }
+
+ public function getStoredVariables() {
+ return $this->_storedvars;
+ }
+
+ public function getCurrentPageRow() {
+ $cspdbgrow = time();
+ $csp_debugger = $this;
+ require CASPAR_PATH . 'templates' . DS . 'debugger-row.php';
+ }
+ }
View
110 caspar/templates/debugger-row.php
@@ -0,0 +1,110 @@
+<?php
+ // prepare fields
+ $dbgjson = $csp_debugger->getJsonOutput();
+ $dbgstored = $csp_debugger->getStoredVariables();
+ $dbglog = \caspar\core\Logging::getEntries();
+ $dbgpartials = $csp_debugger->getPartials();
+?>
+
+ <div class="csp-dbg-entry-row" id="csp-dbg-row-<?php echo $cspdbgrow; ?>">
+ <?php if ($csp_debugger->isAjaxRequest()): ?>AJAX Request<?php else: ?>This page<?php endif; ?> - <?php echo $csp_debugger->getRouting()->getCurrentRouteName(); ?>
+ <div class="csp-dbg-entry-open" id="csp-dbg-row-<?php echo $cspdbgrow; ?>-open" onClick="cspexpandEntry(<?php echo $cspdbgrow; ?>);">
+ &#x25BC;
+ </div>
+ <div class="csp-dbg-entry-close" id="csp-dbg-row-<?php echo $cspdbgrow; ?>-close" style="display: none;" onClick="cspcollapseEntry(<?php echo $cspdbgrow; ?>);">
+ &#x25B2;
+ </div>
+ </div>
+ <div class="csp-dbg-entry-row-content" id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content" style="display: none;">
+ <ul class="csp-dbg-tab-bar" id="csp-dbg-row-<?php echo $cspdbgrow; ?>1-content-tab">
+ <li id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-1" class="csp-dbg-row-content-tab-selected" onClick="cspchangeDebuggerTab(<?php echo $cspdbgrow; ?>,1);">Summary</li>
+ <li id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-2" onClick="cspchangeDebuggerTab(<?php echo $cspdbgrow; ?>,2);">JSON Output (<?php echo count($dbgjson); ?>)</li>
+ <li id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-3" onClick="cspchangeDebuggerTab(<?php echo $cspdbgrow; ?>,3);">Timings (<?php echo count($dbgpartials); ?>)</li>
+ <li id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-4" onClick="cspchangeDebuggerTab(<?php echo $cspdbgrow; ?>,4);">Caspar log (<?php echo count($dbglog); ?>)</li>
+ <li id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-5" onClick="cspchangeDebuggerTab(<?php echo $cspdbgrow; ?>,5);">Database queries (0 please implement me)</li>
+ <li id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-6" onClick="cspchangeDebuggerTab(<?php echo $cspdbgrow; ?>,6);">Stored variables (<?php echo count($dbgstored); ?>)</li>
+ <li id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-7" onClick="cspchangeDebuggerTab(<?php echo $cspdbgrow; ?>,7);">Backtrace</li>
+ </ul>
+ <div class="csp-dbg-tab-panels">
+ <div id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-1-panel" class="csp-dbg-tab-panel">
+ <ul>
+ <li><b>Route:</b> [<?php echo $csp_debugger->getRouting()->getCurrentRouteName(); ?>] <?php echo $csp_debugger->getRouting()->getCurrentRouteModule(); ?> / <?php echo $csp_debugger->getRouting()->getCurrentRouteAction(); ?></li>
+ <li><b>Execution time:</b> <?php echo $csp_debugger->getExecutionTime(); ?> seconds</li>
+ <li><b>AJAX query?</b> <?php if ($csp_debugger->isAjaxRequest()): ?>Yes<?php else: ?>No<?php endif; ?></li>
+ </ul>
+ </div>
+ <div id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-2-panel" class="csp-dbg-tab-panel" style="display: none;">
+ <?php if (!$csp_debugger->isAjaxRequest()): ?>
+ <p><i>This tab only applies to AJAX requests.</i></p>
+ <?php else: ?>
+ <p><i>This is a list of all items in the JSON output.</i></p>
+ <?php foreach ($dbgjson as $field => $value): ?>
+ <div class="csp-dbg-json-field"><?php echo $field; ?></div>
+ <pre class="csp-dbg-json-value"><?php echo $value; ?></pre>
+ <?php endforeach; ?>
+ <?php endif; ?>
+ </div>
+ <div id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-3-panel" class="csp-dbg-tab-panel" style="display: none;">
+ <p><i>This list shows how long actions and templates in this request take to load.</i></p>
+ <?php foreach ($dbgpartials as $partial => $data): ?>
+ <span class="csp-dbg-timing-id"><?php echo $partial; ?></span> <span class="csp-dbg-timing-time">Accessed <?php echo $data['count']; ?> time(s), totalling <?php echo ($data['time'] >= 1) ? round($data['time'], 2) . ' seconds' : round($data['time'] * 1000, 1) . 'ms'; ?></span><br />
+ <?php endforeach; ?>
+ </div>
+ <div id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-4-panel" class="csp-dbg-tab-panel" style="display: none;">
+ <p><i>Additional items can be added to this list using the <code>log</code> method in the Logging class - see the documentation for details.</i></p>
+ <div>
+ <?php foreach ($dbglog as $entry): ?>
+ <?php $color = \caspar\core\Logging::getCategoryColor($entry['category']); ?>
+ <?php $lname = \caspar\core\Logging::getLevelName($entry['level']); ?>
+ <span class="csp-dbg-log-level"><?php echo $lname; ?></span> <span class="csp-dbg-log-source" style="color: #<?php echo $color; ?>">[<?php echo $entry['category']; ?>]</span> <span class="csp-dbg-log-time"><?php echo $entry['time']; ?></span>&nbsp;&nbsp;<span class="csp-dbg-log-msg"><?php echo $entry['message']; ?></span><br />
+ <?php endforeach; ?>
+ </div>
+ </div>
+ <div id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-5-panel" class="csp-dbg-tab-panel" style="display: none;">
+ <p><i>This list shows all the SQL queries that have been made, and how long each took.</i></p>
+ <div class="csp-dbg-query-title">
+ <span class="csp-dbg-query-title-id">Query 1</span> <span class="csp-dbg-query-title-time">10ms</span> <span class="csp-dbg-query-title-file"> - foo.php:123</span>
+ </div>
+ <div class="csp-dbg-query-body">
+ <code>SELECT * FROM foo;</code>
+ </div>
+ <div class="csp-dbg-query-title">
+ <span class="csp-dbg-query-title-id">Query 2</span> <span class="csp-dbg-query-title-time">10ms</span> <span class="csp-dbg-query-title-file"> - foo.php:123</span>
+ </div>
+ <div class="csp-dbg-query-body">
+ <code>SELECT * FROM foo;</code>
+ </div>
+ </div>
+ <div id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-6-panel" class="csp-dbg-tab-panel" style="display: none;">
+ <p><i>You can store a variable for inspection here using the <code>storeVariable()</code> method on your Debugger instance - see the documentation for details.</i></p>
+ <?php foreach ($dbgstored as $field => $data): ?>
+ <div class="csp-dbg-variable-title"><span class="csp-dbg-variable-title-id"><?php echo $field; ?></span> <span class="csp-dbg-variable-title-file"> - <?php echo $data['file'].':'.$data['line']; ?></span></div>
+ <pre class="csp-dbg-variable-content"><?php var_dump($data['value']); ?></pre>
+ <?php endforeach; ?>
+ </div>
+ <div id="csp-dbg-row-<?php echo $cspdbgrow; ?>-content-tab-7-panel" class="csp-dbg-tab-panel" style="display: none;">
+ <ul>
+ <?php $trace = (isset($exception)) ? $exception->getTrace() : debug_backtrace(); ?>
+ <?php foreach ($trace as $trace_element): ?>
+ <?php if (array_key_exists('class', $trace_element) && $trace_element['class'] == 'caspar\core\Caspar' && array_key_exists('function', $trace_element) && $trace_element['function'] == 'errorHandler') continue; ?>
+ <li>
+ <?php if (array_key_exists('class', $trace_element)): ?>
+ <span class="csp-dbg-trace-function"><?php echo $trace_element['class'].$trace_element['type'].$trace_element['function']; ?>()</span>
+ <?php elseif (array_key_exists('function', $trace_element) && array_key_exists('class', $trace_element) && $trace_element['class'] != 'caspar\core\Caspar' && !in_array($trace_element['function'], array('errorHandler', 'exceptionHandler'))): ?>
+ <span class="csp-dbg-trace-function"><?php echo $trace_element['function']; ?>()</span>
+ <?php else: ?>
+ <span class="csp-dbg-trace-function">unknown function</span>
+ <?php endif; ?>
+ <br>
+ <?php if (array_key_exists('file', $trace_element)): ?>
+ <span class="csp-dbg-trace-file"><?php echo $trace_element['file']; ?></span>, line <?php echo $trace_element['line']; ?>
+ <?php else: ?>
+ <span class="csp-dbg-trace-file csp-dbg-trace-file-unknown">unknown file</span>
+ <?php endif; ?>
+ </li>
+ <?php endforeach; ?>
+ </ul>
+ </div>
+ </div>
+ </div>
+
View
62 caspar/templates/debugger.php
@@ -0,0 +1,62 @@
+<?php if ($csp_debugger instanceof \caspar\core\Debugger): ?>
+ <script type="text/javascript" language="javascript">
+ function cspexpandEntry(row) {
+ document.getElementById("csp-dbg-row-" + row + "-close").style.display = "block";
+ document.getElementById("csp-dbg-row-" + row + "-open").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-content").style.display = "block";
+ }
+
+ function cspcollapseEntry(row) {
+ document.getElementById("csp-dbg-row-" + row + "-close").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-open").style.display = "block";
+ document.getElementById("csp-dbg-row-" + row + "-content").style.display = "none";
+ }
+
+ function cspcloseDebugger() {
+ document.getElementById("csp-dbg-main").style.display = "none";
+ }
+
+ function cspopenDebugger() {
+ document.getElementById("csp-dbg-main").style.display = "block";
+ }
+
+ function cspchangeDebuggerTab(row, tab) {
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-1-panel").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-2-panel").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-3-panel").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-4-panel").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-5-panel").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-6-panel").style.display = "none";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-7-panel").style.display = "none";
+
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-1").className = "";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-2").className = "";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-3").className = "";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-4").className = "";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-5").className = "";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-6").className = "";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-7").className = "";
+
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-" + tab + "-panel").style.display = "block";
+ document.getElementById("csp-dbg-row-" + row + "-content-tab-" + tab).className = "csp-dbg-row-content-tab-selected";
+ }
+ </script>
+ <div id="csp-dbg-open">
+ <div id="csp-dbg-open-btn" onClick="cspopenDebugger();"><span>Open debugger</span></div>
+ </div>
+ <div id="csp-dbg-main" style="display: none;">
+ <div id="csp-dbg-title">
+ Debug Console
+ <div class="csp-dbg-title-close" onClick="cspcloseDebugger();">
+ &times;
+ </div>
+ </div>
+ <div id="csp-dbg-content">
+ <?php $csp_debugger->getCurrentPageRow(); ?>
+ </div>
+ </div>
+</body>
+
+</html>
+<?php endif; ?>
+
Please sign in to comment.
Something went wrong with that request. Please try again.