@@ -11,21 +11,21 @@ discard block |
||
| 11 | 11 | class Builder |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 14 | + /** |
|
| 15 | 15 | * Command prefix. |
| 16 | 16 | * |
| 17 | 17 | * @var string |
| 18 | 18 | */ |
| 19 | - public $prefix; |
|
| 19 | + public $prefix; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 21 | + /** |
|
| 22 | 22 | * Command options. |
| 23 | 23 | * |
| 24 | 24 | * @var string |
| 25 | 25 | */ |
| 26 | 26 | public $options; |
| 27 | 27 | |
| 28 | - /** |
|
| 28 | + /** |
|
| 29 | 29 | * Command arguments. |
| 30 | 30 | * |
| 31 | 31 | * @var string |
@@ -67,16 +67,16 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | $options = []; |
| 69 | 69 | foreach ($opts as $key => $value) |
| 70 | - { |
|
| 71 | - if (preg_match('/^-.*$/', $key, $matches)) |
|
| 72 | - { |
|
| 73 | - $options[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 74 | - } |
|
| 75 | - if (preg_match('/^-.*$/', $value, $matches)) |
|
| 76 | - { |
|
| 77 | - $options[] = $value; |
|
| 78 | - } |
|
| 79 | - } |
|
| 70 | + { |
|
| 71 | + if (preg_match('/^-.*$/', $key, $matches)) |
|
| 72 | + { |
|
| 73 | + $options[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 74 | + } |
|
| 75 | + if (preg_match('/^-.*$/', $value, $matches)) |
|
| 76 | + { |
|
| 77 | + $options[] = $value; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | $this->options = implode(' ', array_filter($options, 'strlen')); |
| 81 | 81 | return $this; |
| 82 | 82 | } |
@@ -89,19 +89,19 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | final public function setArguments(array $args) |
| 91 | 91 | { |
| 92 | - $arguments = []; |
|
| 92 | + $arguments = []; |
|
| 93 | 93 | foreach ($args as $key => $value) |
| 94 | - { |
|
| 95 | - if (preg_match('/^-.*$/', $key, $matches)) |
|
| 96 | - { |
|
| 97 | - $arguments[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 98 | - } |
|
| 99 | - else |
|
| 100 | - { |
|
| 101 | - $arguments[] = is_array($value) ? implode(' ', $value) : $value; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - $this->arguments = implode(' ', array_filter($arguments, 'strlen')); |
|
| 94 | + { |
|
| 95 | + if (preg_match('/^-.*$/', $key, $matches)) |
|
| 96 | + { |
|
| 97 | + $arguments[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 98 | + } |
|
| 99 | + else |
|
| 100 | + { |
|
| 101 | + $arguments[] = is_array($value) ? implode(' ', $value) : $value; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + $this->arguments = implode(' ', array_filter($arguments, 'strlen')); |
|
| 105 | 105 | return $this; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | if (preg_match('/^-.*$/', $key, $matches)) |
| 72 | 72 | { |
| 73 | - $options[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 73 | + $options[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT).$value; |
|
| 74 | 74 | } |
| 75 | 75 | if (preg_match('/^-.*$/', $value, $matches)) |
| 76 | 76 | { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | if (preg_match('/^-.*$/', $key, $matches)) |
| 96 | 96 | { |
| 97 | - $arguments[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 97 | + $arguments[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT).$value; |
|
| 98 | 98 | } |
| 99 | 99 | else |
| 100 | 100 | { |
@@ -93,12 +93,12 @@ |
||
| 93 | 93 | */ |
| 94 | 94 | final public function write($command, $returncode = FALSE) |
| 95 | 95 | { |
| 96 | - $command = ($returncode == FALSE) ? $command : $command . '; echo "RETURN_CODE:[$?]";'; |
|
| 96 | + $command = ($returncode == FALSE) ? $command : $command.'; echo "RETURN_CODE:[$?]";'; |
|
| 97 | 97 | $write_count = 0; |
| 98 | - $string_len = strlen($command . PHP_EOL); |
|
| 98 | + $string_len = strlen($command.PHP_EOL); |
|
| 99 | 99 | while ($write_count < $string_len) |
| 100 | 100 | { |
| 101 | - $fwrite_count = fwrite($this->stream, substr($command . PHP_EOL, $write_count), 1024); |
|
| 101 | + $fwrite_count = fwrite($this->stream, substr($command.PHP_EOL, $write_count), 1024); |
|
| 102 | 102 | if ($fwrite_count === FALSE) |
| 103 | 103 | { |
| 104 | 104 | throw new \RuntimeException('failed to write command to stream'); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | if ($this->is_file($srcfile) === FALSE) |
| 53 | 53 | { |
| 54 | - $this->set_error('Local file ' . $srcfile . ' does not exist.'); |
|
| 54 | + $this->set_error('Local file '.$srcfile.' does not exist.'); |
|
| 55 | 55 | $this->set_exitstatus(1); |
| 56 | 56 | return; |
| 57 | 57 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $this->set_exitstatus(1); |
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | - $this->set_output('Successfully copied file at: ' . $srcfile . ' to ' . $destfile); |
|
| 65 | + $this->set_output('Successfully copied file at: '.$srcfile.' to '.$destfile); |
|
| 66 | 66 | $this->set_exitstatus(0); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | continue; |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | - $this->set_output('Successfully deleted remote file(s) at: ' . implode(', ', $files)); |
|
| 94 | + $this->set_output('Successfully deleted remote file(s) at: '.implode(', ', $files)); |
|
| 95 | 95 | $this->set_exitstatus(0); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | if ($file != '.' && $file != '..') |
| 134 | 134 | { |
| 135 | - $filename = rtrim($path, '/') . '/' . $file; |
|
| 135 | + $filename = rtrim($path, '/').'/'.$file; |
|
| 136 | 136 | if ($this->is_dir($filename)) |
| 137 | 137 | { |
| 138 | 138 | $files['directories'][] = $filename; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $handle = opendir($this->sftp_url($directory)); |
| 170 | 170 | while (($file = readdir($handle)) !== FALSE) |
| 171 | 171 | { |
| 172 | - $files[] = preg_grep('/(^.*' . $pattern . '.*$)/', explode(PHP_EOL, $file)); |
|
| 172 | + $files[] = preg_grep('/(^.*'.$pattern.'.*$)/', explode(PHP_EOL, $file)); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | if (empty($files)) |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $_files = []; |
| 186 | 186 | foreach ($files as $file) |
| 187 | 187 | { |
| 188 | - $_files[] = rtrim($directory, '/') . '/' . $file; |
|
| 188 | + $_files[] = rtrim($directory, '/').'/'.$file; |
|
| 189 | 189 | } |
| 190 | 190 | $this->set_output($_files); |
| 191 | 191 | $this->set_exitstatus(0); |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | return; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | - $this->set_output('Successfully created remote directory(ies) at: ' . implode(', ', $directories)); |
|
| 215 | + $this->set_output('Successfully created remote directory(ies) at: '.implode(', ', $directories)); |
|
| 216 | 216 | $this->set_exitstatus(0); |
| 217 | 217 | } |
| 218 | 218 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | { |
| 228 | 228 | if ($this->is_file($oldfile) === FALSE) |
| 229 | 229 | { |
| 230 | - $this->set_error('Local file ' . $oldfile . ' does not exist.'); |
|
| 230 | + $this->set_error('Local file '.$oldfile.' does not exist.'); |
|
| 231 | 231 | $this->set_exitstatus(1); |
| 232 | 232 | return; |
| 233 | 233 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $this->set_exitstatus(1); |
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | - $this->set_output('Successfully renamed remote file at: ' . $oldfile . ' to ' . $newfile); |
|
| 241 | + $this->set_output('Successfully renamed remote file at: '.$oldfile.' to '.$newfile); |
|
| 242 | 242 | $this->set_exitstatus(0); |
| 243 | 243 | } |
| 244 | 244 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $this->set_output('Successfully removed remote directory(ies) at: ' . implode(', ', $directories)); |
|
| 284 | + $this->set_output('Successfully removed remote directory(ies) at: '.implode(', ', $directories)); |
|
| 285 | 285 | $this->set_exitstatus(0); |
| 286 | 286 | } |
| 287 | 287 | |
@@ -298,14 +298,14 @@ discard block |
||
| 298 | 298 | $local_files = !is_array($local_files) ? [$local_files] : $local_files; |
| 299 | 299 | foreach ($local_files as $local_file) |
| 300 | 300 | { |
| 301 | - if (!@ssh2_scp_send($this->connection, $local_file, rtrim($remote_dir, '/') . '/' . basename($local_file), $mode)) |
|
| 301 | + if (!@ssh2_scp_send($this->connection, $local_file, rtrim($remote_dir, '/').'/'.basename($local_file), $mode)) |
|
| 302 | 302 | { |
| 303 | 303 | $this->set_error($this->get_error_message()); |
| 304 | 304 | $this->set_exitstatus(1); |
| 305 | 305 | return; |
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | - $this->set_output('Successfully sent local files to remote host at: ' . implode(', ', $local_files)); |
|
| 308 | + $this->set_output('Successfully sent local files to remote host at: '.implode(', ', $local_files)); |
|
| 309 | 309 | $this->set_exitstatus(0); |
| 310 | 310 | } |
| 311 | 311 | |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | $remote_files = !is_array($remote_files) ? [$remote_files] : $remote_files; |
| 322 | 322 | foreach ($remote_files as $remote_file) |
| 323 | 323 | { |
| 324 | - if (!@ssh2_scp_recv($this->connection, $remote_file, rtrim($local_dir, '/') . '/' . basename($remote_file))) |
|
| 324 | + if (!@ssh2_scp_recv($this->connection, $remote_file, rtrim($local_dir, '/').'/'.basename($remote_file))) |
|
| 325 | 325 | { |
| 326 | 326 | $this->set_error($this->get_error_message()); |
| 327 | 327 | $this->set_exitstatus(1); |
| 328 | 328 | return; |
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | - $this->set_output('Successfully received remote files: ' . implode(', ', $remote_files)); |
|
| 331 | + $this->set_output('Successfully received remote files: '.implode(', ', $remote_files)); |
|
| 332 | 332 | $this->set_exitstatus(0); |
| 333 | 333 | } |
| 334 | 334 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | */ |
| 370 | 370 | final private function sftp_url($path = '') |
| 371 | 371 | { |
| 372 | - return 'ssh2.sftp://' . $this->sftp . $path; |
|
| 372 | + return 'ssh2.sftp://'.$this->sftp.$path; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | break; |
| 140 | 140 | |
| 141 | 141 | default: |
| 142 | - throw new \RuntimeException('Unknown output mode type: ' . $this->get_mode()); |
|
| 142 | + throw new \RuntimeException('Unknown output mode type: '.$this->get_mode()); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | { |
| 155 | 155 | if (!is_resource($this->connection)) |
| 156 | 156 | { |
| 157 | - throw new \RuntimeException(__FUNCTION__ . ': not a valid SSH2 Session resource.'); |
|
| 157 | + throw new \RuntimeException(__FUNCTION__.': not a valid SSH2 Session resource.'); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $command .= '; echo "RETURN_CODE:[$?]"'; |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | $auth = @ssh2_auth_none($resource, $this->username); |
| 38 | 38 | if (is_array($auth)) |
| 39 | 39 | { |
| 40 | - throw new \RuntimeException('Username based authentication failed, supported methods include: ' . implode(', ', $auth)); |
|
| 40 | + throw new \RuntimeException('Username based authentication failed, supported methods include: '.implode(', ', $auth)); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -124,7 +124,7 @@ |
||
| 124 | 124 | final public function get_error_message() |
| 125 | 125 | { |
| 126 | 126 | $this->error_message = error_get_last()['message']; |
| 127 | - return $this->error_message . ' in ' . $this->get_error_file() . ' on line ' . $this->get_error_line(); |
|
| 127 | + return $this->error_message.' in '.$this->get_error_file().' on line '.$this->get_error_line(); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |