1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-27 12:22:28 +01:00

Add all of the potential transformers that might be needed for now.

This commit is contained in:
Dane Everitt 2017-04-07 20:28:58 -04:00
parent 65630bdcce
commit 51204b8d9d
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
12 changed files with 642 additions and 9 deletions

View File

@ -64,10 +64,7 @@ class ServerController extends Controller
$fractal = Fractal::create()->item($server);
if ($request->input('include')) {
$fractal->parseIncludes(collect(explode(',', $request->input('include')))->intersect([
'allocations', 'subusers', 'user',
'pack', 'service', 'option',
])->toArray());
$fractal->parseIncludes(explode(',', $request->input('include')));
}
return $fractal->transformWith(new ServerTransformer)

View File

@ -47,9 +47,7 @@ class ServerController extends Controller
$fractal = Fractal::create()->item($server);
if ($request->input('include')) {
$fractal->parseIncludes(collect(explode(',', $request->input('include')))->intersect([
'allocations', 'subusers', 'stats',
])->toArray());
$fractal->parseIncludes(explode(',', $request->input('include')));
}
return $fractal->transformWith(new ServerTransformer)

View File

@ -313,4 +313,14 @@ class Server extends Model
{
return $this->hasMany(Database::class);
}
/**
* Gets the location of the server.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function location()
{
return $this->node->location();
}
}

View File

@ -30,12 +30,55 @@ use League\Fractal\TransformerAbstract;
class AllocationTransformer extends TransformerAbstract
{
/**
* Return a generic transformed server array.
* The filter to be applied to this transformer.
*
* @var bool|string
*/
protected $filter;
/**
* Transformer constructor.
*
* @param bool|string $filter
* @return void
*/
public function __construct($filter = false)
{
$this->filter = $filter;
}
/**
* Return a generic transformed allocation array.
*
* @return array
*/
public function transform(Allocation $allocation)
{
return $this->transformWithFilter($allocation);
}
/**
* Determine which transformer filter to apply.
*
* @return array
*/
protected function transformWithFilter(Allocation $allocation)
{
if ($this->filter === 'server') {
return $this->transformForServer($allocation);
}
return $allocation->toArray();
}
/**
* Transform the allocation to only return information not duplicated
* in the server response (discard node_id and server_id).
*
* @return array
*/
protected function transformForServer(Allocation $allocation)
{
return collect($allocation)->only('id', 'ip', 'ip_alias', 'port')->toArray();
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Transformers\Admin;
use Pterodactyl\Models\Location;
use League\Fractal\TransformerAbstract;
class LocationTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = [
'nodes',
'servers',
];
/**
* Return a generic transformed pack array.
*
* @return array
*/
public function transform(Location $location)
{
return $location->toArray();
}
/**
* Return the nodes associated with this location.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeServers(Location $location)
{
return $this->collection($location->servers, new ServerTransformer, 'server');
}
/**
* Return the nodes associated with this location.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeNodes(Location $location)
{
return $this->collection($location->nodes, new NodeTransformer, 'node');
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Transformers\Admin;
use Pterodactyl\Models\Node;
use League\Fractal\TransformerAbstract;
class NodeTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = [
'allocations',
'location',
'servers',
];
/**
* Return a generic transformed pack array.
*
* @return array
*/
public function transform(Node $node)
{
return $node->toArray();
}
/**
* Return the nodes associated with this location.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeAllocations(Node $node)
{
return $this->collection($node->allocations, new AllocationTransformer, 'allocation');
}
/**
* Return the nodes associated with this location.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeLocation(Node $node)
{
return $this->item($node->location, new LocationTransformer, 'location');
}
/**
* Return the nodes associated with this location.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeServers(Node $node)
{
return $this->collection($node->servers, new ServerTransformer, 'server');
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Transformers\Admin;
use Pterodactyl\Models\ServiceOption;
use League\Fractal\TransformerAbstract;
class OptionTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = [
'service',
'packs',
'servers',
'variables',
];
/**
* Return a generic transformed service option array.
*
* @return array
*/
public function transform(ServiceOption $option)
{
return $option->toArray();
}
/**
* Return the parent service for this service option.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeService(ServiceOption $option)
{
return $this->item($option->service, new ServiceTransformer, 'service');
}
/**
* Return the packs associated with this service option.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includePacks(ServiceOption $option)
{
return $this->collection($option->packs, new PackTransformer, 'pack');
}
/**
* Return the servers associated with this service option.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeServers(ServiceOption $option)
{
return $this->collection($option->servers, new ServerTransformer, 'server');
}
/**
* Return the variables for this service option.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeVariables(ServiceOption $option)
{
return $this->collection($option->variables, new ServiceVariableTransformer, 'variable');
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Transformers\Admin;
use Pterodactyl\Models\Pack;
use League\Fractal\TransformerAbstract;
class PackTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = [
'option',
'servers',
];
/**
* Return a generic transformed pack array.
*
* @return array
*/
public function transform($pack)
{
if (! $pack instanceof Pack) {
return ['id' => null];
}
return $pack->toArray();
}
/**
* Return the packs associated with this service.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeOption(Pack $pack)
{
return $this->item($pack->option, new OptionTransformer, 'option');
}
/**
* Return the packs associated with this service.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeServers(Pack $pack)
{
return $this->collection($pack->servers, new ServerTransformer, 'server');
}
}

View File

@ -38,6 +38,12 @@ class ServerTransformer extends TransformerAbstract
'allocations',
'user',
'subusers',
'pack',
'service',
'option',
'variables',
'location',
'node',
];
/**
@ -57,7 +63,7 @@ class ServerTransformer extends TransformerAbstract
*/
public function includeAllocations(Server $server)
{
return $this->collection($server->allocations, new AllocationTransformer, 'allocation');
return $this->collection($server->allocations, new AllocationTransformer('server'), 'allocation');
}
/**
@ -79,4 +85,64 @@ class ServerTransformer extends TransformerAbstract
{
return $this->item($server->user, new UserTransformer, 'user');
}
/**
* Return a generic array with pack information for this server.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includePack(Server $server)
{
return $this->item($server->pack, new PackTransformer, 'pack');
}
/**
* Return a generic array with service information for this server.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeService(Server $server)
{
return $this->item($server->service, new ServiceTransformer, 'service');
}
/**
* Return a generic array with service option information for this server.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeOption(Server $server)
{
return $this->item($server->option, new OptionTransformer, 'option');
}
/**
* Return a generic array of data about subusers for this server.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeVariables(Server $server)
{
return $this->collection($server->variables, new ServerVariableTransformer, 'server_variable');
}
/**
* Return a generic array with pack information for this server.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeLocation(Server $server)
{
return $this->item($server->location, new LocationTransformer, 'location');
}
/**
* Return a generic array with pack information for this server.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeNode(Server $server)
{
return $this->item($server->node, new NodeTransformer, 'node');
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Transformers\Admin;
use Pterodactyl\Models\ServerVariable;
use League\Fractal\TransformerAbstract;
class ServerVariableTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = ['parent'];
/**
* Return a generic transformed server variable array.
*
* @return array
*/
public function transform(ServerVariable $variable)
{
return $variable->toArray();
}
/**
* Return the parent service variable data.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeParent(ServerVariable $variable)
{
return $this->item($variable->variable, new ServiceVariableTransformer, 'variable');
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Transformers\Admin;
use Pterodactyl\Models\Service;
use League\Fractal\TransformerAbstract;
class ServiceTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = [
'options',
'servers',
'packs',
];
/**
* Return a generic transformed service array.
*
* @return array
*/
public function transform(Service $service)
{
return $service->toArray();
}
/**
* Return the the service options.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeOptions(Service $service)
{
return $this->collection($service->options, new OptionTransformer, 'option');
}
/**
* Return the servers associated with this service.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeServers(Service $service)
{
return $this->collection($service->servers, new ServerTransformer, 'server');
}
/**
* Return the packs associated with this service.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includePacks(Service $service)
{
return $this->collection($service->packs, new PackTransformer, 'pack');
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Transformers\Admin;
use Pterodactyl\Models\ServiceVariable;
use League\Fractal\TransformerAbstract;
class ServiceVariableTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = ['variables'];
/**
* Return a generic transformed server variable array.
*
* @return array
*/
public function transform(ServiceVariable $variable)
{
return $variable->toArray();
}
/**
* Return the server variables associated with this variable.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeVariables(ServiceVariable $variable)
{
return $this->collection($variable->serverVariable, new ServerVariableTransformer, 'server_variable');
}
}