Skip to content

Commit 685d6f9

Browse files
authored
feat: add the ability to magically get a resource through a method (#37)
1 parent 32c1b84 commit 685d6f9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Client.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public function __get(string $name)
4848
return $this->getService($name);
4949
}
5050

51+
/**
52+
* Magic method to retrieve a service by name.
53+
*/
54+
public function __call(string $name, array $arguments)
55+
{
56+
return $this->getService($name);
57+
}
58+
5159
/**
5260
* Attach the given API service to the client.
5361
*/

tests/Client.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020
->to->toBe('[email protected]');
2121
});
2222

23-
test('service is created when required', function () {
23+
test('service is created when required through property', function () {
2424
$resend = Resend::client('foo');
2525

2626
expect($resend->apiKeys)
2727
->toBeInstanceOf(ApiKey::class);
2828
});
29+
30+
test('sevice is created when required through method', function () {
31+
$resend = Resend::client('foo');
32+
33+
expect($resend->apiKeys())
34+
->toBeInstanceOf(ApiKey::class);
35+
});

0 commit comments

Comments
 (0)