2018-01-20 01:58:57 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
|
2018-01-20 01:58:57 +00:00
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
|
2018-01-20 01:58:57 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
2018-01-20 01:58:57 +00:00
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
class ServerController extends ApplicationApiController
|
2018-01-20 01:58:57 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ServerController constructor.
|
|
|
|
*
|
2018-01-20 03:47:06 +00:00
|
|
|
* @param \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal $fractal
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2018-01-20 01:58:57 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
|
|
|
*/
|
2018-01-20 03:47:06 +00:00
|
|
|
public function __construct(Fractal $fractal, Request $request, ServerRepositoryInterface $repository)
|
2018-01-20 01:58:57 +00:00
|
|
|
{
|
2018-01-20 03:47:06 +00:00
|
|
|
parent::__construct($fractal, $request);
|
|
|
|
|
2018-01-20 01:58:57 +00:00
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
/**
|
|
|
|
* Return all of the servers that currently exist on the Panel.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest $request
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function index(GetServersRequest $request): array
|
2018-01-20 01:58:57 +00:00
|
|
|
{
|
2018-01-20 03:47:06 +00:00
|
|
|
$servers = $this->repository->setSearchTerm($request->input('search'))->paginated(50);
|
2018-01-20 01:58:57 +00:00
|
|
|
|
|
|
|
return $this->fractal->collection($servers)
|
2018-01-20 03:47:06 +00:00
|
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a single server transformed for the application API.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest $request
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function view(GetServerRequest $request, Server $server): array
|
|
|
|
{
|
|
|
|
return $this->fractal->item($server)
|
|
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
2018-01-20 01:58:57 +00:00
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|