Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Wings/DaemonConfigurationRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Wings;
4
5
use Pterodactyl\Models\Node;
6
use Psr\Http\Message\ResponseInterface;
7
use GuzzleHttp\Exception\TransferException;
8
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
9
10
/**
11
* @method \Pterodactyl\Repositories\Wings\DaemonConfigurationRepository setNode(\Pterodactyl\Models\Node $node)
12
* @method \Pterodactyl\Repositories\Wings\DaemonConfigurationRepository setServer(\Pterodactyl\Models\Server $server)
13
*/
14
class DaemonConfigurationRepository extends DaemonRepository
15
{
16
/**
17
* Returns system information from the wings instance.
18
*
19
* @throws DaemonConnectionException
20
*/
21
public function getSystemInformation(?int $version = null): array
22
{
23
try {
24
$response = $this->getHttpClient()->get('/api/system' . (!is_null($version) ? '?v=' . $version : ''));
25
} catch (TransferException $exception) {
26
throw new DaemonConnectionException($exception);
27
}
28
29
return json_decode($response->getBody()->__toString(), true);
30
}
31
32
/**
33
* Updates the configuration information for a daemon. Updates the information for
34
* this instance using a passed-in model. This allows us to change plenty of information
35
* in the model, and still use the old, pre-update model to actually make the HTTP request.
36
*
37
* @throws DaemonConnectionException
38
*/
39
public function update(Node $node): ResponseInterface
40
{
41
try {
42
return $this->getHttpClient()->post(
43
'/api/update',
44
['json' => $node->getConfiguration()]
45
);
46
} catch (TransferException $exception) {
47
throw new DaemonConnectionException($exception);
48
}
49
}
50
}
51
52