-
Notifications
You must be signed in to change notification settings - Fork 21
/
MultiConnection.php
100 lines (90 loc) · 1.78 KB
/
MultiConnection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php namespace Illuminate\Remote;
use Closure;
class MultiConnection implements ConnectionInterface {
/**
* All of the active server connections.
*
* @var array
*/
protected $connections;
/**
* The array of connections.
*
* @param array $connections
* @return void
*/
public function __construct(array $connections)
{
$this->connections = $connections;
}
/**
* Define a set of commands as a task.
*
* @param string $task
* @param string|array $commands
* @return void
*/
public function define($task, $commands)
{
foreach ($this->connections as $connection)
{
$connection->define($task, $commands);
}
}
/**
* Run a task against the connection.
*
* @param string $task
* @param \Closure $callback
* @return void
*/
public function task($task, Closure $callback = null)
{
foreach ($this->connections as $connection)
{
$connection->task($task, $callback);
}
}
/**
* Run a set of commands against the connection.
*
* @param string|array $commands
* @param \Closure $callback
* @return void
*/
public function run($commands, Closure $callback = null)
{
foreach ($this->connections as $connection)
{
$connection->run($commands, $callback);
}
}
/**
* Upload a local file to the server.
*
* @param string $local
* @param string $remote
* @return void
*/
public function put($local, $remote)
{
foreach ($this->connections as $connection)
{
$connection->put($local, $remote);
}
}
/**
* Upload a string to to the given file on the server.
*
* @param string $remote
* @param string $contents
* @return void
*/
public function putString($remote, $contents)
{
foreach ($this->connections as $connection)
{
$connection->putString($remote, $contents);
}
}
}