Skip to content

Commit

Permalink
Fixes #7: notices when toolbar does not need to be shown
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano committed Jan 11, 2012
1 parent c9b25f9 commit 1ad971d
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions config/bootstrap/dispatcher.php
Expand Up @@ -51,15 +51,56 @@
// Render the toolbar (unless it's an asset from the li3_perf library) // Render the toolbar (unless it's an asset from the li3_perf library)
// Why? See li3_perf\extensions\util\Asset // Why? See li3_perf\extensions\util\Asset
if(!isset($params['request']->params['asset_type'])) { if(!isset($params['request']->params['asset_type'])) {
$skip = false;
$li3_perf = Libraries::get('li3_perf');
if(isset($li3_perf['skip'])) {
$controller = isset($params['request']->params['controller']) ? $params['request']->params['controller']:null;
$action = isset($params['request']->params['action']) ? $params['request']->params['action']:null;
$library = isset($params['request']->params['library']) ? $params['request']->params['library']:null;

// Check to see if the toolbar should be shown for this library
if(isset($li3_perf['skip']['library'])) {
if(in_array($library, $li3_perf['skip']['library'])) {
$skip = true;
}
}

// Check to see if the toolbar should be shown for this controller
if(isset($li3_perf['skip']['controller'])) {
if(in_array($controller, $li3_perf['skip']['controller'])) {
$skip = true;
}
}

// Check to see if the toolbar should be shown for this action
if(isset($li3_perf['skip']['action'])) {
if(in_array($action, $li3_perf['skip']['action'])) {
$skip = true;
}
}
}

if ($skip || !isset($result->body[0])) {
return $result;
}

$timers = Data::get('timers') + array(
'li3_perf_start' => 0,
'li3_perf_end' => 0,
'li3_perf_start_dispatch' => 0,
'li3_perf_has_route' => 0,
'li3_perf_start_call' => 0,
'li3_perf_end_call' => 0,
'_filter_for_variables' => 0,
'_filter_for_queries' => 0
);

$View = new View(array( $View = new View(array(
'paths' => array( 'paths' => array(
'template' => '{:library}/views/elements/{:template}.{:type}.php', 'template' => '{:library}/views/elements/{:template}.{:type}.php',
'layout' => '{:library}/views/layouts/{:layout}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php',
) )
)); ));

$timers = Data::get('timers');

$toolbar = $View->render('all', $toolbar = $View->render('all',
array( array(
'timers' => $timers += array( 'timers' => $timers += array(
Expand Down Expand Up @@ -87,38 +128,7 @@
// There are sometimes issues with the headers already being sent otherwise. // There are sometimes issues with the headers already being sent otherwise.
// TODO: IF proper HTML were to be desired, perhaps insert $toolbar into the body in the // TODO: IF proper HTML were to be desired, perhaps insert $toolbar into the body in the
// proper spot within the HTML. // proper spot within the HTML.
$skip = false; $result->body[0] = $toolbar . $result->body[0];
$li3_perf = Libraries::get('li3_perf');
if(isset($li3_perf['skip'])) {
$controller = isset($params['request']->params['controller']) ? $params['request']->params['controller']:null;
$action = isset($params['request']->params['action']) ? $params['request']->params['action']:null;
$library = isset($params['request']->params['library']) ? $params['request']->params['library']:null;

// Check to see if the toolbar should be shown for this library
if(isset($li3_perf['skip']['library'])) {
if(in_array($library, $li3_perf['skip']['library'])) {
$skip = true;
}
}

// Check to see if the toolbar should be shown for this controller
if(isset($li3_perf['skip']['controller'])) {
if(in_array($controller, $li3_perf['skip']['controller'])) {
$skip = true;
}
}

// Check to see if the toolbar should be shown for this action
if(isset($li3_perf['skip']['action'])) {
if(in_array($action, $li3_perf['skip']['action'])) {
$skip = true;
}
}
}

if(isset($result->body[0]) && !$skip) {
$result->body[0] = $toolbar . $result->body[0];
}
} }


return $result; return $result;
Expand Down

0 comments on commit 1ad971d

Please sign in to comment.