Commit 66ff8a40 authored by Dayle Rees's avatar Dayle Rees

integrated a simple version of anbu into the laravel core

Signed-off-by: 's avatarDayle Rees <thepunkfan@gmail.com>
parent 2c12be30
<?php
return array(
/*
|--------------------------------------------------------------------------
| Show the LOG tab.
|--------------------------------------------------------------------------
|
| Display a tog showing all entries made using the Laravel Log class.
|
*/
'tab_logs' => true,
/*
|--------------------------------------------------------------------------
| Show the QUERIES tab.
|--------------------------------------------------------------------------
|
| Display a tab showing all queries performed by the Database layer.
|
*/
'tab_queries' => true,
/*
|--------------------------------------------------------------------------
| Include jQuery?
|--------------------------------------------------------------------------
|
| Anbu needs the jQuery JavaScript framework to function, if you are already
| using jQuery in your templates, set this value to false.
|
*/
'include_jquery' => true,
/*
|--------------------------------------------------------------------------
| Event Listeners
|--------------------------------------------------------------------------
|
| These are the Laravel event listeners, feel free to modify them to use
| a different data source, or include more if necessary.
|
*/
'event_listeners' => function()
{
// pass laravel log entries to anbu
Event::listen('laravel.log', 'Anbu::log');
// pass executed SQL queries to anbu
Event::listen('laravel.query', 'Anbu::sql');
},
);
......@@ -125,6 +125,20 @@ Event::listen(Lang::loader, function($bundle, $language, $file)
Blade::sharpen();
/*
|--------------------------------------------------------------------------
| Enable The Anbu Profiler
|--------------------------------------------------------------------------
|
| The Anbu profiler is an easy way to view all of your Executed SQL
| queries, log entries and other useful data from the front-end of your
| web app, to enable output simply add Anbu::render(); after the <body>
| tag of your main template, or page.
|
*/
Anbu::register();
/*
|--------------------------------------------------------------------------
| Set The Default Timezone
......
......@@ -88,6 +88,7 @@
</style>
</head>
<body>
<?php Anbu::render(); ?>
<div id="main">
<h1>Welcome To Laravel</h1>
......
/*
Anbu Styles
Copyright 2012 Dayle Rees.
MIT License <http://www.opensource.org/licenses/mit>
Intended for inclusion with the Laravel PHP Framework.
*/
.anbu
{
font-family:Helvetica, "Helvetica Neue", Arial, sans-serif !important;
font-size:14px !important;
background-color:#222 !important;
position:fixed !important;
bottom:0 !important;
right:0 !important;
width:100%;
z-index: 9999 !important;
}
.anbu-tabs
{
margin:0 !important;
padding:0 !important;
overflow:hidden !important;
}
.anbu-tabs li
{
display:inline;
}
.anbu-tabs a, .anbu-tabs a:visited
{
color:#aaa !important;
text-transform:uppercase !important;
font-weight:bold !important;
display:inline-block;
text-decoration:none !important;
font-size:0.8em !important;
padding: 0.8em 2em 0.7em 2em !important;
-webkit-transition-property:color, background-color;
-webkit-transition-duration: 0.7s, 0.2s;
-webkit-transition-timing-function: ease-in, ease-in;
-moz-transition-property:color, background-color;
-moz-transition-duration: 0.7s, 0.2s;
-moz-transition-timing-function: ease-in, ease-in;
-ms-transition-property:color, background-color;
-ms-transition-duration: 0.7s, 0.2s;
-ms-transition-timing-function: ease-in, ease-in;
-o-transition-property:color, background-color;
-o-transition-duration: 0.7s, 0.2s;
-o-transition-timing-function: ease-in, ease-in;
transition-property:color, background-color;
transition-duration: 0.7s, 0.2s;
transition-timing-function: ease-in, ease-in;
}
#anbu-closed-tabs a, #anbu-closed-tabs a:visited
{
padding: 0.85em 1.2em 0.85em 1.2em !important;
}
.anbu-tabs a:hover
{
background-color:#333 !important;
color:#fff !important;
}
.anbu-tabs a.anbu-active-tab
{
color:#fff !important;
background-color:#333 !important;
}
.anbu a:focus
{
outline:none !important;
}
.anbu-tabs a:active
{
background-color:#111 !important;
}
.anbu-tabs li.anbu-tab-right
{
float:right !important;
}
.anbu-tabs li.anbu-tab-right a, .anbu-tabs li.anbu-tab-right a:visited
{
padding: 0.86em 2em 0.7em 2em !important;
}
#anbu-closed-tabs
{
display:none;
}
.anbu-window
{
display:none;
}
.anbu-content-area
{
background-color: #fff !important;
background-image: -webkit-gradient(linear, left top, left bottom, from(#eeeeee), to(#ffffff));
background-image: -webkit-linear-gradient(top, #eeeeee, #ffffff);
background-image: -moz-linear-gradient(top, #eeeeee, #ffffff);
background-image: -ms-linear-gradient(top, #eeeeee, #ffffff);
background-image: -o-linear-gradient(top, #eeeeee, #ffffff);
background-image: linear-gradient(to bottom, #eeeeee, #ffffff);
height:14em;
margin-top:6px !important;
overflow-x:hidden !important;
overflow-y:auto !important;
}
.anbu-table table
{
margin:0 !important;
padding:0 !important;
font-size:0.9em !important;
border:0 !important;
border-collapse:collapse !important;
width:100% !important;
background-color:#fff !important;
}
.anbu-table pre
{
margin:0 !important;
}
.anbu-table tr
{
border-bottom:1px solid #ccc !important;
}
.anbu-table tr:first-child
{
border:0 !important;
}
.anbu-table th
{
background-color:#555 !important;
color:#fff !important;
text-transform:uppercase !important;
}
.anbu-table th, .anbu-table td
{
text-align:left !important;
padding:0.4em 1em !important;
margin:0 !important;
}
.anbu-table td
{
vertical-align:top !important;
}
.anbu-table-first
{
background-color:#eee !important;
border-right:1px solid #ccc !important;
width:10% !important;
}
span.anbu-count
{
margin-left:0.5em !important;
background-color:#555 !important;
display:inline-block !important;
padding:0.1em 0.5em 0.2em 0.5em !important;
color:#eee !important;
text-shadow:0 0 4px #000 !important;
-webkit-border-radius: 1px;
-moz-border-radius: 1px;
border-radius: 1px;
-moz-background-clip: padding; -webkit-background-clip: padding-box; background-clip: padding-box;
}
.anbu-empty
{
display:block !important;
padding:1em !important;
text-align:center !important;
font-style:italic !important;
color:#ccc !important;
margin:1em !important;
text-shadow:0 1px 0px #fff !important;
}
.anbu pre
{
overflow-x: auto;
white-space: pre-wrap;
white-space: -moz-pre-wrap !important;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}
/*
Anbu Profiler
Copyright 2012 Dayle Rees.
MIT License <http://www.opensource.org/licenses/mit>
Intended for inclusion with the Laravel PHP Framework.
*/
var anbu = {
// BOUND ELEMENTS
// -------------------------------------------------------------
// Binding these elements early, stops jQuery from "querying"
// the DOM every time they are used.
el : {
main : $('.anbu'),
close : $('#anbu-close'),
zoom : $('#anbu-zoom'),
hide : $('#anbu-hide'),
show : $('#anbu-show'),
tab_pane : $('.anbu-tab-pane'),
hidden_tab_pane : $('.anbu-tab-pane:visible'),
tab : $('.anbu-tab'),
tabs : $('.anbu-tabs'),
tab_links : $('.anbu-tabs a'),
window : $('.anbu-window'),
closed_tabs : $('#anbu-closed-tabs'),
open_tabs : $('#anbu-open-tabs'),
content_area : $('.anbu-content-area')
},
// CLASS ATTRIBUTES
// -------------------------------------------------------------
// Useful variable for Anbu.
isZoomed : false, // is anbu in full screen mode
small_height : $('.anbu-content-area').height(), // initial height of content area
active_tab : 'anbu-active-tab', // the name of the active tab css
tab_data : 'data-anbu-tab', // the data attribute of the tab link
mini_button_width : '2.6em', // size of anbu when compact
window_open : false, // is the top window open?
active_pane : '', // current active pane
// START()
// -------------------------------------------------------------
// Sets up all the binds for Anbu!
start : function ()
{
// hide initial elements
anbu.el.close.hide();
anbu.el.zoom.hide();
anbu.el.tab_pane.hide();
// bind all click events
anbu.el.close.click( function () { anbu.close_window(); });
anbu.el.hide.click( function () { anbu.hide(); });
anbu.el.show.click( function () { anbu.show(); });
anbu.el.zoom.click( function () { anbu.zoom(); });
anbu.el.tab.click( function () { anbu.clicked_tab($(this)); });
},
// CLICKED_TAB()
// -------------------------------------------------------------
// A tab has been clicked, decide what to do.
clicked_tab : function (tab)
{
// if the tab is closed
if(anbu.window_open && anbu.active_pane == tab.attr(anbu.tab_data))
{
anbu.close_window();
}
else
{
anbu.open_window(tab);
}
},
// OPEN_WINDOW()
// -------------------------------------------------------------
// Animate open the top window to the appropriate tab.
open_window : function (tab)
{
// can't directly assign this line, but it works
$('.anbu-tab-pane:visible').fadeOut(200);
$('.' + tab.attr(anbu.tab_data)).delay(220).fadeIn(300);
anbu.el.tab_links.removeClass(anbu.active_tab);
tab.addClass(anbu.active_tab);
anbu.el.window.slideDown(300);
anbu.el.close.fadeIn(300);
anbu.el.zoom.fadeIn(300);
anbu.active_pane = tab.attr(anbu.tab_data);
anbu.window_open = true;
},
// CLOSE_WINDOW()
// -------------------------------------------------------------
// Animate closed the top window hiding all tabs.
close_window : function()
{
anbu.el.tab_pane.fadeOut(100);
anbu.el.window.slideUp(300);
anbu.el.close.fadeOut(300);
anbu.el.zoom.fadeOut(300);
anbu.el.tab_links.removeClass(anbu.active_tab);
anbu.active_pane = '';
anbu.window_open = false;
},
// SHOW()
// -------------------------------------------------------------
// Show the Anbu toolbar when it has been compacted.
show : function ()
{
anbu.el.closed_tabs.fadeOut(600, function () {
anbu.el.open_tabs.fadeIn(200);
})
anbu.el.main.animate({width: '100%'}, 700);
},
// HIDE()
// -------------------------------------------------------------
// Hide the anbu toolbar, show a tiny re-open button.
hide : function ()
{
anbu.close_window();
anbu.el.window.slideUp(400, function () {
anbu.close_window();
anbu.el.open_tabs.fadeOut(200, function () {
anbu.el.closed_tabs.fadeIn(200);
})
anbu.el.main.animate({width: anbu.mini_button_width}, 700);
});
},
// TOGGLEZOOM()
// -------------------------------------------------------------
// Toggle the zoomed mode of the top window.
zoom : function ()
{
if(anbu.isZoomed)
{
height = anbu.small_height;
anbu.isZoomed = false;
}
else
{
// the 6px is padding on the top of the window
height = ($(window).height() - anbu.el.tabs.height() - 6) + 'px';
anbu.isZoomed = true;
}
anbu.el.content_area.animate({height: height}, 700);
}
}
jQuery(document).ready(function () {
// launch anbu
anbu.start();
});
<?php namespace Laravel\Anbu;
use Laravel\View;
use Laravel\File;
use Laravel\Config;
/**
* Anbu, the light weight profiler for Laravel.
*
* Anbu is intended for inclusion with the Laravel framework.
*
* @author Dayle Rees <me@daylerees.com>
* @copyright 2012 Dayle Rees <me@daylerees.com>
* @license MIT License <http://www.opensource.org/licenses/mit>
*/
class Anbu {
/**
* An array of log entries recorded.
*
* @var array
*/
private static $logs = array();
/**
* Am array of SQL queries executed.
*
* @var array
*/
private static $queries = array();
/**
* Render Anbu, assign view params and echo out the main view.
*
* @return void
*/
public static function render()
{
$data = array(
'anbu_logs' => static::$logs,
'anbu_queries' => static::$queries,
'anbu_css' => File::get(path('sys').'anbu/anbu.css'),
'anbu_js' => File::get(path('sys').'anbu/anbu.js'),
'anbu_config' => Config::get('anbu')
);
echo View::make('path: '.path('sys').'anbu/template.php', $data)->render();
}
/**
* Add a log entry to the log entries array.
*
* @return void
*/
public static function log($type, $message)
{
static::$logs[] = array($type, $message);
}
/**
* Add a performed SQL query to Anbu.
*
* @param string $sql
* @param array $bindings
* @param float $time
* @return void
*/
public static function sql($sql, $bindings, $time)
{
// I used this method to swap in the bindings, its very ugly
// will be replaced later, hopefully will find something in
// the core
foreach ($bindings as $b)
{
$count = 1;
$sql = str_replace('?', '`'.$b.'`', $sql,$count);
}
static::$queries[] = array($sql, $time);
}
/**
* Start Anbu's event listeners.
*
* @return void
*/
public static function register()
{
// load the event listeners from a closure in the
// anbu config file, this allows the user to easily
// modify them
$listener = Config::get('anbu.event_listeners');
$listener();
}
}
<!-- ANBU - LARAVEL PROFILER -->
<style type="text/css"><?php echo $anbu_css ?></style>
<div class="anbu">
<div class="anbu-window">
<div class="anbu-content-area">
<?php if ($anbu_config['tab_logs']) : ?>
<div class="anbu-tab-pane anbu-table anbu-log">
<?php if (count($anbu_logs)) : ?>
<table>
<tr>
<th>Type</th>
<th>Message</th>
</tr>
<?php foreach($anbu_logs as $l) : ?>
<tr>
<td class="anbu-table-first"><?php echo $l[0]; ?></td>
<td><?php print_r($l[1]); ?></td>
<?php endforeach; ?>
</tr>
</table>
<?php else : ?>
<span class="anbu-empty">There are no log entries.</span>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($anbu_config['tab_queries']) : ?>
<div class="anbu-tab-pane anbu-table anbu-sql">
<?php if (count($anbu_queries)) : ?>
<table>
<tr>
<th>Time</th>
<th>Query</th>
</tr>
<?php foreach($anbu_queries as $s) : ?>
<tr>
<td class="anbu-table-first"><?php echo $s[1]; ?>ms</td>
<td><pre><?php print_r($s[0]); ?></pre></td>
<?php endforeach; ?>
</tr>
</table>
<?php else : ?>
<span class="anbu-empty">There have been no SQL queries executed.</span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<ul id="anbu-open-tabs" class="anbu-tabs">
<?php if ($anbu_config['tab_logs']) : ?><li><a data-anbu-tab="anbu-log" class="anbu-tab" href="#">Log <span class="anbu-count"><?php echo count($anbu_logs); ?></span></a></li><?php endif; ?>
<?php if ($anbu_config['tab_queries']) : ?><li><a data-anbu-tab="anbu-sql" class="anbu-tab" href="#">SQL <span class="anbu-count"><?php echo count($anbu_queries); ?></span></a></li><?php endif; ?>
<li class="anbu-tab-right"><a id="anbu-hide" href="#">&#8614;</a></li>
<li class="anbu-tab-right"><a id="anbu-close" href="#">&times;</a></li>
<li class="anbu-tab-right"><a id="anbu-zoom" href="#">&#8645;</a></li>
</ul>
<ul id="anbu-closed-tabs" class="anbu-tabs">
<li><a id="anbu-show" href="#">&#8612;</a></li>
</ul>
</div>
<?php if ($anbu_config['include_jquery']) : ?><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><?php endif; ?>
<script><?php echo $anbu_js ?></script>
<!-- /ANBU - LARAVEL PROFILER -->
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment