UserApi.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Http\Api;
  3. use App\Services\UserService;
  4. /**
  5. * **冻结的转发壳,不要往里写逻辑。**
  6. *
  7. * 实现全部在 {@see UserService}。保留这个类只为一件事:让 v2 的六十多个调用点
  8. * 不必改动——改它们要配快照测试,而 dashboard-v4 在线上跑着且无人维护。
  9. *
  10. * 新代码一律注入 `UserService`。等本类的调用点清零,连同 `app/Http/Api/` 一起删。
  11. *
  12. * 方法名沿用 v2 的旧名,其中几个名不副实(`getIdByName` 返回的是 uuid,
  13. * `getIdByUuid` 返回的是自增主键),`UserService` 那边已改成诚实的名字。
  14. *
  15. * @deprecated 用 App\Services\UserService
  16. */
  17. class UserApi
  18. {
  19. /** @deprecated 用 UserService::uuidByName() */
  20. public static function getIdByName($name)
  21. {
  22. return self::service()->uuidByName($name);
  23. }
  24. /** @deprecated 用 UserService::intIdByUuid() */
  25. public static function getIdByUuid($uuid)
  26. {
  27. return self::service()->intIdByUuid($uuid);
  28. }
  29. /** @deprecated 用 UserService::intIdByName() */
  30. public static function getIntIdByName($name)
  31. {
  32. return self::service()->intIdByName($name);
  33. }
  34. /** @deprecated 用 UserService::byId() */
  35. public static function getById($id)
  36. {
  37. return self::service()->byId($id);
  38. }
  39. /** @deprecated 用 UserService::byName() */
  40. public static function getByName($name)
  41. {
  42. return self::service()->byName($name);
  43. }
  44. /** @deprecated 用 UserService::byUuid();列表场景用 byUuids(),别循环调这个 */
  45. public static function getByUuid($id)
  46. {
  47. return self::service()->byUuid($id);
  48. }
  49. /** @deprecated 用 UserService::byUuids(),它返回 uuid => 摘要的映射,不会丢项 */
  50. public static function getListByUuid($uuid)
  51. {
  52. // 非数组返回 null 是 v2 的既有口径,留在适配层,不要带进 Service
  53. if (! $uuid || ! is_array($uuid)) {
  54. return null;
  55. }
  56. return self::service()->listByUuids($uuid);
  57. }
  58. /** @deprecated 用 UserService::profile() */
  59. public static function userInfo($user)
  60. {
  61. return self::service()->profile($user);
  62. }
  63. private static function service(): UserService
  64. {
  65. return app(UserService::class);
  66. }
  67. }