@@ -54,19 +54,19 @@ class Connection implements ConnectionInterface
54
54
/**
55
55
* Create a new SSH connection instance.
56
56
*
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
63
63
*/
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 )
65
65
{
66
66
$ this ->name = $ name ;
67
67
$ this ->host = $ host ;
68
68
$ this ->username = $ username ;
69
- $ this ->gateway = $ gateway ?: new SecLibGateway ($ host , $ auth , new Filesystem ());
69
+ $ this ->gateway = $ gateway ?: new SecLibGateway ($ host , $ auth , new Filesystem (), $ timeout );
70
70
}
71
71
72
72
/**
@@ -79,7 +79,7 @@ public function __construct($name, $host, $username, array $auth, GatewayInterfa
79
79
*/
80
80
public function define ($ task , $ commands )
81
81
{
82
- $ this ->tasks [ $ task ] = $ commands ;
82
+ $ this ->tasks [$ task ] = $ commands ;
83
83
}
84
84
85
85
/**
@@ -92,8 +92,8 @@ public function define($task, $commands)
92
92
*/
93
93
public function task ($ task , Closure $ callback = null )
94
94
{
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 );
97
97
}
98
98
}
99
99
@@ -128,6 +128,94 @@ public function run($commands, Closure $callback = null)
128
128
}
129
129
}
130
130
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
+
131
219
/**
132
220
* Download the contents of a remote file.
133
221
*
@@ -216,52 +304,6 @@ public function delete($remote)
216
304
return $ this ->getGateway ()->delete ($ remote );
217
305
}
218
306
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
-
265
307
/**
266
308
* Get the exit status of the last command.
267
309
*
@@ -271,46 +313,4 @@ public function status()
271
313
{
272
314
return $ this ->gateway ->status ();
273
315
}
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
- }
316
316
}
0 commit comments