diff --git a/README.md b/README.md index 834f274..821d7c8 100644 --- a/README.md +++ b/README.md @@ -68,17 +68,6 @@ user, you can use the `become` method: $result = DirectAdmin::become('user')->post('{DIRECTADMIN_API_CALL}'); ``` -### Passing the DirectAdmin API call as a method - -You can also call any DirectAdmin API command by passing it as method to -the `DirectAdmin` facade like so: - -```php -$result = DirectAdmin::CMD_API_DOMAIN_OWNERS(); -``` - -This will be a POST request by default. - For more information on the available commands, please refer to the [DirectAdmin API documentation](https://docs.directadmin.com/directadmin/customizing-workflow/api-all-about.html). diff --git a/src/DirectAdmin.php b/src/DirectAdmin.php index 3216aa2..a2ddab1 100755 --- a/src/DirectAdmin.php +++ b/src/DirectAdmin.php @@ -2,10 +2,12 @@ namespace Sensson\DirectAdmin; +use Carbon\Traits\Macro; use Illuminate\Http\Client\ConnectionException; use Illuminate\Http\Client\Response; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Tappable; use JsonException; use Sensson\DirectAdmin\Enums\Method; @@ -17,6 +19,7 @@ class DirectAdmin { + use Macroable; use Tappable; public bool $debug = false; @@ -143,13 +146,4 @@ protected function getQueryParams(): array 'json' => 'yes', ]; } - - public function __call(string $name, array $arguments) - { - if (method_exists($this, $name)) { - return $this->{$name}(...$arguments); - } - - return $this->call($name, $arguments); - } } diff --git a/tests/DirectAdminTest.php b/tests/DirectAdminTest.php index 8674528..9a4ce59 100644 --- a/tests/DirectAdminTest.php +++ b/tests/DirectAdminTest.php @@ -24,21 +24,6 @@ ]); }); -it('processes api call directly', function () { - Http::fake(function () { - return Http::response([ - 'domain.com' => 'username', - ]); - }); - - $response = app(DirectAdmin::class)->CMD_API_DOMAIN_OWNERS(); - - expect($response->toArray()) - ->toMatchArray([ - 'domain.com' => 'username', - ]); -}); - it('becomes a user', function () { config()->set('directadmin.username', 'admin'); $directadmin = app(DirectAdmin::class)->become('user'); @@ -46,18 +31,6 @@ expect($directadmin->username)->toBe('admin|user'); }); -it('becomes a user even when passing the command as a method', function () { - Http::fake(function () { - return Http::response([ - 'domain.com' => 'username', - ]); - }); - - config()->set('directadmin.username', 'admin'); - /** @noinspection PhpUndefinedMethodInspection */ - app(DirectAdmin::class)->become('user')->CMD_API_DOMAIN_OWNERS(); -})->throwsNoExceptions(); - it('fails when incorrect credentials are used', function () { Http::fake(fn () => Http::response([], 401));