mirror of
https://github.com/filp/whoops.git
synced 2026-09-12 18:56:22 +00:00
Add PrettyPageHandler::addDataTable & example
This commit is contained in:
+12
-2
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user