22
33namespace Sal \Seven \Adapter \Ssh ;
44
5+ use Psr \Log \LoggerInterface ;
6+ use Psr \Log \NullLogger ;
57use Sal \Seven \Model \CommandResult ;
68use Sal \Seven \Model \File ;
79use Symfony \Component \Process \Exception \ProcessTimedOutException ;
@@ -20,8 +22,12 @@ class SshAdapter implements SshAdapterInterface
2022 private string $ user = 'root ' ;
2123 private ?int $ timeout = 60 ;
2224
25+ private LoggerInterface $ logger ;
26+
2327 public function __construct ()
2428 {
29+ $ this ->logger = new NullLogger ();
30+
2531 $ this ->options = [
2632 '-o ' , 'ControlMaster=auto ' ,
2733 '-o ' , 'ControlPath=/tmp/php-seven-ssh-%C ' ,
@@ -32,6 +38,11 @@ public function __construct()
3238 ];
3339 }
3440
41+ public function setLogger (LoggerInterface $ logger ): void
42+ {
43+ $ this ->logger = $ logger ;
44+ }
45+
3546 public function setHost (string $ host ): void
3647 {
3748 $ this ->host = $ host ;
@@ -84,6 +95,8 @@ public function secureCopyFileDownload(
8495 ["{$ this ->user }@ {$ this ->host }: $ sourceFilePath " , $ destinationFolder ]
8596 );
8697
98+ $ this ->logger ->debug (implode (' ' , $ commandLine ));
99+
87100 $ proc = new Process ($ commandLine );
88101 $ proc ->setTimeout ($ timeout );
89102 $ proc ->run ();
@@ -120,6 +133,8 @@ public function secureCopyFileUpload(
120133 [$ sourceFilePath , "{$ this ->user }@ {$ this ->host }: $ destinationFolder/ " ]
121134 );
122135
136+ $ this ->logger ->debug (implode (' ' , $ commandLine ));
137+
123138 $ proc = new Process ($ commandLine );
124139 $ proc ->setTimeout ($ timeout );
125140 $ proc ->run ();
@@ -170,6 +185,8 @@ public function runCommand(
170185 [(new Process ($ command ))->getCommandLine ()]
171186 );
172187
188+ $ this ->logger ->debug (implode (' ' , $ commandLine ));
189+
173190 $ proc = new Process ($ commandLine );
174191
175192 if (null !== $ pipedInput ) {
@@ -201,6 +218,8 @@ public function waitForSshLogin(): void
201218 ["{$ this ->user }@ $ this ->host " ]
202219 );
203220
221+ $ this ->logger ->debug (implode (' ' , $ commandLine ));
222+
204223 $ process = new Process ($ commandLine );
205224 $ process ->setTimeout (null );
206225 do {
0 commit comments