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\User; |
26
|
|
|
|
27
|
|
|
use Pterodactyl\Models\Server; |
28
|
|
|
use League\Fractal\TransformerAbstract; |
29
|
|
|
|
30
|
|
|
class ServerTransformer extends TransformerAbstract |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* List of resources that can be included. |
34
|
|
|
* |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $availableIncludes = [ |
38
|
|
|
'allocations', |
39
|
|
|
'subusers', |
40
|
|
|
'stats', |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Return a generic transformed server array. |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public function transform(Server $server) |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
'id' => $server->uuidShort, |
52
|
|
|
'uuid' => $server->uuid, |
53
|
|
|
'name' => $server->name, |
54
|
|
|
'description' => $server->description, |
55
|
|
|
'node' => $server->node->name, |
56
|
|
|
'limits' => [ |
57
|
|
|
'memory' => $server->memory, |
58
|
|
|
'swap' => $server->swap, |
59
|
|
|
'disk' => $server->disk, |
60
|
|
|
'io' => $server->io, |
61
|
|
|
'cpu' => $server->cpu, |
62
|
|
|
'oom_disabled' => (bool) $server->oom_disabled, |
63
|
|
|
], |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return a generic array of allocations for this server. |
69
|
|
|
* |
70
|
|
|
* @return \Leauge\Fractal\Resource\Collection |
71
|
|
|
*/ |
72
|
|
|
public function includeAllocations(Server $server) |
73
|
|
|
{ |
74
|
|
|
$allocations = $server->allocations; |
75
|
|
|
|
76
|
|
|
return $this->collection($allocations, new AllocationTransformer($server), 'allocation'); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Return a generic array of subusers for this server. |
81
|
|
|
* |
82
|
|
|
* @return \Leauge\Fractal\Resource\Collection |
83
|
|
|
*/ |
84
|
|
|
public function includeSubusers(Server $server) |
85
|
|
|
{ |
86
|
|
|
$server->load('subusers.permissions', 'subusers.user'); |
87
|
|
|
|
88
|
|
|
return $this->collection($server->subusers, new SubuserTransformer, 'subuser'); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Return a generic array of allocations for this server. |
93
|
|
|
* |
94
|
|
|
* @return \Leauge\Fractal\Resource\Item |
95
|
|
|
*/ |
96
|
|
|
public function includeStats(Server $server) |
97
|
|
|
{ |
98
|
|
|
return $this->item($server->guzzleClient(), new StatsTransformer, 'stat'); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: