From 9e904880c13c46cb4f82b36c570b0ede0e70a79d Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Sun, 15 Jan 2017 01:17:20 +0100 Subject: [PATCH] Rename API invocation methods to explicitly include API Separate API invocations more clearly from possible other invocations. Refs #22 --- src/DirectAdmin/Context/AdminContext.php | 6 +++--- src/DirectAdmin/Context/BaseContext.php | 8 ++++---- src/DirectAdmin/Context/ResellerContext.php | 10 +++++----- src/DirectAdmin/Context/UserContext.php | 2 +- src/DirectAdmin/DirectAdmin.php | 2 +- src/DirectAdmin/Objects/Database.php | 6 +++--- .../Objects/Database/AccessHost.php | 4 ++-- src/DirectAdmin/Objects/Domain.php | 20 +++++++++---------- src/DirectAdmin/Objects/Email/Mailbox.php | 2 +- src/DirectAdmin/Objects/Users/Reseller.php | 2 +- src/DirectAdmin/Objects/Users/User.php | 10 +++++----- tests/DirectAdmin/EnvironmentTest.php | 2 +- 12 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/DirectAdmin/Context/AdminContext.php b/src/DirectAdmin/Context/AdminContext.php index 17fd54d..92b6fcd 100644 --- a/src/DirectAdmin/Context/AdminContext.php +++ b/src/DirectAdmin/Context/AdminContext.php @@ -63,7 +63,7 @@ public function createReseller($username, $password, $email, $domain, $package = */ public function getAdmins() { - return BaseObject::toObjectArray($this->invokeGet('SHOW_ADMINS'), Admin::class, $this); + return BaseObject::toObjectArray($this->invokeApiGet('SHOW_ADMINS'), Admin::class, $this); } /** @@ -85,7 +85,7 @@ public function getAllAccounts() */ public function getAllUsers() { - return BaseObject::toObjectArray($this->invokeGet('SHOW_ALL_USERS'), User::class, $this); + return BaseObject::toObjectArray($this->invokeApiGet('SHOW_ALL_USERS'), User::class, $this); } /** @@ -107,7 +107,7 @@ public function getReseller($username) */ public function getResellers() { - return BaseObject::toObjectArray($this->invokeGet('SHOW_RESELLERS'), Reseller::class, $this); + return BaseObject::toObjectArray($this->invokeApiGet('SHOW_RESELLERS'), Reseller::class, $this); } /** diff --git a/src/DirectAdmin/Context/BaseContext.php b/src/DirectAdmin/Context/BaseContext.php index 8f59f24..ab3f77d 100644 --- a/src/DirectAdmin/Context/BaseContext.php +++ b/src/DirectAdmin/Context/BaseContext.php @@ -49,9 +49,9 @@ protected function getConnection() * @param array $query Optional query parameters * @return array The parsed and validated response */ - public function invokeGet($command, $query = []) + public function invokeApiGet($command, $query = []) { - return $this->connection->invoke('GET', $command, ['query' => $query]); + return $this->connection->invokeApi('GET', $command, ['query' => $query]); } /** @@ -61,8 +61,8 @@ public function invokeGet($command, $query = []) * @param array $postParameters Optional form parameters * @return array The parsed and validated response */ - public function invokePost($command, $postParameters = []) + public function invokeApiPost($command, $postParameters = []) { - return $this->connection->invoke('POST', $command, ['form_params' => $postParameters]); + return $this->connection->invokeApi('POST', $command, ['form_params' => $postParameters]); } } diff --git a/src/DirectAdmin/Context/ResellerContext.php b/src/DirectAdmin/Context/ResellerContext.php index 05e1019..fd61e8c 100644 --- a/src/DirectAdmin/Context/ResellerContext.php +++ b/src/DirectAdmin/Context/ResellerContext.php @@ -54,7 +54,7 @@ public function createUser($username, $password, $email, $domain, $ip, $package */ protected function createAccount($username, $password, $email, $options, $endpoint, $returnType) { - $this->invokePost($endpoint, array_merge($options, [ + $this->invokeApiPost($endpoint, array_merge($options, [ 'action' => 'create', 'add' => 'Submit', 'email' => $email, @@ -86,7 +86,7 @@ public function deleteAccounts(array $usernames) foreach (array_values($usernames) as $idx => $username) { $options["select{$idx}"] = $username; } - $this->invokePost('SELECT_USERS', $options); + $this->invokeApiPost('SELECT_USERS', $options); } /** @@ -121,7 +121,7 @@ public function suspendAccounts(array $usernames, $suspend = true) foreach (array_values($usernames) as $idx => $username) { $options['select' . $idx] = $username; } - $this->invokePost('SELECT_USERS', $options); + $this->invokeApiPost('SELECT_USERS', $options); } /** @@ -141,7 +141,7 @@ public function unsuspendAccounts(array $usernames) */ public function getIPs() { - return $this->invokeGet('SHOW_RESELLER_IPS'); + return $this->invokeApiGet('SHOW_RESELLER_IPS'); } /** @@ -163,7 +163,7 @@ public function getUser($username) */ public function getUsers() { - return BaseObject::toObjectArray($this->invokeGet('SHOW_USERS'), User::class, $this); + return BaseObject::toObjectArray($this->invokeApiGet('SHOW_USERS'), User::class, $this); } /** diff --git a/src/DirectAdmin/Context/UserContext.php b/src/DirectAdmin/Context/UserContext.php index c00083a..a24ad24 100644 --- a/src/DirectAdmin/Context/UserContext.php +++ b/src/DirectAdmin/Context/UserContext.php @@ -66,7 +66,7 @@ public function getType() public function getContextUser() { if (!isset($this->user)) { - $this->user = User::fromConfig($this->invokeGet('SHOW_USER_CONFIG'), $this); + $this->user = User::fromConfig($this->invokeApiGet('SHOW_USER_CONFIG'), $this); } return $this->user; } diff --git a/src/DirectAdmin/DirectAdmin.php b/src/DirectAdmin/DirectAdmin.php index 5620ffa..5b92186 100644 --- a/src/DirectAdmin/DirectAdmin.php +++ b/src/DirectAdmin/DirectAdmin.php @@ -124,7 +124,7 @@ public function getUsername() * @return array The unvalidated response * @throws DirectAdminException If anything went wrong on the network level */ - public function invoke($method, $command, $options = []) + public function invokeApi($method, $command, $options = []) { $result = $this->rawRequest($method, '/CMD_API_' . $command, $options); if (!empty($result['error'])) { diff --git a/src/DirectAdmin/Objects/Database.php b/src/DirectAdmin/Objects/Database.php index 0eee1e6..e007817 100644 --- a/src/DirectAdmin/Objects/Database.php +++ b/src/DirectAdmin/Objects/Database.php @@ -62,7 +62,7 @@ public static function create(User $user, $name, $username, $password) } else { $options += ['userlist' => $username]; } - $user->getContext()->invokePost('DATABASES', $options); + $user->getContext()->invokeApiPost('DATABASES', $options); return new self($name, $user, $user->getContext()); } @@ -71,7 +71,7 @@ public static function create(User $user, $name, $username, $password) */ public function delete() { - $this->getContext()->invokePost('DATABASES', [ + $this->getContext()->invokeApiPost('DATABASES', [ 'action' => 'delete', 'select0' => $this->getDatabaseName(), ]); @@ -84,7 +84,7 @@ public function delete() public function getAccessHosts() { return $this->getCache(self::CACHE_ACCESS_HOSTS, function () { - $accessHosts = $this->getContext()->invokeGet('DATABASES', [ + $accessHosts = $this->getContext()->invokeApiGet('DATABASES', [ 'action' => 'accesshosts', 'db' => $this->getDatabaseName(), ]); diff --git a/src/DirectAdmin/Objects/Database/AccessHost.php b/src/DirectAdmin/Objects/Database/AccessHost.php index 68b777e..eb30ae4 100644 --- a/src/DirectAdmin/Objects/Database/AccessHost.php +++ b/src/DirectAdmin/Objects/Database/AccessHost.php @@ -38,7 +38,7 @@ public function __construct($host, Database $database) */ public static function create(Database $database, $host) { - $database->getContext()->invokePost('DATABASES', [ + $database->getContext()->invokeApiPost('DATABASES', [ 'action' => 'accesshosts', 'create' => 'yes', 'db' => $database->getDatabaseName(), @@ -52,7 +52,7 @@ public static function create(Database $database, $host) */ public function delete() { - $this->getContext()->invokePost('DATABASES', [ + $this->getContext()->invokeApiPost('DATABASES', [ 'action' => 'accesshosts', 'delete' => 'yes', 'db' => $this->database->getDatabaseName(), diff --git a/src/DirectAdmin/Objects/Domain.php b/src/DirectAdmin/Objects/Domain.php index c68d9e5..34ca034 100644 --- a/src/DirectAdmin/Objects/Domain.php +++ b/src/DirectAdmin/Objects/Domain.php @@ -89,8 +89,8 @@ public static function create(User $user, $domainName, $bandwidthLimit = null, $ 'php' => Conversion::onOff($php, $user->hasPHP()), 'cgi' => Conversion::onOff($cgi, $user->hasCGI()), ]; - $user->getContext()->invokePost('DOMAIN', $options); - $config = $user->getContext()->invokeGet('ADDITIONAL_DOMAINS'); + $user->getContext()->invokeApiPost('DOMAIN', $options); + $config = $user->getContext()->invokeApiGet('ADDITIONAL_DOMAINS'); return new self($domainName, $user->getContext(), $config[$domainName]); } @@ -139,7 +139,7 @@ public function createPointer($domain, $alias = false) } else { $list = &$this->pointers; } - $this->getContext()->invokePost('DOMAIN_POINTER', $parameters); + $this->getContext()->invokeApiPost('DOMAIN_POINTER', $parameters); $list[] = $domain; $list = array_unique($list); } @@ -160,7 +160,7 @@ public function createSubdomain($prefix) */ public function delete() { - $this->getContext()->invokePost('DOMAIN', [ + $this->getContext()->invokeApiPost('DOMAIN', [ 'delete' => true, 'confirmed' => true, 'select0' => $this->domainName, @@ -197,7 +197,7 @@ public function getBandwidthLimit() */ public function getCatchall() { - $value = $this->getContext()->invokeGet('EMAIL_CATCH_ALL', ['domain' => $this->domainName]); + $value = $this->getContext()->invokeApiGet('EMAIL_CATCH_ALL', ['domain' => $this->domainName]); return isset($value['value']) ? $value['value'] : null; } @@ -237,7 +237,7 @@ public function getDomainNames() public function getForwarders() { return $this->getCache(self::CACHE_FORWARDERS, function () { - $forwarders = $this->getContext()->invokeGet('EMAIL_FORWARDERS', [ + $forwarders = $this->getContext()->invokeApiGet('EMAIL_FORWARDERS', [ 'domain' => $this->getDomainName(), ]); return DomainObject::toDomainObjectArray($forwarders, Forwarder::class, $this); @@ -250,7 +250,7 @@ public function getForwarders() public function getMailboxes() { return $this->getCache(self::CACHE_MAILBOXES, function () { - $boxes = $this->getContext()->invokeGet('POP', [ + $boxes = $this->getContext()->invokeApiGet('POP', [ 'domain' => $this->getDomainName(), 'action' => 'full_list', ]); @@ -280,7 +280,7 @@ public function getPointers() public function getSubdomains() { return $this->getCache(self::CACHE_SUBDOMAINS, function () { - $subs = $this->getContext()->invokeGet('SUBDOMAINS', ['domain' => $this->getDomainName()]); + $subs = $this->getContext()->invokeApiGet('SUBDOMAINS', ['domain' => $this->getDomainName()]); $subs = array_combine($subs, $subs); return DomainObject::toDomainObjectArray($subs, Subdomain::class, $this); }); @@ -297,7 +297,7 @@ public function getSubdomains() */ public function invokePost($command, $action, $parameters = [], $clearCache = true) { - $response = $this->getContext()->invokePost($command, array_merge([ + $response = $this->getContext()->invokeApiPost($command, array_merge([ 'action' => $action, 'domain' => $this->domainName, ], $parameters)); @@ -314,7 +314,7 @@ public function setCatchall($newValue) { $parameters = array_merge(['domain' => $this->domainName, 'update' => 'Update'], (empty($newValue) || $newValue[0] == ':') ? ['catch' => $newValue] : ['catch' => 'address', 'value' => $newValue]); - $this->getContext()->invokePost('EMAIL_CATCH_ALL', $parameters); + $this->getContext()->invokeApiPost('EMAIL_CATCH_ALL', $parameters); } /** diff --git a/src/DirectAdmin/Objects/Email/Mailbox.php b/src/DirectAdmin/Objects/Email/Mailbox.php index 8fa6981..0046cbd 100644 --- a/src/DirectAdmin/Objects/Email/Mailbox.php +++ b/src/DirectAdmin/Objects/Email/Mailbox.php @@ -119,7 +119,7 @@ public function getMailsSent() protected function getData($key) { return $this->getCacheItem(self::CACHE_DATA, $key, function () { - $result = $this->getContext()->invokeGet('POP', [ + $result = $this->getContext()->invokeApiGet('POP', [ 'domain' => $this->getDomainName(), 'action' => 'full_list', ]); diff --git a/src/DirectAdmin/Objects/Users/Reseller.php b/src/DirectAdmin/Objects/Users/Reseller.php index 55d2152..c535f75 100644 --- a/src/DirectAdmin/Objects/Users/Reseller.php +++ b/src/DirectAdmin/Objects/Users/Reseller.php @@ -46,7 +46,7 @@ public function getUser($username) */ public function getUsers() { - return BaseObject::toObjectArray($this->getContext()->invokeGet('SHOW_USERS', ['reseller' => $this->getUsername()]), + return BaseObject::toObjectArray($this->getContext()->invokeApiGet('SHOW_USERS', ['reseller' => $this->getUsername()]), User::class, $this->getContext()); } diff --git a/src/DirectAdmin/Objects/Users/User.php b/src/DirectAdmin/Objects/Users/User.php index 37418f2..5670ede 100644 --- a/src/DirectAdmin/Objects/Users/User.php +++ b/src/DirectAdmin/Objects/Users/User.php @@ -206,7 +206,7 @@ public function getDatabases() { return $this->getCache(self::CACHE_DATABASES, function () { $databases = []; - foreach ($this->getSelfManagedContext()->invokeGet('DATABASES') as $fullName) { + foreach ($this->getSelfManagedContext()->invokeApiGet('DATABASES') as $fullName) { list($user, $db) = explode('_', $fullName, 2); if ($this->getUsername() != $user) { throw new DirectAdminException('Username incorrect on database ' . $fullName); @@ -238,7 +238,7 @@ public function getDomains() if (!$this->isSelfManaged()) { $this->domains = $this->impersonate()->getDomains(); } else { - $this->domains = BaseObject::toRichObjectArray($this->getContext()->invokeGet('ADDITIONAL_DOMAINS'), Domain::class, $this->getContext()); + $this->domains = BaseObject::toRichObjectArray($this->getContext()->invokeApiGet('ADDITIONAL_DOMAINS'), Domain::class, $this->getContext()); } } return $this->domains; @@ -297,7 +297,7 @@ public function impersonate() */ public function modifyConfig(array $newConfig) { - $this->getContext()->invokePost('MODIFY_USER', array_merge( + $this->getContext()->invokeApiPost('MODIFY_USER', array_merge( $this->loadConfig(), Conversion::processUnlimitedOptions($newConfig), ['action' => 'customize', 'user' => $this->getUsername()] @@ -382,7 +382,7 @@ private function getConfig($item) private function getUsage($item) { return $this->getCacheItem(self::CACHE_USAGE, $item, function () { - return $this->getContext()->invokeGet('SHOW_USER_USAGE', ['user' => $this->getUsername()]); + return $this->getContext()->invokeApiGet('SHOW_USER_USAGE', ['user' => $this->getUsername()]); }); } @@ -417,6 +417,6 @@ protected function isSelfManaged() */ private function loadConfig() { - return $this->getContext()->invokeGet('SHOW_USER_CONFIG', ['user' => $this->getUsername()]); + return $this->getContext()->invokeApiGet('SHOW_USER_CONFIG', ['user' => $this->getUsername()]); } } diff --git a/tests/DirectAdmin/EnvironmentTest.php b/tests/DirectAdmin/EnvironmentTest.php index b567863..a974179 100644 --- a/tests/DirectAdmin/EnvironmentTest.php +++ b/tests/DirectAdmin/EnvironmentTest.php @@ -50,7 +50,7 @@ public function testInvalidPassword() public function testInvalidCall() { $admin = DirectAdmin::connectAdmin(DIRECTADMIN_URL, MASTER_ADMIN_USERNAME, MASTER_ADMIN_PASSWORD); - $admin->invokeGet('INVALID_COMMAND'); + $admin->invokeApiGet('INVALID_COMMAND'); } /**