ErrorTrait.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace traits;
  12. /**
  13. *
  14. * Class BaseError
  15. * @package crmeb\basic
  16. */
  17. trait ErrorTrait
  18. {
  19. /**
  20. * 错误信息
  21. * @var string
  22. */
  23. protected $error;
  24. /**
  25. * 设置错误信息
  26. * @param string|null $error
  27. * @return bool
  28. */
  29. protected function setError($error = null)
  30. {
  31. $this->error = $error ?: '未知错误';
  32. return false;
  33. }
  34. /**
  35. * 获取错误信息
  36. * @return string
  37. */
  38. public function getError()
  39. {
  40. $error = $this->error;
  41. $this->error = null;
  42. return $error;
  43. }
  44. }