Register.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\Models\Whmcs\Errors;
  3. /**
  4. * Register Error in WHMCS Module Log
  5. *
  6. * @autor ThurData <info@thrudata.ch>
  7. */
  8. class Register extends \ThurData\Servers\KerioEmail\Core\HandlerError\Exceptions\Exception
  9. {
  10. protected $exception = null;
  11. /**
  12. * Register Exception in WHMCS Module Log
  13. *
  14. * @autor ThurData <info@thrudata.ch>
  15. * @param Exception $exc
  16. */
  17. static function register($exc)
  18. {
  19. if (!self::isExceptionLogable($exc))
  20. {
  21. return;
  22. }
  23. $debug = var_export($exc, true);
  24. \logModuleCall("Error", __NAMESPACE__, [
  25. 'message' => $exc->getMessage(),
  26. 'code' => $exc->getCode(),
  27. 'token' => self::getToken($exc),
  28. ],
  29. $debug, 0, 0);
  30. }
  31. /**
  32. * Returns an error token string
  33. * @return type string
  34. */
  35. public static function getToken($exception)
  36. {
  37. $token = 'Unknow Token';
  38. if (method_exists($exception, 'getToken'))
  39. {
  40. $token = $exception->getToken();
  41. }
  42. return $token;
  43. }
  44. /**
  45. * Checks if the exception can be logged
  46. * @return boolean
  47. */
  48. public static function isExceptionLogable($exception = null)
  49. {
  50. if (method_exists($exception, 'isLogable'))
  51. {
  52. return $exception->isLogable();
  53. }
  54. return false;
  55. }
  56. }