example.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Whoops - php errors for cool kids
  4. * @author Filipe Dobreira <http://github.com/filp>
  5. *
  6. * Run this example file with the PHP 5.4 web server with:
  7. *
  8. * $ cd project_dir
  9. * $ php -S localhost:8080
  10. *
  11. * and access localhost:8080/example/example.php through your browser
  12. *
  13. * Or just run it through apache/nginx/what-have-yous as usual.
  14. */
  15. namespace Whoops\Example;
  16. use Whoops\Run;
  17. use Whoops\Handler\PrettyPageHandler;
  18. use Exception as BaseException;
  19. require __DIR__ . '/../vendor/autoload.php';
  20. class Exception extends BaseException {}
  21. $run = new Run;
  22. $handler = new PrettyPageHandler;
  23. // Add a custom table to the layout:
  24. $handler->addDataTable('Ice-cream I like', array(
  25. 'Chocolate' => 'yes',
  26. 'Coffee & chocolate' => 'a lot',
  27. 'Strawberry & chocolate' => 'it\'s alright',
  28. 'Vanilla' => 'ew'
  29. ));
  30. $run->pushHandler($handler);
  31. // Example: tag all frames inside a function with their function name
  32. $run->pushHandler(function($exception, $inspector, $run) {
  33. $inspector->getFrames()->map(function($frame) {
  34. if($function = $frame->getFunction()) {
  35. $frame->addComment("This frame is within function '$function'", 'cpt-obvious');
  36. }
  37. return $frame;
  38. });
  39. });
  40. $run->register();
  41. function fooBar() {
  42. throw new Exception("Something broke!");
  43. }
  44. function bar()
  45. {
  46. fooBar();
  47. }
  48. bar();