diff --git a/application/config/application.php b/application/config/application.php old mode 100644 new mode 100755 index c5f5a3ba..8cbf104a --- 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 @@ -140,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', @@ -157,4 +168,4 @@ 'View' => 'Laravel\\View', ), -); \ No newline at end of file +); 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 old mode 100644 new mode 100755 index 085dd090..8d2db780 --- a/application/start.php +++ b/application/start.php @@ -154,4 +154,4 @@ if ( ! Request::cli() and Config::get('session.driver') !== '') { Session::load(); -} \ No newline at end of file +} 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/profiling/profiler.css b/laravel/profiling/profiler.css new file mode 100755 index 00000000..1fb4e52f --- /dev/null +++ b/laravel/profiling/profiler.css @@ -0,0 +1,200 @@ +.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/profiling/profiler.js b/laravel/profiling/profiler.js new file mode 100755 index 00000000..f91ad18f --- /dev/null +++ b/laravel/profiling/profiler.js @@ -0,0 +1,165 @@ +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(); +}); \ 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