misc_pterodactyl-panel/app/Repositories/Daemon/ServerRepository.php

121 lines
2.9 KiB
PHP
Raw Normal View History

<?php
2017-09-26 02:43:01 +00:00
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Daemon;
2017-08-27 19:55:25 +00:00
use Webmozart\Assert\Assert;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
class ServerRepository extends BaseRepository implements ServerRepositoryInterface
{
/**
* Create a new server on the daemon for the panel.
*
* @param array $structure
* @param array $overrides
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \GuzzleHttp\Exception\RequestException
*/
public function create(array $structure, array $overrides = []): ResponseInterface
{
// Loop through overrides.
foreach ($overrides as $key => $value) {
array_set($structure, $key, $value);
}
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'servers', [
'json' => $structure,
]);
}
/**
* {@inheritdoc}
*/
public function update(array $data)
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('PATCH', 'server', [
'json' => $data,
]);
}
/**
* {@inheritdoc}
*/
public function reinstall($data = null)
{
Assert::nullOrIsArray($data, 'First argument passed to reinstall must be null or an array, received %s.');
if (is_null($data)) {
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/reinstall');
}
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/reinstall', [
'json' => $data,
]);
}
/**
* {@inheritdoc}
*/
public function rebuild()
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/rebuild');
}
/**
* {@inheritdoc}
*/
public function suspend()
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/suspend');
}
/**
* {@inheritdoc}
*/
public function unsuspend()
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('POST', 'server/unsuspend');
}
/**
* {@inheritdoc}
*/
public function delete()
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('DELETE', 'servers');
}
/**
* {@inheritdoc}
*/
public function details()
{
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('GET', 'server');
}
/**
* {@inheritdoc}
*/
public function revokeAccessKey($key)
{
if (is_array($key)) {
return $this->getHttpClient()->request('POST', 'keys', [
'json' => $key,
]);
}
Assert::stringNotEmpty($key, 'First argument passed to revokeAccessKey must be a non-empty string or array, received %s.');
2017-10-01 02:00:24 +00:00
return $this->getHttpClient()->request('DELETE', 'keys/' . $key);
}
}