7
7
8
8
class RemoteProcessRunner
9
9
{
10
+ /**
11
+ * @var callable|null
12
+ */
13
+ private $ onOutput = null ;
14
+
10
15
public function __construct (
11
16
private Connection $ connection ,
12
17
private ProcessRunner $ processRunner
13
18
) {
14
19
}
15
20
21
+ /**
22
+ * A PHP callback to run whenever there is some output available on STDOUT or STDERR.
23
+ */
24
+ public function onOutput (callable $ callback ): self
25
+ {
26
+ $ this ->onOutput = $ callback ;
27
+
28
+ return $ this ;
29
+ }
30
+
16
31
/**
17
32
* Runs the full path of given script on the remote server.
18
33
*/
@@ -61,8 +76,6 @@ private function sshOptions(): array
61
76
62
77
/**
63
78
* Formats the script and output paths, and runs the script.
64
- *
65
- * @return \ProtoneMedia\LaravelTaskRunner\ProcessOutput
66
79
*/
67
80
public function runUploadedScript (string $ script , string $ output , int $ timeout = 0 ): ProcessOutput
68
81
{
@@ -74,8 +87,6 @@ public function runUploadedScript(string $script, string $output, int $timeout =
74
87
75
88
/**
76
89
* Formats the script and output paths, and runs the script in the background.
77
- *
78
- * @return \ProtoneMedia\LaravelTaskRunner\ProcessOutput
79
90
*/
80
91
public function runUploadedScriptInBackground (string $ script , string $ output , int $ timeout = 0 ): ProcessOutput
81
92
{
@@ -90,8 +101,6 @@ public function runUploadedScriptInBackground(string $script, string $output, in
90
101
91
102
/**
92
103
* Wraps the script in a bash subshell command, and runs it over SSH.
93
- *
94
- * @return \ProtoneMedia\LaravelTaskRunner\ProcessOutput
95
104
*/
96
105
private function run (string $ script , int $ timeout = 0 ): ProcessOutput
97
106
{
@@ -104,17 +113,15 @@ private function run(string $script, int $timeout = 0): ProcessOutput
104
113
]);
105
114
106
115
$ output = $ this ->processRunner ->run (
107
- FacadesProcess::command ($ command )->timeout ($ timeout > 0 ? $ timeout : null )
116
+ FacadesProcess::command ($ command )->timeout ($ timeout > 0 ? $ timeout : null ),
117
+ $ this ->onOutput
108
118
);
109
119
110
120
return $ this ->cleanupOutput ($ output );
111
121
}
112
122
113
123
/**
114
124
* Removes the known hosts warning from the output.
115
- *
116
- * @param \ProtoneMedia\LaravelTaskRunner\ProcessOutput $processOutput
117
- * @return \ProtoneMedia\LaravelTaskRunner\ProcessOutput
118
125
*/
119
126
private function cleanupOutput (ProcessOutput $ processOutput ): ProcessOutput
120
127
{
0 commit comments