misc_pterodactyl-panel/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php

83 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
use Pterodactyl\Models\Server;
2018-01-21 22:02:03 +00:00
use Pterodactyl\Services\Servers\BuildModificationService;
use Pterodactyl\Services\Servers\DetailsModificationService;
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerDetailsRequest;
2018-01-21 22:02:03 +00:00
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest;
class ServerDetailsController extends ApplicationApiController
{
2018-01-21 22:02:03 +00:00
/**
* @var \Pterodactyl\Services\Servers\BuildModificationService
*/
private $buildModificationService;
/**
* @var \Pterodactyl\Services\Servers\DetailsModificationService
*/
2018-01-21 22:02:03 +00:00
private $detailsModificationService;
/**
* ServerDetailsController constructor.
*
2019-09-06 04:32:57 +00:00
* @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService
2018-01-21 22:02:03 +00:00
* @param \Pterodactyl\Services\Servers\DetailsModificationService $detailsModificationService
*/
public function __construct(
BuildModificationService $buildModificationService,
DetailsModificationService $detailsModificationService
) {
parent::__construct();
2018-01-21 22:02:03 +00:00
$this->buildModificationService = $buildModificationService;
$this->detailsModificationService = $detailsModificationService;
}
/**
2018-01-21 22:02:03 +00:00
* Update the details for a specific server.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerDetailsRequest $request
* @param \Pterodactyl\Models\Server $server
*
* @return array
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Throwable
*/
public function details(UpdateServerDetailsRequest $request, Server $server): array
{
$server = $this->detailsModificationService->returnUpdatedModel()->handle(
$server, $request->validated()
);
2018-01-21 22:02:03 +00:00
return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class))
->toArray();
}
/**
* Update the build details for a specific server.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request
2019-12-22 21:45:40 +00:00
* @param \Pterodactyl\Models\Server $server
*
2018-01-21 22:02:03 +00:00
* @return array
*
* @throws \Throwable
2018-01-21 22:02:03 +00:00
* @throws \Pterodactyl\Exceptions\DisplayException
*/
2019-12-22 21:45:40 +00:00
public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array
2018-01-21 22:02:03 +00:00
{
2019-12-22 21:45:40 +00:00
$server = $this->buildModificationService->handle($server, $request->validated());
return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class))
->toArray();
}
}