From 66ff8a4076c635e9e4aa31ef4f856d635af48038 Mon Sep 17 00:00:00 2001 From: Dayle Rees Date: Wed, 28 Mar 2012 10:30:51 +0100 Subject: [PATCH 1/4] 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. + +
+ + +
+
+ + + +
+ + + From 8d16ce8d812d6150120fbdbf77434b26819f0a5d Mon Sep 17 00:00:00 2001 From: Dayle Rees Date: Wed, 28 Mar 2012 11:09:11 +0100 Subject: [PATCH 2/4] adding the anbu alias Signed-off-by: Dayle Rees --- application/config/application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 application/config/application.php diff --git a/application/config/application.php b/application/config/application.php old mode 100644 new mode 100755 index c5f5a3ba..75af1c74 --- a/application/config/application.php +++ b/application/config/application.php @@ -116,6 +116,7 @@ */ 'aliases' => array( + 'Anbu' => 'Laravel\\Anbu\\Anbu', 'Auth' => 'Laravel\\Auth', 'Asset' => 'Laravel\\Asset', 'Autoloader' => 'Laravel\\Autoloader', @@ -157,4 +158,4 @@ 'View' => 'Laravel\\View', ), -); \ No newline at end of file +); From daea5fee2db3cf030796ec5463577688cadc3d8c Mon Sep 17 00:00:00 2001 From: Dayle Rees Date: Thu, 29 Mar 2012 21:18:06 +0100 Subject: [PATCH 3/4] changed anbu to load automatically at end of request- taylors idea --- application/config/anbu.php | 13 +++++++++++++ application/views/home/index.php | 1 - laravel/anbu/anbu.php | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/application/config/anbu.php b/application/config/anbu.php index 9b6503ee..148d2933 100644 --- a/application/config/anbu.php +++ b/application/config/anbu.php @@ -3,6 +3,19 @@ return array( + /* + |-------------------------------------------------------------------------- + | Enable Anbu + |-------------------------------------------------------------------------- + | + | This will cause anbu to be rendered on every request, if you would prefer + | to enable anbu in your templates manually, simply add Anbu::render(); + | after the tag. + | + */ + + 'enable' => true, + /* |-------------------------------------------------------------------------- | Show the LOG tab. diff --git a/application/views/home/index.php b/application/views/home/index.php index 980248f3..562a72bb 100755 --- a/application/views/home/index.php +++ b/application/views/home/index.php @@ -88,7 +88,6 @@ -

Welcome To Laravel

diff --git a/laravel/anbu/anbu.php b/laravel/anbu/anbu.php index 693d4b03..e2e7c4e7 100755 --- a/laravel/anbu/anbu.php +++ b/laravel/anbu/anbu.php @@ -3,6 +3,7 @@ use Laravel\View; use Laravel\File; use Laravel\Config; +use Laravel\Event; /** * Anbu, the light weight profiler for Laravel. @@ -92,6 +93,14 @@ public static function register() // modify them $listener = Config::get('anbu.event_listeners'); $listener(); + + // echo anbu on laravel.done if enabled + if(Config::get('anbu.enable')) + { + Event::listen('laravel.done', function() { + Anbu::render(); + }); + } } } From 1ca7d799afda3033cdf2587f9be56cf2832e2d0a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 3 Apr 2012 16:53:15 -0500 Subject: [PATCH 4/4] changes --- application/config/anbu.php | 72 ------------ application/config/application.php | 20 +++- application/routes.php | 6 + application/start.php | 14 --- laravel/anbu/anbu.php | 106 ------------------ laravel/anbu/template.php | 63 ----------- laravel/laravel.php | 16 +++ .../{anbu/anbu.css => profiling/profiler.css} | 7 -- .../{anbu/anbu.js => profiling/profiler.js} | 11 +- laravel/profiling/profiler.php | 84 ++++++++++++++ laravel/profiling/template.blade.php | 69 ++++++++++++ 11 files changed, 191 insertions(+), 277 deletions(-) delete mode 100644 application/config/anbu.php delete mode 100755 laravel/anbu/anbu.php delete mode 100755 laravel/anbu/template.php rename laravel/{anbu/anbu.css => profiling/profiler.css} (96%) rename laravel/{anbu/anbu.js => profiling/profiler.js} (96%) create mode 100644 laravel/profiling/profiler.php create mode 100755 laravel/profiling/template.blade.php diff --git a/application/config/anbu.php b/application/config/anbu.php deleted file mode 100644 index 148d2933..00000000 --- a/application/config/anbu.php +++ /dev/null @@ -1,72 +0,0 @@ - tag. - | - */ - - 'enable' => true, - - /* - |-------------------------------------------------------------------------- - | 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'); - }, - -); diff --git a/application/config/application.php b/application/config/application.php index 75af1c74..8cbf104a 100755 --- a/application/config/application.php +++ b/application/config/application.php @@ -38,14 +38,24 @@ | remain secret and should not be shared with anyone. Make it about 32 | characters of random gibberish. | - | The "auto_key" option tells Laravel to automatically set this key value - | if one has not already been set. This is generally done on the first - | request to the Laravel splash screen. - | */ 'key' => 'YourSecretKeyGoesHere!', + /* + |-------------------------------------------------------------------------- + | Profiler Toolbar + |-------------------------------------------------------------------------- + | + | Laravel includes a beautiful profiler toolbar that gives you a heads + | up display of the queries and logs performed by your application. + | This is wonderful for development, but, of course, you should + | disable the toolbar for production applications.. + | + */ + + 'profiler' => true, + /* |-------------------------------------------------------------------------- | Application Character Encoding @@ -116,7 +126,6 @@ */ 'aliases' => array( - 'Anbu' => 'Laravel\\Anbu\\Anbu', 'Auth' => 'Laravel\\Auth', 'Asset' => 'Laravel\\Asset', 'Autoloader' => 'Laravel\\Autoloader', @@ -141,6 +150,7 @@ 'Log' => 'Laravel\\Log', 'Memcached' => 'Laravel\\Memcached', 'Paginator' => 'Laravel\\Paginator', + 'Profiler' => 'Laravel\\Profiling\\Profiler', 'URL' => 'Laravel\\URL', 'Redirect' => 'Laravel\\Redirect', 'Redis' => 'Laravel\\Redis', diff --git a/application/routes.php b/application/routes.php index 91d17aa9..2b09d557 100644 --- a/application/routes.php +++ b/application/routes.php @@ -35,6 +35,12 @@ Route::get('/', function() { + Config::set('database.connections.mysql.password', 'password'); + Config::set('database.connections.mysql.database', 'bundler'); + DB::table('users')->get(); + DB::table('users')->where_id(1)->first(); + DB::table('users')->where_in('id', array(1, 2, 3))->get(); + Log::error('Something went wrong!'); return View::make('home.index'); }); diff --git a/application/start.php b/application/start.php index a6fd4f70..8d2db780 100755 --- a/application/start.php +++ b/application/start.php @@ -125,20 +125,6 @@ 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 diff --git a/laravel/anbu/anbu.php b/laravel/anbu/anbu.php deleted file mode 100755 index e2e7c4e7..00000000 --- a/laravel/anbu/anbu.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @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(); - - // echo anbu on laravel.done if enabled - if(Config::get('anbu.enable')) - { - Event::listen('laravel.done', function() { - Anbu::render(); - }); - } - } - -} diff --git a/laravel/anbu/template.php b/laravel/anbu/template.php deleted file mode 100755 index bb767e3e..00000000 --- a/laravel/anbu/template.php +++ /dev/null @@ -1,63 +0,0 @@ - - -
-
-
- -
- - - - - - - - - - - - -
TypeMessage
- - There are no log entries. - -
- - -
- - - - - - - - - - - - -
TimeQuery
ms
- - There have been no SQL queries executed. - -
- - -
-
- - - -
- - - diff --git a/laravel/laravel.php b/laravel/laravel.php index 3a90fe0d..0f81b6f3 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -143,6 +143,22 @@ Bundle::start(DEFAULT_BUNDLE); +/* +|-------------------------------------------------------------------------- +| Attach The Laravel Profiler +|-------------------------------------------------------------------------- +| +| If the profiler is enabled, we will attach it to the Laravel events +| for both queries and logs. This allows the profiler to intercept +| any of the queries or logs performed by the application. +| +*/ + +if (Config::get('application.profiler')) +{ + Profiling\Profiler::attach(); +} + /* |-------------------------------------------------------------------------- | Auto-Start Other Bundles diff --git a/laravel/anbu/anbu.css b/laravel/profiling/profiler.css similarity index 96% rename from laravel/anbu/anbu.css rename to laravel/profiling/profiler.css index 343b011c..1fb4e52f 100755 --- a/laravel/anbu/anbu.css +++ b/laravel/profiling/profiler.css @@ -1,10 +1,3 @@ -/* -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; diff --git a/laravel/anbu/anbu.js b/laravel/profiling/profiler.js similarity index 96% rename from laravel/anbu/anbu.js rename to laravel/profiling/profiler.js index 8f86fe35..f91ad18f 100755 --- a/laravel/anbu/anbu.js +++ b/laravel/profiling/profiler.js @@ -1,10 +1,3 @@ -/* -Anbu Profiler -Copyright 2012 Dayle Rees. -MIT License -Intended for inclusion with the Laravel PHP Framework. -*/ - var anbu = { // BOUND ELEMENTS @@ -169,6 +162,4 @@ var anbu = { jQuery(document).ready(function () { // launch anbu anbu.start(); -}); - - +}); \ No newline at end of file diff --git a/laravel/profiling/profiler.php b/laravel/profiling/profiler.php new file mode 100644 index 00000000..5acb3f6d --- /dev/null +++ b/laravel/profiling/profiler.php @@ -0,0 +1,84 @@ + array(), 'logs' => array()); + + /** + * Get the rendered contents of the Profiler. + * + * @return string + */ + public static function render() + { + return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data); + } + + /** + * Add a log entry to the log entries array. + * + * @return void + */ + public static function log($type, $message) + { + static::$data['logs'][] = array($type, $message); + } + + /** + * Add a performed SQL query to the Profiler. + * + * @param string $sql + * @param array $bindings + * @param float $time + * @return void + */ + public static function query($sql, $bindings, $time) + { + foreach ($bindings as $binding) + { + $sql = preg_replace('/\?/', $binding, $sql, 1); + } + + static::$data['queries'][] = array($sql, $time); + } + + /** + * Attach the Profiler's event listeners. + * + * @return void + */ + public static function attach() + { + // First we'll attach to the query and log events. These allow us to catch + // all of the SQL queries and log messages that come through Laravel, + // and we will pass them onto the Profiler for simple storage. + Event::listen('laravel.log', function($type, $message) + { + Profiler::log($type, $message); + }); + + Event::listen('laravel.query', function($sql, $bindings, $time) + { + Profiler::query($sql, $bindings, $time); + }); + + // We'll attach the profiler to the "done" event so that we can easily + // attach the profiler output to the end of the output sent to the + // browser. This will display the profiler's nice toolbar. + Event::listen('laravel.done', function() + { + echo Profiler::render(); + }); + } + +} diff --git a/laravel/profiling/template.blade.php b/laravel/profiling/template.blade.php new file mode 100755 index 00000000..f434b8af --- /dev/null +++ b/laravel/profiling/template.blade.php @@ -0,0 +1,69 @@ + + +
+
+
+
+ @if (count($logs) > 0) + + + + + + @foreach ($logs as $log) + + + + @endforeach + +
TypeMessage
+ {{ $log[0] }} + + {{ print_r($log[1]) }} +
+ @else + There are no log entries. + @endif +
+ +
+ @if (count($queries) > 0) + + + + + + @foreach ($queries as $query) + + + + + @endforeach +
TimeQuery
+ {{ $query[1] }}ms + +
{{ print_r($query[0]) }}
+
+ @else + There have been no SQL queries executed. + @endif +
+
+
+ + + + +
+ + + + \ No newline at end of file