Skip to content

Commit 3ff5798

Browse files
committed
Merge branch '5.1'
Signed-off-by: Tom Shafer <[email protected]> # Conflicts: # src/SecLibGateway.php
2 parents a5f9be5 + b31a78b commit 3ff5798

File tree

6 files changed

+358
-248
lines changed

6 files changed

+358
-248
lines changed

config/remote.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
|
1414
*/
1515

16-
'default' => 'production',
16+
'default' => 'production',
1717

1818
/*
1919
|--------------------------------------------------------------------------
@@ -35,6 +35,7 @@
3535
'keytext' => '',
3636
'keyphrase' => '',
3737
'agent' => '',
38+
'timeout' => 10,
3839
],
3940
],
4041

@@ -49,7 +50,7 @@
4950
|
5051
*/
5152

52-
'groups' => [
53+
'groups' => [
5354
'web' => ['production'],
5455
],
5556

src/Connection.php

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ class Connection implements ConnectionInterface
5454
/**
5555
* Create a new SSH connection instance.
5656
*
57-
* @param string $name
58-
* @param string $host
59-
* @param string $username
60-
* @param array $auth
61-
* @param \Collective\Remote\GatewayInterface
62-
* @param
57+
* @param string $name
58+
* @param string $host
59+
* @param string $username
60+
* @param array $auth
61+
* @param \Collective\Remote\GatewayInterface $gateway
62+
* @param int $timeout
6363
*/
64-
public function __construct($name, $host, $username, array $auth, GatewayInterface $gateway = null)
64+
public function __construct($name, $host, $username, array $auth, GatewayInterface $gateway = null, $timeout = 10)
6565
{
6666
$this->name = $name;
6767
$this->host = $host;
6868
$this->username = $username;
69-
$this->gateway = $gateway ?: new SecLibGateway($host, $auth, new Filesystem());
69+
$this->gateway = $gateway ?: new SecLibGateway($host, $auth, new Filesystem(), $timeout);
7070
}
7171

7272
/**
@@ -79,7 +79,7 @@ public function __construct($name, $host, $username, array $auth, GatewayInterfa
7979
*/
8080
public function define($task, $commands)
8181
{
82-
$this->tasks[ $task ] = $commands;
82+
$this->tasks[$task] = $commands;
8383
}
8484

8585
/**
@@ -92,8 +92,8 @@ public function define($task, $commands)
9292
*/
9393
public function task($task, Closure $callback = null)
9494
{
95-
if (isset($this->tasks[ $task ])) {
96-
return $this->run($this->tasks[ $task ], $callback);
95+
if (isset($this->tasks[$task])) {
96+
$this->run($this->tasks[$task], $callback);
9797
}
9898
}
9999

@@ -128,6 +128,94 @@ public function run($commands, Closure $callback = null)
128128
}
129129
}
130130

131+
/**
132+
* Get the gateway implementation.
133+
*
134+
* @throws \RuntimeException
135+
*
136+
* @return \Collective\Remote\GatewayInterface
137+
*/
138+
public function getGateway()
139+
{
140+
if (!$this->gateway->connected() && !$this->gateway->connect($this->username)) {
141+
throw new \RuntimeException('Unable to connect to remote server.');
142+
}
143+
144+
return $this->gateway;
145+
}
146+
147+
/**
148+
* Get the display callback for the connection.
149+
*
150+
* @param \Closure|null $callback
151+
*
152+
* @return \Closure
153+
*/
154+
protected function getCallback($callback)
155+
{
156+
if (!is_null($callback)) {
157+
return $callback;
158+
}
159+
160+
return function ($line) {
161+
$this->display($line);
162+
};
163+
}
164+
165+
/**
166+
* Display the given line using the default output.
167+
*
168+
* @param string $line
169+
*
170+
* @return void
171+
*/
172+
public function display($line)
173+
{
174+
$server = $this->username.'@'.$this->host;
175+
176+
$lead = '<comment>['.$server.']</comment> <info>('.$this->name.')</info>';
177+
178+
$this->getOutput()->writeln($lead.' '.$line);
179+
}
180+
181+
/**
182+
* Get the output implementation for the connection.
183+
*
184+
* @return \Symfony\Component\Console\Output\OutputInterface
185+
*/
186+
public function getOutput()
187+
{
188+
if (is_null($this->output)) {
189+
$this->output = new NullOutput();
190+
}
191+
192+
return $this->output;
193+
}
194+
195+
/**
196+
* Set the output implementation.
197+
*
198+
* @param \Symfony\Component\Console\Output\OutputInterface $output
199+
*
200+
* @return void
201+
*/
202+
public function setOutput(OutputInterface $output)
203+
{
204+
$this->output = $output;
205+
}
206+
207+
/**
208+
* Format the given command set.
209+
*
210+
* @param string|array $commands
211+
*
212+
* @return string
213+
*/
214+
protected function formatCommands($commands)
215+
{
216+
return is_array($commands) ? implode(' && ', $commands) : $commands;
217+
}
218+
131219
/**
132220
* Download the contents of a remote file.
133221
*
@@ -216,52 +304,6 @@ public function delete($remote)
216304
return $this->getGateway()->delete($remote);
217305
}
218306

219-
/**
220-
* Display the given line using the default output.
221-
*
222-
* @param string $line
223-
*
224-
* @return void
225-
*/
226-
public function display($line)
227-
{
228-
$server = $this->username.'@'.$this->host;
229-
230-
$lead = '<comment>['.$server.']</comment> <info>('.$this->name.')</info>';
231-
232-
$this->getOutput()->writeln($lead.' '.$line);
233-
}
234-
235-
/**
236-
* Format the given command set.
237-
*
238-
* @param string|array $commands
239-
*
240-
* @return string
241-
*/
242-
protected function formatCommands($commands)
243-
{
244-
return is_array($commands) ? implode(' && ', $commands) : $commands;
245-
}
246-
247-
/**
248-
* Get the display callback for the connection.
249-
*
250-
* @param \Closure|null $callback
251-
*
252-
* @return \Closure
253-
*/
254-
protected function getCallback($callback)
255-
{
256-
if (!is_null($callback)) {
257-
return $callback;
258-
}
259-
260-
return function ($line) {
261-
$this->display($line);
262-
};
263-
}
264-
265307
/**
266308
* Get the exit status of the last command.
267309
*
@@ -271,46 +313,4 @@ public function status()
271313
{
272314
return $this->gateway->status();
273315
}
274-
275-
/**
276-
* Get the gateway implementation.
277-
*
278-
* @throws \RuntimeException
279-
*
280-
* @return \Collective\Remote\GatewayInterface
281-
*/
282-
public function getGateway()
283-
{
284-
if (!$this->gateway->connected() && !$this->gateway->connect($this->username)) {
285-
throw new \RuntimeException('Unable to connect to remote server.');
286-
}
287-
288-
return $this->gateway;
289-
}
290-
291-
/**
292-
* Get the output implementation for the connection.
293-
*
294-
* @return \Symfony\Component\Console\Output\OutputInterface
295-
*/
296-
public function getOutput()
297-
{
298-
if (is_null($this->output)) {
299-
$this->output = new NullOutput();
300-
}
301-
302-
return $this->output;
303-
}
304-
305-
/**
306-
* Set the output implementation.
307-
*
308-
* @param \Symfony\Component\Console\Output\OutputInterface $output
309-
*
310-
* @return void
311-
*/
312-
public function setOutput(OutputInterface $output)
313-
{
314-
$this->output = $output;
315-
}
316316
}

src/MultiConnection.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,35 @@ public function run($commands, Closure $callback = null)
6868
}
6969
}
7070

71+
/**
72+
* Download the contents of a remote file.
73+
*
74+
* @param string $remote
75+
* @param string $local
76+
*
77+
* @return void
78+
*/
79+
public function get($remote, $local)
80+
{
81+
foreach ($this->connections as $connection) {
82+
$connection->get($remote, $local);
83+
}
84+
}
85+
86+
/**
87+
* Get the contents of a remote file.
88+
*
89+
* @param string $remote
90+
*
91+
* @return string
92+
*/
93+
public function getString($remote)
94+
{
95+
foreach ($this->connections as $connection) {
96+
$connection->getString($remote);
97+
}
98+
}
99+
71100
/**
72101
* Upload a local file to the server.
73102
*
@@ -97,4 +126,47 @@ public function putString($remote, $contents)
97126
$connection->putString($remote, $contents);
98127
}
99128
}
129+
130+
/**
131+
* Check whether a given file exists on the server.
132+
*
133+
* @param string $remote
134+
*
135+
* @return bool
136+
*/
137+
public function exists($remote)
138+
{
139+
foreach ($this->connections as $connection) {
140+
$connection->exists($remote);
141+
}
142+
}
143+
144+
/**
145+
* Rename a remote file.
146+
*
147+
* @param string $remote
148+
* @param string $newRemote
149+
*
150+
* @return bool
151+
*/
152+
public function rename($remote, $newRemote)
153+
{
154+
foreach ($this->connections as $connection) {
155+
$connection->rename($remote, $newRemote);
156+
}
157+
}
158+
159+
/**
160+
* Delete a remote file from the server.
161+
*
162+
* @param string $remote
163+
*
164+
* @return bool
165+
*/
166+
public function delete($remote)
167+
{
168+
foreach ($this->connections as $connection) {
169+
$connection->delete($remote);
170+
}
171+
}
100172
}

0 commit comments

Comments
 (0)