Total Complexity | 5 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
22 | abstract class Presenter extends FractalPresenter |
||
23 | { |
||
24 | protected $meta = []; |
||
25 | |||
26 | /** |
||
27 | * Prepare data to present. |
||
28 | * |
||
29 | * @param Collection $data data |
||
30 | * |
||
31 | * @throws \Exception |
||
32 | * |
||
33 | * @return mixed |
||
34 | */ |
||
35 | public function present($data) |
||
36 | { |
||
37 | if (!class_exists('League\Fractal\Manager')) { |
||
38 | throw new \Exception(trans('repository::packages.league_fractal_required')); |
||
39 | } |
||
40 | |||
41 | if ($data instanceof Collection) { |
||
|
|||
42 | $this->resource = $this->transformCollection($data); |
||
43 | } elseif ($data instanceof AbstractPaginator) { |
||
44 | $this->resource = $this->transformPaginator($data); |
||
45 | } else { |
||
46 | $this->resource = $this->transformItem($data); |
||
47 | } |
||
48 | |||
49 | // set meta |
||
50 | $this->resource->setMeta($this->meta); |
||
51 | |||
52 | return $this->fractal->createData($this->resource)->toArray(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Set Meta |
||
57 | * |
||
58 | * @param array $meta meta |
||
59 | * |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function setMeta(array $meta) |
||
65 | } |
||
66 | } |
||
67 |