1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Repositories\Transformers;
- use App\Repositories\Models\Model;
- use League\Fractal\TransformerAbstract;
- interface BaseShuntInterface
- {
- public function mobileDetailTransform($model);
- public function mobileTransform($model);
- public function pcTransform($model);
- public function detailTransform($model);
- }
- class BaseShuntTransformer extends TransformerAbstract implements BaseShuntInterface
- {
- public function transform(Model $model)
- {
- if (is_mobile()) {
- if ($this->isId()) {
- return $this->mobileDetailTransform($model);
- }
- return $this->mobileTransform($model);
- }
- if ($this->isId()) {
- return $this->detailTransform($model);
- }
- return $this->pcTransform($model);
- }
- /**
- * 是否为详情
- * @return bool
- */
- private function isId()
- {
- return request()->has('id');
- }
- public function mobileDetailTransform($model)
- {
- return [];
- }
- public function mobileTransform($model)
- {
- return [];
- }
- public function detailTransform($model)
- {
- return [];
- }
- public function pcTransform($model)
- {
- return [];
- }
- }
|