Register.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\Models\Whmcs\Errors;
  3. /**
  4. * Register Error in WHMCS Module Log
  5. *
  6. * @author Michal Czech <michael@modulesgarden.com>
  7. */
  8. class Register extends \ModulesGarden\ProxmoxAddon\Core\HandlerError\Exceptions\Exception
  9. {
  10. protected $exception = null;
  11. /**
  12. * Register Exception in WHMCS Module Log
  13. *
  14. * @author Michal Czech <michael@modulesgarden.com>
  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. ], $debug, 0, 0);
  29. }
  30. /**
  31. * Returns an error token string
  32. * @return type string
  33. */
  34. public static function getToken($exception)
  35. {
  36. $token = 'Unknow Token';
  37. if (method_exists($exception, 'getToken'))
  38. {
  39. $token = $exception->getToken();
  40. }
  41. return $token;
  42. }
  43. /**
  44. * Checks if the exception can be logged
  45. * @return boolean
  46. */
  47. public static function isExceptionLogable($exception = null)
  48. {
  49. if (method_exists($exception, 'isLogable'))
  50. {
  51. return $exception->isLogable();
  52. }
  53. return false;
  54. }
  55. }