Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Wings/DaemonCommandRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Wings;
4
5
use Webmozart\Assert\Assert;
6
use Pterodactyl\Models\Server;
7
use Psr\Http\Message\ResponseInterface;
8
use GuzzleHttp\Exception\TransferException;
9
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
10
11
/**
12
* @method \Pterodactyl\Repositories\Wings\DaemonCommandRepository setNode(\Pterodactyl\Models\Node $node)
13
* @method \Pterodactyl\Repositories\Wings\DaemonCommandRepository setServer(\Pterodactyl\Models\Server $server)
14
*/
15
class DaemonCommandRepository extends DaemonRepository
16
{
17
/**
18
* Sends a command or multiple commands to a running server instance.
19
*
20
* @throws DaemonConnectionException
21
*/
22
public function send(array|string $command): ResponseInterface
23
{
24
Assert::isInstanceOf($this->server, Server::class);
25
26
try {
27
return $this->getHttpClient()->post(
28
sprintf('/api/servers/%s/commands', $this->server->uuid),
29
[
30
'json' => ['commands' => is_array($command) ? $command : [$command]],
31
]
32
);
33
} catch (TransferException $exception) {
34
throw new DaemonConnectionException($exception);
35
}
36
}
37
}
38
39