2017-08-26 23:08:11 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-08-26 23:08:11 +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
|
2017-08-26 23:08:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Daemon;
|
|
|
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface;
|
|
|
|
use Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException;
|
|
|
|
|
|
|
|
class PowerRepository extends BaseRepository implements PowerRepositoryInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function sendSignal($signal)
|
|
|
|
{
|
|
|
|
Assert::stringNotEmpty($signal, 'The first argument passed to sendSignal must be a non-empty string, received %s.');
|
|
|
|
|
|
|
|
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,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new InvalidPowerSignalException('The signal ' . $signal . ' is not defined and could not be processed.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|