Add PrettyPageHandler::addDataTable & example

This commit is contained in:
filp
2013-03-14 11:34:43 +00:00
parent 728d8f0337
commit a23dfa9c66
2 changed files with 49 additions and 2 deletions
+12 -2
View File
@@ -22,8 +22,18 @@ require __DIR__ . '/../vendor/autoload.php';
class Exception extends BaseException {}
$run = new Run;
$run->pushHandler(new PrettyPageHandler);
$run = new Run;
$handler = new PrettyPageHandler;
// Add a custom table to the layout:
$handler->addDataTable('Ice-cream I like', array(
'Chocolate' => 'yes',
'Coffee & chocolate' => 'a lot',
'Strawberry & chocolate' => 'it\'s alright',
'Vanilla' => 'ew'
));
$run->pushHandler($handler);
// Example: tag all frames with a comment
$run->pushHandler(function($exception, $inspector, $run) {
+37
View File
@@ -15,6 +15,11 @@ class PrettyPageHandler extends Handler
*/
private $resourcesPath;
/**
* @var array[]
*/
private $extraTables = array();
/**
* @return int|null
*/
@@ -57,6 +62,9 @@ class PrettyPageHandler extends Handler
)
);
// Add extra entries to the "super" list of data tables:
$v->super = array_merge($v->super, $this->getDataTables());
call_user_func(function() use($templateFile, $v) {
// $e -> cleanup output
$e = function($_) { return htmlspecialchars($_, ENT_QUOTES, 'UTF-8'); };
@@ -74,6 +82,35 @@ class PrettyPageHandler extends Handler
return Handler::LAST_HANDLER;
}
/**
* Adds an entry to the list of superglobals displayed in the template.
* The expected data is a simple associative array. Any nested arrays
* will be flattened with print_r
* @param string $label
* @param array $data
*/
public function addDataTable($label, array $data)
{
$this->extraTables[$label] = $data;
}
/**
* Returns all the extra data tables registered with this handler.
* Optionally accepts a 'label' parameter, to only return the data
* table under that label.
* @param string|null $label
* @return array[]
*/
public function getDataTables($label = null)
{
if($label !== null) {
return isset($this->extraTables[$label]) ?
$this->extraTables[$labe] : array();
}
return $this->extraTables;
}
/**
* @return string
*/