A modest collection of PHP libraries used at SparkFun.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. <?php
  2. /**
  3. * SparkException
  4. *
  5. * user-level application exceptions
  6. *
  7. * @author Ben LeMasurier <ben@sparkfun.com>
  8. */
  9. namespace SparkLib\Exception;
  10. use \SparkLib\Blode\Event;
  11. class SparkException extends \Exception
  12. {
  13. protected $_action = 'index';
  14. protected $_app_name = '';
  15. protected $_controller = 'index';
  16. protected $_params = '';
  17. // require a message which will be displayed to the user
  18. public function __construct($message, $code = 0, Exception $previous = null) {
  19. Event::debug(array(
  20. 'event' => 'SparkException:' . $message,
  21. 'app' => get_class($this),
  22. 'path' => $_SERVER['REQUEST_URI'],
  23. 'remote_addr' => $_SERVER['REMOTE_ADDR']
  24. ));
  25. parent::__construct($message, $code, $previous);
  26. }
  27. public function action() { return $this->_action; }
  28. public function appName() { return $this->_app_name; }
  29. public function controller() { return $this->_controller; }
  30. public function params() { return $this->_params; }
  31. // these are user-level exceptions, never display a stack-trace.
  32. public function __toString() { return $this->message; }
  33. }