BaseShuntTransformer.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Repositories\Transformers;
  11. use App\Repositories\Models\Model;
  12. use League\Fractal\TransformerAbstract;
  13. interface BaseShuntInterface
  14. {
  15. public function mobileDetailTransform($model);
  16. public function mobileTransform($model);
  17. public function pcTransform($model);
  18. public function detailTransform($model);
  19. }
  20. class BaseShuntTransformer extends TransformerAbstract implements BaseShuntInterface
  21. {
  22. public function transform(Model $model)
  23. {
  24. if (is_mobile()) {
  25. if ($this->isId()) {
  26. return $this->mobileDetailTransform($model);
  27. }
  28. return $this->mobileTransform($model);
  29. }
  30. if ($this->isId()) {
  31. return $this->detailTransform($model);
  32. }
  33. return $this->pcTransform($model);
  34. }
  35. /**
  36. * 是否为详情
  37. * @return bool
  38. */
  39. private function isId()
  40. {
  41. return request()->has('id');
  42. }
  43. public function mobileDetailTransform($model)
  44. {
  45. return [];
  46. }
  47. public function mobileTransform($model)
  48. {
  49. return [];
  50. }
  51. public function detailTransform($model)
  52. {
  53. return [];
  54. }
  55. public function pcTransform($model)
  56. {
  57. return [];
  58. }
  59. }