Files
panel/app/Repositories/Daemon/DaemonRepository.php

51 lines
1.0 KiB
PHP
Raw Normal View History

<?php
2024-03-12 22:39:16 -04:00
namespace App\Repositories\Daemon;
2024-03-12 22:39:16 -04:00
use App\Models\Node;
2024-03-23 16:10:47 -04:00
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
use Webmozart\Assert\Assert;
2024-03-12 22:39:16 -04:00
use App\Models\Server;
abstract class DaemonRepository
{
protected ?Server $server;
protected ?Node $node;
/**
* Set the server model this request is stemming from.
2024-03-17 13:59:21 -04:00
*
* @return static
*/
2024-03-17 13:59:21 -04:00
public function setServer(Server $server): self
{
$this->server = $server;
$this->setNode($this->server->node);
return $this;
}
/**
* Set the node model this request is stemming from.
*/
2024-03-17 12:52:22 -04:00
public function setNode(Node $node): static
{
$this->node = $node;
return $this;
}
/**
* Return an instance of the Guzzle HTTP Client to be used for requests.
*/
2024-03-23 16:10:47 -04:00
public function getHttpClient(array $headers = []): PendingRequest
{
Assert::isInstanceOf($this->node, Node::class);
2024-03-23 16:10:47 -04:00
return Http::daemon($this->node, $headers);
}
}