From 66ff8a4076c635e9e4aa31ef4f856d635af48038 Mon Sep 17 00:00:00 2001 From: Dayle Rees Date: Wed, 28 Mar 2012 10:30:51 +0100 Subject: [PATCH] integrated a simple version of anbu into the laravel core Signed-off-by: Dayle Rees --- application/config/anbu.php | 59 +++++++++ application/start.php | 16 ++- application/views/home/index.php | 3 +- laravel/anbu/anbu.css | 207 +++++++++++++++++++++++++++++++ laravel/anbu/anbu.js | 174 ++++++++++++++++++++++++++ laravel/anbu/anbu.php | 97 +++++++++++++++ laravel/anbu/template.php | 63 ++++++++++ 7 files changed, 617 insertions(+), 2 deletions(-) create mode 100644 application/config/anbu.php mode change 100644 => 100755 application/start.php mode change 100644 => 100755 application/views/home/index.php create mode 100755 laravel/anbu/anbu.css create mode 100755 laravel/anbu/anbu.js create mode 100755 laravel/anbu/anbu.php create mode 100755 laravel/anbu/template.php diff --git a/application/config/anbu.php b/application/config/anbu.php new file mode 100644 index 00000000..9b6503ee --- /dev/null +++ b/application/config/anbu.php @@ -0,0 +1,59 @@ + 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'); + }, + +); diff --git a/application/start.php b/application/start.php old mode 100644 new mode 100755 index 085dd090..a6fd4f70 --- a/application/start.php +++ b/application/start.php @@ -125,6 +125,20 @@ 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 +| tag of your main template, or page. +| +*/ + +Anbu::register(); + /* |-------------------------------------------------------------------------- | Set The Default Timezone @@ -154,4 +168,4 @@ if ( ! Request::cli() and Config::get('session.driver') !== '') { Session::load(); -} \ No newline at end of file +} diff --git a/application/views/home/index.php b/application/views/home/index.php old mode 100644 new mode 100755 index 156c36ab..980248f3 --- a/application/views/home/index.php +++ b/application/views/home/index.php @@ -88,6 +88,7 @@ +

Welcome To Laravel

@@ -126,4 +127,4 @@
- \ No newline at end of file + diff --git a/laravel/anbu/anbu.css b/laravel/anbu/anbu.css new file mode 100755 index 00000000..343b011c --- /dev/null +++ b/laravel/anbu/anbu.css @@ -0,0 +1,207 @@ +/* +Anbu Styles +Copyright 2012 Dayle Rees. +MIT License +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; +} diff --git a/laravel/anbu/anbu.js b/laravel/anbu/anbu.js new file mode 100755 index 00000000..8f86fe35 --- /dev/null +++ b/laravel/anbu/anbu.js @@ -0,0 +1,174 @@ +/* +Anbu Profiler +Copyright 2012 Dayle Rees. +MIT License +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(); +}); + + diff --git a/laravel/anbu/anbu.php b/laravel/anbu/anbu.php new file mode 100755 index 00000000..693d4b03 --- /dev/null +++ b/laravel/anbu/anbu.php @@ -0,0 +1,97 @@ + + * @copyright 2012 Dayle Rees + * @license MIT License + */ +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(); + } + +} diff --git a/laravel/anbu/template.php b/laravel/anbu/template.php new file mode 100755 index 00000000..bb767e3e --- /dev/null +++ b/laravel/anbu/template.php @@ -0,0 +1,63 @@ + + +
+
+
+ +
+ + + + + + + + + + + + +
TypeMessage
+ + There are no log entries. + +
+ + +
+ + + + + + + + + + + + +
TimeQuery
ms
+ + There have been no SQL queries executed. + +
+ + +
+
+ + + +
+ + +