mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 14:56:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			37 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.');
 | |
|         }
 | |
|     }
 | |
| }
 | 
