| @@ 31-85 (lines=55) @@ | ||
| 28 | use Pterodactyl\Models\ServerVariable; |
|
| 29 | use League\Fractal\TransformerAbstract; |
|
| 30 | ||
| 31 | class ServerVariableTransformer extends TransformerAbstract |
|
| 32 | { |
|
| 33 | /** |
|
| 34 | * List of resources that can be included. |
|
| 35 | * |
|
| 36 | * @var array |
|
| 37 | */ |
|
| 38 | protected $availableIncludes = ['parent']; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * The Illuminate Request object if provided. |
|
| 42 | * |
|
| 43 | * @var \Illuminate\Http\Request|bool |
|
| 44 | */ |
|
| 45 | protected $request; |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Setup request object for transformer. |
|
| 49 | * |
|
| 50 | * @param \Illuminate\Http\Request|bool $request |
|
| 51 | * @return void |
|
| 52 | */ |
|
| 53 | public function __construct($request = false) |
|
| 54 | { |
|
| 55 | if (! $request instanceof Request && $request !== false) { |
|
| 56 | throw new DisplayException('Request passed to constructor must be of type Request or false.'); |
|
| 57 | } |
|
| 58 | ||
| 59 | $this->request = $request; |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Return a generic transformed server variable array. |
|
| 64 | * |
|
| 65 | * @return array |
|
| 66 | */ |
|
| 67 | public function transform(ServerVariable $variable) |
|
| 68 | { |
|
| 69 | return $variable->toArray(); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * Return the parent service variable data. |
|
| 74 | * |
|
| 75 | * @return \Leauge\Fractal\Resource\Item |
|
| 76 | */ |
|
| 77 | public function includeParent(ServerVariable $variable) |
|
| 78 | { |
|
| 79 | if ($this->request && ! $this->request->apiKeyHasPermission('option-view')) { |
|
| 80 | return; |
|
| 81 | } |
|
| 82 | ||
| 83 | return $this->item($variable->variable, new ServiceVariableTransformer($this->request), 'variable'); |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||
| @@ 31-85 (lines=55) @@ | ||
| 28 | use League\Fractal\TransformerAbstract; |
|
| 29 | use Pterodactyl\Models\ServiceVariable; |
|
| 30 | ||
| 31 | class ServiceVariableTransformer extends TransformerAbstract |
|
| 32 | { |
|
| 33 | /** |
|
| 34 | * List of resources that can be included. |
|
| 35 | * |
|
| 36 | * @var array |
|
| 37 | */ |
|
| 38 | protected $availableIncludes = ['variables']; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * The Illuminate Request object if provided. |
|
| 42 | * |
|
| 43 | * @var \Illuminate\Http\Request|bool |
|
| 44 | */ |
|
| 45 | protected $request; |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Setup request object for transformer. |
|
| 49 | * |
|
| 50 | * @param \Illuminate\Http\Request|bool $request |
|
| 51 | * @return void |
|
| 52 | */ |
|
| 53 | public function __construct($request = false) |
|
| 54 | { |
|
| 55 | if (! $request instanceof Request && $request !== false) { |
|
| 56 | throw new DisplayException('Request passed to constructor must be of type Request or false.'); |
|
| 57 | } |
|
| 58 | ||
| 59 | $this->request = $request; |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Return a generic transformed server variable array. |
|
| 64 | * |
|
| 65 | * @return array |
|
| 66 | */ |
|
| 67 | public function transform(ServiceVariable $variable) |
|
| 68 | { |
|
| 69 | return $variable->toArray(); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * Return the server variables associated with this variable. |
|
| 74 | * |
|
| 75 | * @return \Leauge\Fractal\Resource\Collection |
|
| 76 | */ |
|
| 77 | public function includeVariables(ServiceVariable $variable) |
|
| 78 | { |
|
| 79 | if ($this->request && ! $this->request->apiKeyHasPermission('server-view')) { |
|
| 80 | return; |
|
| 81 | } |
|
| 82 | ||
| 83 | return $this->collection($variable->serverVariable, new ServerVariableTransformer($this->request), 'server_variable'); |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||