Skip to content

Commit 2f235e0

Browse files
committed
fix: Refactor Client and update handler methods.
Reordered constructor parameters for clarity and consistency. Added dedicated handler methods for Accounting, Domain, and RootServer with lazy instantiation. Updated README to reflect method naming changes.
1 parent 3453f41 commit 2f235e0

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ $token = getenv('24FIRE_API_KEY');
5555
$client = new FireAPI($token, true); // 'true' activates the sandbox environment
5656

5757
// Request to the server in the sandbox environment
58-
var_dump($client->RootServer()->getAll());
58+
var_dump($client->rootServer()->getAll());
5959
?>
6060
```

src/Client.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace FireAPI;
44

5+
use FireAPI\Accounting\Accounting;
6+
use FireAPI\Domain\Domain;
57
use FireAPI\Exceptions\ParameterException;
8+
use FireAPI\RootServer\RootServer;
69
use GuzzleHttp\Exception\GuzzleException;
710
use Psr\Http\Message\ResponseInterface;
811
use RuntimeException;
@@ -20,7 +23,7 @@ class Client
2023
* @param \GuzzleHttp\Client|null $httpClient
2124
* @param bool $sandbox
2225
*/
23-
public function __construct(string $token, ?\GuzzleHttp\Client $httpClient = null, bool $sandbox = false)
26+
public function __construct(string $token, bool $sandbox = false, ?\GuzzleHttp\Client $httpClient = null)
2427
{
2528
$this->token = $token;
2629
$this->setHttpClient($httpClient);
@@ -172,4 +175,36 @@ public function delete(string $actionPath, array $params = []): mixed
172175
$response = $this->request($actionPath, $params, 'DELETE');
173176
return $this->processRequest($response);
174177
}
178+
179+
/**
180+
* Retrieve the accounting handler instance.
181+
*
182+
* If the accounting handler does not already exist, it initializes a new instance.
183+
*
184+
* @return Accounting
185+
*/
186+
public function accounting(): Accounting
187+
{
188+
return $this->accountingHandler ??= new Accounting($this);
189+
}
190+
191+
/**
192+
* Retrieve the domain handler instance.
193+
*
194+
* @return Domain
195+
*/
196+
public function domain(): Domain
197+
{
198+
return $this->domainHandler ??= new Domain($this);
199+
}
200+
201+
/**
202+
* Retrieves the RootServer instance. If the instance does not already exist, it initializes a new RootServer object.
203+
*
204+
* @return RootServer The instance of the RootServer.
205+
*/
206+
public function rootServer(): RootServer
207+
{
208+
return $this->rootServerHandler ??= new RootServer($this);
209+
}
175210
}

0 commit comments

Comments
 (0)