addDataTableCallback() public method

The supplied callback argument will be called when the error is rendered, it should produce a simple associative array. Any nested arrays will be flattened with print_r.
public addDataTableCallback ( string $label, callable $callback )
$label string
$callback callable Callable returning an associative array
コード例 #1
0
ファイル: WhoopsServiceProvider.php プロジェクト: d-m-/bolt
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $app['whoops'] = $app->share(function () use($app) {
         $run = new Run();
         $run->allowQuit(false);
         $run->pushHandler($app['whoops.handler']);
         return $run;
     });
     $app['whoops.handler'] = $app->share(function () use($app) {
         if (PHP_SAPI === 'cli') {
             return $app['whoops.handler.cli'];
         } else {
             return $app['whoops.handler.page'];
         }
     });
     $app['whoops.handler.cli'] = $app->share(function () {
         return new PlainTextHandler();
     });
     $app['whoops.handler.page'] = $app->share(function () use($app) {
         $handler = new PrettyPageHandler();
         $handler->addDataTableCallback('Bolt Application', $app['whoops.handler.page.app_info']);
         $handler->addDataTableCallback('Request', $app['whoops.handler.page.request_info']);
         $handler->setPageTitle('Bolt - Fatal error.');
         return $handler;
     });
     $app['whoops.handler.page.app_info'] = $app->protect(function () use($app) {
         return ['Charset' => $app['charset'], 'Locale' => $app['locale'], 'Route Class' => $app['route_class'], 'Dispatcher Class' => $app['dispatcher_class'], 'Application Class' => get_class($app)];
     });
     $app['whoops.handler.page.request_info'] = $app->protect(function () use($app) {
         /** @var RequestStack $requestStack */
         $requestStack = $app['request_stack'];
         if (!($request = $requestStack->getCurrentRequest())) {
             return [];
         }
         return ['URI' => $request->getUri(), 'Request URI' => $request->getRequestUri(), 'Path Info' => $request->getPathInfo(), 'Query String' => $request->getQueryString() ?: '<none>', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getScriptName(), 'Base Path' => $request->getBasePath(), 'Base URL' => $request->getBaseUrl(), 'Scheme' => $request->getScheme(), 'Port' => $request->getPort(), 'Host' => $request->getHost()];
     });
     $app['whoops.listener'] = $app->share(function () use($app) {
         $showWhileLoggedOff = $app['config']->get('general/debug_show_loggedoff', false);
         return new WhoopsListener($app['whoops'], $app['session'], $showWhileLoggedOff);
     });
 }
コード例 #2
0
ファイル: class-plugin.php プロジェクト: rarst/wps
 /**
  * @param array $values Optional arguments for container.
  */
 public function __construct($values = array())
 {
     $defaults = array();
     $defaults['tables'] = array('$wp' => function () {
         global $wp;
         if (!$wp instanceof \WP) {
             return array();
         }
         $output = get_object_vars($wp);
         unset($output['private_query_vars']);
         unset($output['public_query_vars']);
         return array_filter($output);
     }, '$wp_query' => function () {
         global $wp_query;
         if (!$wp_query instanceof \WP_Query) {
             return array();
         }
         $output = get_object_vars($wp_query);
         $output['query_vars'] = array_filter($output['query_vars']);
         unset($output['posts']);
         unset($output['post']);
         return array_filter($output);
     }, '$post' => function () {
         $post = get_post();
         if (!$post instanceof \WP_Post) {
             return array();
         }
         return get_object_vars($post);
     });
     $defaults['handler.pretty'] = function ($plugin) {
         $handler = new PrettyPageHandler();
         foreach ($plugin['tables'] as $name => $callback) {
             $handler->addDataTableCallback($name, $callback);
         }
         // Requires Remote Call plugin.
         $handler->addEditor('phpstorm-remote-call', 'http://localhost:8091?message=%file:%line');
         return $handler;
     };
     $defaults['handler.json'] = function () {
         $handler = new Admin_Ajax_Handler();
         $handler->addTraceToOutput(true);
         return $handler;
     };
     $defaults['run'] = function ($plugin) {
         $run = new Run();
         $run->pushHandler($plugin['handler.pretty']);
         $run->pushHandler($plugin['handler.json']);
         return $run;
     };
     parent::__construct(array_merge($defaults, $values));
 }