Helper.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Core;
  4. use Random\RandomException;
  5. use SixShop\Core\Exception\LogicException;
  6. use think\Paginator;
  7. use think\Response;
  8. /**
  9. * 助手类
  10. * @deprecated 类已弃用, 请使用函数版本的助手方法
  11. */
  12. final class Helper
  13. {
  14. /**
  15. * 返回成功数据
  16. * @deprecated 函数已弃用, 请使用 success_response()
  17. */
  18. public static function success_response(mixed $data = [], string $status = 'ok', int $code = 200, string $msg = 'success', string $type = 'json', string $xslt = ''): Response
  19. {
  20. return success_response($data, $status, $code, $msg, $type, $xslt);
  21. }
  22. /**
  23. * 返回分页数据
  24. * @deprecated 函数已弃用, 请使用 page_response()
  25. */
  26. public static function page_response(Paginator $page, mixed $data = [], string $status = 'ok', int $code = 200, string $msg = 'success'): Response
  27. {
  28. return json([
  29. 'code' => $code,
  30. 'status' => $status,
  31. 'msg' => $msg,
  32. 'page' => $page,
  33. 'data' => $data
  34. ]);
  35. }
  36. /**
  37. * 抛出逻辑异常
  38. * @throws LogicException
  39. * @deprecated 函数已弃用, 请使用 throw_logic_exception()
  40. */
  41. public static function throw_logic_exception(string $msg = 'error', int $code = 1, string $status = 'error', mixed $data = [], int $httpCode = 200, $header = [], $options = []): void
  42. {
  43. throw new LogicException(error_response($msg, $status, $code, $data, $httpCode, $header, $options));
  44. }
  45. /**
  46. * 返回失败数据
  47. * @deprecated 函数已弃用, 请使用 error_response()
  48. */
  49. public static function error_response(string $msg = 'error', string $status = 'error', int $code = 1, mixed $data = [], int $httpCode = 400, $header = [], $options = []): Response
  50. {
  51. return json([
  52. 'code' => $code,
  53. 'status' => $status,
  54. 'msg' => $msg,
  55. 'data' => $data
  56. ], $httpCode, $header, $options);
  57. }
  58. /**
  59. * 构建树形结构选项
  60. * @param array $data 数据源
  61. * @param string $valueField 值字段
  62. * @param string $labelField 标签字段
  63. * @param string $parentField 父字段
  64. * @param int $parentId 父ID
  65. * @param string $childrenKey 子节点键
  66. * @param bool $preserveOriginal 是否保留原始数据
  67. *
  68. * @deprecated 函数已弃用, 请使用 build_tree_options()
  69. */
  70. public static function build_tree_options(
  71. array $data,
  72. string $valueField = 'id',
  73. string $labelField = 'name',
  74. string $parentField = 'parent_id',
  75. int $parentId = 0,
  76. string $childrenKey = 'children',
  77. bool $preserveOriginal = true
  78. ): array
  79. {
  80. return build_tree_options($data, $valueField, $labelField, $parentField, $parentId, $childrenKey, $preserveOriginal);
  81. }
  82. /**
  83. * 生成随机密码
  84. * @param int $length 密码长度
  85. * @return string 生成的密码
  86. * @throws RandomException
  87. * @deprecated 函数已弃用, 请使用 secret_password()
  88. */
  89. public static function secret_password(int $length = 16): string
  90. {
  91. return secret_password($length);
  92. }
  93. /**
  94. * 获取插件目录
  95. * @param string $extensionID 插件ID
  96. * @return string 插件目录
  97. * @deprecated 函数已弃用, 请使用 extension_path()
  98. */
  99. public static function extension_path(string $extensionID = ''): string
  100. {
  101. return extension_path($extensionID);
  102. }
  103. /**
  104. *
  105. * @deprecated 废弃方法,请使用 extension_name_list 方法
  106. */
  107. public static function extension_name_list(): array
  108. {
  109. return extension_name_list();
  110. }
  111. }