misc_pterodactyl-panel/app/Repositories/Daemon/PowerRepository.php
2018-05-13 12:42:11 -04:00

36 lines
1.2 KiB
PHP

<?php
namespace Pterodactyl\Repositories\Daemon;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface;
use Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException;
class PowerRepository extends BaseRepository implements PowerRepositoryInterface
{
/**
* Send a power signal to a server.
*
* @param string $signal
* @return \Psr\Http\Message\ResponseInterface
*
* @throws InvalidPowerSignalException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function sendSignal(string $signal): ResponseInterface
{
switch ($signal) {
case self::SIGNAL_START:
case self::SIGNAL_STOP:
case self::SIGNAL_RESTART:
case self::SIGNAL_KILL:
return $this->getHttpClient()->request('PUT', 'server/power', [
'json' => [
'action' => $signal,
],
]);
default:
throw new InvalidPowerSignalException('The signal "' . $signal . '" is not defined and could not be processed.');
}
}
}