32 lines
		
	
	
		
			899 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			899 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Repositories\Daemon;
 | |
| 
 | |
| use Webmozart\Assert\Assert;
 | |
| use App\Models\Server;
 | |
| use Psr\Http\Message\ResponseInterface;
 | |
| use GuzzleHttp\Exception\TransferException;
 | |
| use App\Exceptions\Http\Connection\DaemonConnectionException;
 | |
| 
 | |
| class DaemonPowerRepository extends DaemonRepository
 | |
| {
 | |
|     /**
 | |
|      * Sends a power action to the server instance.
 | |
|      *
 | |
|      * @throws \App\Exceptions\Http\Connection\DaemonConnectionException
 | |
|      */
 | |
|     public function send(string $action): ResponseInterface
 | |
|     {
 | |
|         Assert::isInstanceOf($this->server, Server::class);
 | |
| 
 | |
|         try {
 | |
|             return $this->getHttpClient()->post(
 | |
|                 sprintf('/api/servers/%s/power', $this->server->uuid),
 | |
|                 ['json' => ['action' => $action]]
 | |
|             );
 | |
|         } catch (TransferException $exception) {
 | |
|             throw new DaemonConnectionException($exception);
 | |
|         }
 | |
|     }
 | |
| }
 | 
