@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | 'action' => 'create', |
| 58 | 58 | 'name' => $name, |
| 59 | 59 | ]; |
| 60 | - if (!empty($password)) { |
|
| 60 | + if(!empty($password)) { |
|
| 61 | 61 | $options += ['user' => $username, 'passwd' => $password, 'passwd2' => $password]; |
| 62 | 62 | } else { |
| 63 | 63 | $options += ['userlist' => $username]; |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function getAccessHosts() |
| 85 | 85 | { |
| 86 | - return $this->getCache(self::CACHE_ACCESS_HOSTS, function () { |
|
| 86 | + return $this->getCache(self::CACHE_ACCESS_HOSTS, function() { |
|
| 87 | 87 | $accessHosts = $this->getContext()->invokeGet('DATABASES', [ |
| 88 | 88 | 'action' => 'accesshosts', |
| 89 | 89 | 'db' => $this->getDatabaseName(), |
| 90 | 90 | ]); |
| 91 | 91 | |
| 92 | - return array_map(function ($name) { |
|
| 92 | + return array_map(function($name) { |
|
| 93 | 93 | return new Database\AccessHost($name, $this); |
| 94 | 94 | }, $accessHosts); |
| 95 | 95 | }); |
@@ -57,9 +57,12 @@ |
||
| 57 | 57 | 'action' => 'create', |
| 58 | 58 | 'name' => $name, |
| 59 | 59 | ]; |
| 60 | - if (!empty($password)) { |
|
| 60 | + if (!empty($password)) |
|
| 61 | + { |
|
| 61 | 62 | $options += ['user' => $username, 'passwd' => $password, 'passwd2' => $password]; |
| 62 | - } else { |
|
| 63 | + } |
|
| 64 | + else |
|
| 65 | + { |
|
| 63 | 66 | $options += ['userlist' => $username]; |
| 64 | 67 | } |
| 65 | 68 | $user->getContext()->invokePost('DATABASES', $options); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $ukey = "u{$key}"; |
| 41 | 41 | unset($options[$ukey]); |
| 42 | - if (array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) { |
|
| 42 | + if(array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) { |
|
| 43 | 43 | $options[$ukey] = 'ON'; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public static function processUnlimitedOptions(array $options) |
| 54 | 54 | { |
| 55 | - foreach (['bandwidth', 'domainptr', 'ftp', 'mysql', 'nemailf', 'nemailml', 'nemailr', 'nemails', |
|
| 55 | + foreach(['bandwidth', 'domainptr', 'ftp', 'mysql', 'nemailf', 'nemailml', 'nemailr', 'nemails', |
|
| 56 | 56 | 'nsubdomains', 'quota', 'vdomains', ] as $key) { |
| 57 | 57 | self::processUnlimitedOption($options, $key); |
| 58 | 58 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public static function responseToArray($data) |
| 69 | 69 | { |
| 70 | - $unescaped = preg_replace_callback('/&#([0-9]{2})/', function ($val) { |
|
| 70 | + $unescaped = preg_replace_callback('/&#([0-9]{2})/', function($val) { |
|
| 71 | 71 | return chr($val[1]); |
| 72 | 72 | }, $data); |
| 73 | 73 | return \GuzzleHttp\Psr7\parse_query($unescaped); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public static function sanitizeArray($result) |
| 83 | 83 | { |
| 84 | - if (count($result) == 1 && isset($result['list[]'])) { |
|
| 84 | + if(count($result) == 1 && isset($result['list[]'])) { |
|
| 85 | 85 | $result = $result['list[]']; |
| 86 | 86 | } |
| 87 | 87 | return is_array($result) ? $result : [$result]; |
@@ -39,7 +39,8 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $ukey = "u{$key}"; |
| 41 | 41 | unset($options[$ukey]); |
| 42 | - if (array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) { |
|
| 42 | + if (array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) |
|
| 43 | + { |
|
| 43 | 44 | $options[$ukey] = 'ON'; |
| 44 | 45 | } |
| 45 | 46 | } |
@@ -53,7 +54,8 @@ discard block |
||
| 53 | 54 | public static function processUnlimitedOptions(array $options) |
| 54 | 55 | { |
| 55 | 56 | foreach (['bandwidth', 'domainptr', 'ftp', 'mysql', 'nemailf', 'nemailml', 'nemailr', 'nemails', |
| 56 | - 'nsubdomains', 'quota', 'vdomains', ] as $key) { |
|
| 57 | + 'nsubdomains', 'quota', 'vdomains', ] as $key) |
|
| 58 | + { |
|
| 57 | 59 | self::processUnlimitedOption($options, $key); |
| 58 | 60 | } |
| 59 | 61 | return $options; |
@@ -81,7 +83,8 @@ discard block |
||
| 81 | 83 | */ |
| 82 | 84 | public static function sanitizeArray($result) |
| 83 | 85 | { |
| 84 | - if (count($result) == 1 && isset($result['list[]'])) { |
|
| 86 | + if (count($result) == 1 && isset($result['list[]'])) |
|
| 87 | + { |
|
| 85 | 88 | $result = $result['list[]']; |
| 86 | 89 | } |
| 87 | 90 | return is_array($result) ? $result : [$result]; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | public function invoke($method, $command, $options = []) |
| 128 | 128 | { |
| 129 | 129 | $result = $this->rawRequest($method, '/CMD_API_' . $command, $options); |
| 130 | - if (!empty($result['error'])) { |
|
| 130 | + if(!empty($result['error'])) { |
|
| 131 | 131 | throw new DirectAdminException("$method to $command failed: $result[details] ($result[text])"); |
| 132 | 132 | } |
| 133 | 133 | return Conversion::sanitizeArray($result); |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | try { |
| 159 | 159 | $response = $this->connection->request($method, $uri, $options); |
| 160 | - if ($response->getHeader('Content-Type')[0] == 'text/html') { |
|
| 160 | + if($response->getHeader('Content-Type')[0] == 'text/html') { |
|
| 161 | 161 | throw new DirectAdminException("DirectAdmin API returned a text/html body. Requested {$uri} via {$method}. Responded: " . strip_tags($response->getBody()->getContents())); |
| 162 | 162 | } |
| 163 | 163 | $body = $response->getBody()->getContents(); |
| 164 | 164 | return Conversion::responseToArray($body); |
| 165 | - } catch (TransferException $exception) { |
|
| 165 | + } catch(TransferException $exception) { |
|
| 166 | 166 | // Rethrow anything that causes a network issue |
| 167 | 167 | throw new DirectAdminException("Request to {$uri} using {$method} failed", 0, $exception); |
| 168 | 168 | } |
@@ -127,7 +127,8 @@ discard block |
||
| 127 | 127 | public function invoke($method, $command, $options = []) |
| 128 | 128 | { |
| 129 | 129 | $result = $this->rawRequest($method, '/CMD_API_' . $command, $options); |
| 130 | - if (!empty($result['error'])) { |
|
| 130 | + if (!empty($result['error'])) |
|
| 131 | + { |
|
| 131 | 132 | throw new DirectAdminException("$method to $command failed: $result[details] ($result[text])"); |
| 132 | 133 | } |
| 133 | 134 | return Conversion::sanitizeArray($result); |
@@ -155,14 +156,18 @@ discard block |
||
| 155 | 156 | */ |
| 156 | 157 | private function rawRequest($method, $uri, $options) |
| 157 | 158 | { |
| 158 | - try { |
|
| 159 | + try |
|
| 160 | + { |
|
| 159 | 161 | $response = $this->connection->request($method, $uri, $options); |
| 160 | - if ($response->getHeader('Content-Type')[0] == 'text/html') { |
|
| 162 | + if ($response->getHeader('Content-Type')[0] == 'text/html') |
|
| 163 | + { |
|
| 161 | 164 | throw new DirectAdminException("DirectAdmin API returned a text/html body. Requested {$uri} via {$method}. Responded: " . strip_tags($response->getBody()->getContents())); |
| 162 | 165 | } |
| 163 | 166 | $body = $response->getBody()->getContents(); |
| 164 | 167 | return Conversion::responseToArray($body); |
| 165 | - } catch (TransferException $exception) { |
|
| 168 | + } |
|
| 169 | + catch (TransferException $exception) |
|
| 170 | + { |
|
| 166 | 171 | // Rethrow anything that causes a network issue |
| 167 | 172 | throw new DirectAdminException("Request to {$uri} using {$method} failed", 0, $exception); |
| 168 | 173 | } |