ErrorHandler.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class Raven_Breadcrumbs_ErrorHandler
  3. {
  4. protected $existingHandler;
  5. /**
  6. * @var Raven_Client the client object that sends the message to the server
  7. */
  8. protected $ravenClient;
  9. /**
  10. * @param Raven_Client $ravenClient
  11. */
  12. public function __construct(Raven_Client $ravenClient)
  13. {
  14. $this->ravenClient = $ravenClient;
  15. }
  16. public function handleError($code, $message, $file = '', $line = 0, $context = array())
  17. {
  18. $this->ravenClient->breadcrumbs->record(array(
  19. 'category' => 'error_reporting',
  20. 'message' => $message,
  21. 'level' => $this->ravenClient->translateSeverity($code),
  22. 'data' => array(
  23. 'code' => $code,
  24. 'line' => $line,
  25. 'file' => $file,
  26. ),
  27. ));
  28. if ($this->existingHandler !== null) {
  29. return call_user_func($this->existingHandler, $code, $message, $file, $line, $context);
  30. } else {
  31. return false;
  32. }
  33. }
  34. public function install()
  35. {
  36. $this->existingHandler = set_error_handler(array($this, 'handleError'), E_ALL);
  37. return $this;
  38. }
  39. }