1 | <?php |
||
31 | class ServerTransformer extends TransformerAbstract |
||
32 | { |
||
33 | /** |
||
34 | * List of resources that can be included. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $availableIncludes = [ |
||
39 | 'allocations', |
||
40 | 'user', |
||
41 | 'subusers', |
||
42 | 'pack', |
||
43 | 'service', |
||
44 | 'option', |
||
45 | 'variables', |
||
46 | 'location', |
||
47 | 'node', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * The Illuminate Request object if provided. |
||
52 | * |
||
53 | * @var \Illuminate\Http\Request|bool |
||
54 | */ |
||
55 | protected $request; |
||
56 | |||
57 | /** |
||
58 | * Setup request object for transformer. |
||
59 | * |
||
60 | * @param \Illuminate\Http\Request|bool $request |
||
61 | * @return void |
||
|
|||
62 | */ |
||
63 | public function __construct($request = false) |
||
71 | |||
72 | /** |
||
73 | * Return a generic transformed server array. |
||
74 | * |
||
75 | * @return array |
||
76 | */ |
||
77 | public function transform(Server $server) |
||
78 | { |
||
79 | return collect($server->toArray())->only($server->getTableColumns())->toArray(); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Return a generic array of allocations for this server. |
||
84 | * |
||
85 | * @return \Leauge\Fractal\Resource\Collection |
||
86 | */ |
||
87 | public function includeAllocations(Server $server) |
||
88 | { |
||
89 | if ($this->request && ! $this->request->apiKeyHasPermission('server-view')) { |
||
90 | return; |
||
91 | } |
||
92 | |||
93 | return $this->collection($server->allocations, new AllocationTransformer($this->request, 'server'), 'allocation'); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Return a generic array of data about subusers for this server. |
||
98 | * |
||
99 | * @return \Leauge\Fractal\Resource\Collection |
||
100 | */ |
||
101 | public function includeSubusers(Server $server) |
||
102 | { |
||
103 | if ($this->request && ! $this->request->apiKeyHasPermission('server-view')) { |
||
104 | return; |
||
105 | } |
||
106 | |||
107 | return $this->collection($server->subusers, new SubuserTransformer($this->request), 'subuser'); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Return a generic array of data about subusers for this server. |
||
112 | * |
||
113 | * @return \Leauge\Fractal\Resource\Item |
||
114 | */ |
||
115 | public function includeUser(Server $server) |
||
116 | { |
||
117 | if ($this->request && ! $this->request->apiKeyHasPermission('user-view')) { |
||
118 | return; |
||
119 | } |
||
120 | |||
121 | return $this->item($server->user, new UserTransformer($this->request), 'user'); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Return a generic array with pack information for this server. |
||
126 | * |
||
127 | * @return \Leauge\Fractal\Resource\Item |
||
128 | */ |
||
129 | public function includePack(Server $server) |
||
137 | |||
138 | /** |
||
139 | * Return a generic array with service information for this server. |
||
140 | * |
||
141 | * @return \Leauge\Fractal\Resource\Item |
||
142 | */ |
||
143 | public function includeService(Server $server) |
||
151 | |||
152 | /** |
||
153 | * Return a generic array with service option information for this server. |
||
154 | * |
||
155 | * @return \Leauge\Fractal\Resource\Item |
||
156 | */ |
||
157 | public function includeOption(Server $server) |
||
165 | |||
166 | /** |
||
167 | * Return a generic array of data about subusers for this server. |
||
168 | * |
||
169 | * @return \Leauge\Fractal\Resource\Collection |
||
170 | */ |
||
171 | public function includeVariables(Server $server) |
||
179 | |||
180 | /** |
||
181 | * Return a generic array with pack information for this server. |
||
182 | * |
||
183 | * @return \Leauge\Fractal\Resource\Item |
||
184 | */ |
||
185 | public function includeLocation(Server $server) |
||
193 | |||
194 | /** |
||
195 | * Return a generic array with pack information for this server. |
||
196 | * |
||
197 | * @return \Leauge\Fractal\Resource\Item|void |
||
198 | */ |
||
199 | public function includeNode(Server $server) |
||
207 | } |
||
208 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.