|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Pterodactyl - Panel |
|
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
|
5
|
|
|
* |
|
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
8
|
|
|
* in the Software without restriction, including without limitation the rights |
|
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
11
|
|
|
* furnished to do so, subject to the following conditions: |
|
12
|
|
|
* |
|
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
14
|
|
|
* copies or substantial portions of the Software. |
|
15
|
|
|
* |
|
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
22
|
|
|
* SOFTWARE. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Pterodactyl\Transformers\Admin; |
|
26
|
|
|
|
|
27
|
|
|
use Illuminate\Http\Request; |
|
28
|
|
|
use Pterodactyl\Models\Pack; |
|
29
|
|
|
use League\Fractal\TransformerAbstract; |
|
30
|
|
|
|
|
31
|
|
|
class PackTransformer extends TransformerAbstract |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* List of resources that can be included. |
|
35
|
|
|
* |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $availableIncludes = [ |
|
39
|
|
|
'option', |
|
40
|
|
|
'servers', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The Illuminate Request object if provided. |
|
45
|
|
|
* |
|
46
|
|
|
* @var \Illuminate\Http\Request|bool |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $request; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Setup request object for transformer. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \Illuminate\Http\Request|bool $request |
|
54
|
|
|
* @return void |
|
|
|
|
|
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct($request = false) |
|
57
|
|
|
{ |
|
58
|
|
|
if (! $request instanceof Request && $request !== false) { |
|
59
|
|
|
throw new DisplayException('Request passed to constructor must be of type Request or false.'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$this->request = $request; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Return a generic transformed pack array. |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
public function transform($pack) |
|
71
|
|
|
{ |
|
72
|
|
|
if (! $pack instanceof Pack) { |
|
73
|
|
|
return ['id' => null]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $pack->toArray(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Return the packs associated with this service. |
|
81
|
|
|
* |
|
82
|
|
|
* @return \Leauge\Fractal\Resource\Item |
|
83
|
|
|
*/ |
|
84
|
|
|
public function includeOption(Pack $pack) |
|
85
|
|
|
{ |
|
86
|
|
|
if ($this->request && ! $this->request->apiKeyHasPermission('option-view')) { |
|
87
|
|
|
return; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $this->item($pack->option, new OptionTransformer($this->request), 'option'); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Return the packs associated with this service. |
|
95
|
|
|
* |
|
96
|
|
|
* @return \Leauge\Fractal\Resource\Collection |
|
97
|
|
|
*/ |
|
98
|
|
|
public function includeServers(Pack $pack) |
|
99
|
|
|
{ |
|
100
|
|
|
if ($this->request && ! $this->request->apiKeyHasPermission('server-list')) { |
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this->collection($pack->servers, new ServerTransformer($this->request), 'server'); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
Adding a
@returnannotation 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.