2017-08-26 23:08:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Daemon;
|
|
|
|
|
2018-01-06 00:27:47 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2017-08-26 23:08:11 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface;
|
|
|
|
use Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException;
|
|
|
|
|
|
|
|
class PowerRepository extends BaseRepository implements PowerRepositoryInterface
|
|
|
|
{
|
|
|
|
/**
|
2018-01-06 00:27:47 +00:00
|
|
|
* Send a power signal to a server.
|
|
|
|
*
|
|
|
|
* @param string $signal
|
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
|
|
*
|
2018-05-13 16:19:35 +00:00
|
|
|
* @throws InvalidPowerSignalException
|
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
2017-08-26 23:08:11 +00:00
|
|
|
*/
|
2018-01-06 00:27:47 +00:00
|
|
|
public function sendSignal(string $signal): ResponseInterface
|
2017-08-26 23:08:11 +00:00
|
|
|
{
|
|
|
|
switch ($signal) {
|
|
|
|
case self::SIGNAL_START:
|
|
|
|
case self::SIGNAL_STOP:
|
|
|
|
case self::SIGNAL_RESTART:
|
|
|
|
case self::SIGNAL_KILL:
|
2017-10-01 02:00:24 +00:00
|
|
|
return $this->getHttpClient()->request('PUT', 'server/power', [
|
2017-08-26 23:08:11 +00:00
|
|
|
'json' => [
|
|
|
|
'action' => $signal,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
default:
|
2018-01-06 00:27:47 +00:00
|
|
|
throw new InvalidPowerSignalException('The signal "' . $signal . '" is not defined and could not be processed.');
|
2017-08-26 23:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|