DaoException.class.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace KIF\Exception;
  3. use Exception;
  4. /**
  5. *
  6. * 数据访问层异常
  7. * @author gaoxiaogang@gmail.com
  8. *
  9. */
  10. class DaoException extends Exception {
  11. public function __construct ($message = 'Dao exception', $code = 0) {
  12. parent::__construct($message, $code);
  13. }
  14. /**
  15. *
  16. * 缓存服务不可用
  17. * @var string
  18. */
  19. const CACHE_SERVICE_UNAVAILABLE = 'CACHE_SERVICE_UNAVAILABLE';
  20. /**
  21. *
  22. * 设置表缓存标志失败
  23. * @var string
  24. */
  25. const CACHE_SET_TABLE_FLAG_ERROR = 'CACHE_SET_TABLE_FLAG_ERROR';
  26. /**
  27. *
  28. * 获取异常描述
  29. * @return array
  30. */
  31. static public function getDesc() {
  32. return array(
  33. self::CACHE_SERVICE_UNAVAILABLE => array(
  34. 'kw' => 'CACHE_SERVICE_UNAVAILABLE',
  35. 'desc' => '缓存服务不可用',
  36. ),
  37. self::CACHE_SET_TABLE_FLAG_ERROR => array(
  38. 'kw' => 'CACHE_SET_TABLE_FLAG_ERROR',
  39. 'desc' => '设置表缓存标志失败',
  40. ),
  41. );
  42. }
  43. /**
  44. *
  45. * 根据异常的关键词获取文本型的描述
  46. * @param string $kw
  47. * @return false | string
  48. */
  49. static public function getTextDescByKW($kw) {
  50. $descs = self::getDesc();
  51. if (isset($descs[$kw])) {
  52. return $descs[$kw]['desc'];
  53. }
  54. return false;
  55. }
  56. }