Commit 1ca7d799 authored by Taylor Otwell's avatar Taylor Otwell

changes

parent daea5fee
<?php
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 <body> 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');
},
);
...@@ -38,14 +38,24 @@ return array( ...@@ -38,14 +38,24 @@ return array(
| remain secret and should not be shared with anyone. Make it about 32 | remain secret and should not be shared with anyone. Make it about 32
| characters of random gibberish. | 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!', '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 | Application Character Encoding
...@@ -116,7 +126,6 @@ return array( ...@@ -116,7 +126,6 @@ return array(
*/ */
'aliases' => array( 'aliases' => array(
'Anbu' => 'Laravel\\Anbu\\Anbu',
'Auth' => 'Laravel\\Auth', 'Auth' => 'Laravel\\Auth',
'Asset' => 'Laravel\\Asset', 'Asset' => 'Laravel\\Asset',
'Autoloader' => 'Laravel\\Autoloader', 'Autoloader' => 'Laravel\\Autoloader',
...@@ -141,6 +150,7 @@ return array( ...@@ -141,6 +150,7 @@ return array(
'Log' => 'Laravel\\Log', 'Log' => 'Laravel\\Log',
'Memcached' => 'Laravel\\Memcached', 'Memcached' => 'Laravel\\Memcached',
'Paginator' => 'Laravel\\Paginator', 'Paginator' => 'Laravel\\Paginator',
'Profiler' => 'Laravel\\Profiling\\Profiler',
'URL' => 'Laravel\\URL', 'URL' => 'Laravel\\URL',
'Redirect' => 'Laravel\\Redirect', 'Redirect' => 'Laravel\\Redirect',
'Redis' => 'Laravel\\Redis', 'Redis' => 'Laravel\\Redis',
......
...@@ -35,6 +35,12 @@ ...@@ -35,6 +35,12 @@
Route::get('/', function() 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'); return View::make('home.index');
}); });
......
...@@ -125,20 +125,6 @@ Event::listen(Lang::loader, function($bundle, $language, $file) ...@@ -125,20 +125,6 @@ Event::listen(Lang::loader, function($bundle, $language, $file)
Blade::sharpen(); 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 | Set The Default Timezone
......
<?php namespace Laravel\Anbu;
use Laravel\View;
use Laravel\File;
use Laravel\Config;
use Laravel\Event;
/**
* 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();
// echo anbu on laravel.done if enabled
if(Config::get('anbu.enable'))
{
Event::listen('laravel.done', function() {
Anbu::render();
});
}
}
}
...@@ -143,6 +143,22 @@ Input::$input = $input; ...@@ -143,6 +143,22 @@ Input::$input = $input;
Bundle::start(DEFAULT_BUNDLE); 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 | Auto-Start Other Bundles
......
/*
Anbu Styles
Copyright 2012 Dayle Rees.
MIT License <http://www.opensource.org/licenses/mit>
Intended for inclusion with the Laravel PHP Framework.
*/
.anbu .anbu
{ {
font-family:Helvetica, "Helvetica Neue", Arial, sans-serif !important; font-family:Helvetica, "Helvetica Neue", Arial, sans-serif !important;
......
/*
Anbu Profiler
Copyright 2012 Dayle Rees.
MIT License <http://www.opensource.org/licenses/mit>
Intended for inclusion with the Laravel PHP Framework.
*/
var anbu = { var anbu = {
// BOUND ELEMENTS // BOUND ELEMENTS
...@@ -170,5 +163,3 @@ jQuery(document).ready(function () { ...@@ -170,5 +163,3 @@ jQuery(document).ready(function () {
// launch anbu // launch anbu
anbu.start(); anbu.start();
}); });
\ No newline at end of file
<?php namespace Laravel\Profiling;
use Laravel\View;
use Laravel\File;
use Laravel\Event;
use Laravel\Config;
class Profiler {
/**
* An array of the recorded Profiler data.
*
* @var array
*/
protected static $data = array('queries' => 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();
});
}
}
<!-- ANBU - LARAVEL PROFILER --> <!-- ANBU - LARAVEL PROFILER -->
<style type="text/css"><?php echo $anbu_css ?></style> <style type="text/css">{{ file_get_contents(path('sys').'profiling/profiler.css') }}</style>
<div class="anbu"> <div class="anbu">
<div class="anbu-window"> <div class="anbu-window">
<div class="anbu-content-area"> <div class="anbu-content-area">
<?php if ($anbu_config['tab_logs']) : ?>
<div class="anbu-tab-pane anbu-table anbu-log"> <div class="anbu-tab-pane anbu-table anbu-log">
<?php if (count($anbu_logs)) : ?> @if (count($logs) > 0)
<table> <table>
<tr> <tr>
<th>Type</th> <th>Type</th>
<th>Message</th> <th>Message</th>
</tr> </tr>
<?php foreach($anbu_logs as $l) : ?> @foreach ($logs as $log)
<tr> <tr>
<td class="anbu-table-first"><?php echo $l[0]; ?></td> <td class="anbu-table-first">
<td><?php print_r($l[1]); ?></td> {{ $log[0] }}
<?php endforeach; ?> </td>
<td>
{{ print_r($log[1]) }}
</td>
@endforeach
</tr> </tr>
</table> </table>
<?php else : ?> @else
<span class="anbu-empty">There are no log entries.</span> <span class="anbu-empty">There are no log entries.</span>
<?php endif; ?> @endif
</div> </div>
<?php endif; ?>
<?php if ($anbu_config['tab_queries']) : ?>
<div class="anbu-tab-pane anbu-table anbu-sql"> <div class="anbu-tab-pane anbu-table anbu-sql">
<?php if (count($anbu_queries)) : ?> @if (count($queries) > 0)
<table> <table>
<tr> <tr>
<th>Time</th> <th>Time</th>
<th>Query</th> <th>Query</th>
</tr> </tr>
<?php foreach($anbu_queries as $s) : ?> @foreach ($queries as $query)
<tr> <tr>
<td class="anbu-table-first"><?php echo $s[1]; ?>ms</td> <td class="anbu-table-first">
<td><pre><?php print_r($s[0]); ?></pre></td> {{ $query[1] }}ms
<?php endforeach; ?> </td>
<td>
<pre>{{ print_r($query[0]) }}</pre>
</td>
</tr> </tr>
@endforeach
</table> </table>
<?php else : ?> @else
<span class="anbu-empty">There have been no SQL queries executed.</span> <span class="anbu-empty">There have been no SQL queries executed.</span>
<?php endif; ?> @endif
</div> </div>
<?php endif; ?>
</div> </div>
</div> </div>
<ul id="anbu-open-tabs" class="anbu-tabs"> <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; ?> <li><a data-anbu-tab="anbu-log" class="anbu-tab" href="#">Log <span class="anbu-count">{{ count($logs) }}</span></a></li>
<?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><a data-anbu-tab="anbu-sql" class="anbu-tab" href="#">SQL <span class="anbu-count">{{ count($queries) }}</span></a></li>
<li class="anbu-tab-right"><a id="anbu-hide" href="#">&#8614;</a></li> <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-close" href="#">&times;</a></li>
<li class="anbu-tab-right"><a id="anbu-zoom" href="#">&#8645;</a></li> <li class="anbu-tab-right"><a id="anbu-zoom" href="#">&#8645;</a></li>
...@@ -58,6 +63,7 @@ ...@@ -58,6 +63,7 @@
<li><a id="anbu-show" href="#">&#8612;</a></li> <li><a id="anbu-show" href="#">&#8612;</a></li>
</ul> </ul>
</div> </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> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>{{ file_get_contents(path('sys').'profiling/profiler.js') }}</script>
<!-- /ANBU - LARAVEL PROFILER --> <!-- /ANBU - LARAVEL PROFILER -->
\ No newline at end of file
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