@@ -44,14 +44,7 @@ public function exec(string $cmd): UnixShell
4444 {
4545 /* @phpstan-ignore-next-line */
4646 logger ()->info (ConsoleColor::yellow ('[EXEC] ' ) . ConsoleColor::green ($ cmd ));
47- logger ()->debug ('Executed at: ' . debug_backtrace ()[0 ]['file ' ] . ': ' . debug_backtrace ()[0 ]['line ' ]);
48- $ env_str = $ this ->getEnvString ();
49- if (!empty ($ env_str )) {
50- $ cmd = "{$ env_str } {$ cmd }" ;
51- }
52- if ($ this ->cd !== null ) {
53- $ cmd = 'cd ' . escapeshellarg ($ this ->cd ) . ' && ' . $ cmd ;
54- }
47+ $ cmd = $ this ->getExecString ($ cmd );
5548 if (!$ this ->debug ) {
5649 $ cmd .= ' 1>/dev/null 2>&1 ' ;
5750 }
@@ -99,10 +92,7 @@ public function execWithResult(string $cmd, bool $with_log = true): array
9992 /* @phpstan-ignore-next-line */
10093 logger ()->debug (ConsoleColor::blue ('[EXEC] ' ) . ConsoleColor::gray ($ cmd ));
10194 }
102- logger ()->debug ('Executed at: ' . debug_backtrace ()[0 ]['file ' ] . ': ' . debug_backtrace ()[0 ]['line ' ]);
103- if ($ this ->cd !== null ) {
104- $ cmd = 'cd ' . escapeshellarg ($ this ->cd ) . ' && ' . $ cmd ;
105- }
95+ $ cmd = $ this ->getExecString ($ cmd );
10696 exec ($ cmd , $ out , $ code );
10797 return [$ code , $ out ];
10898 }
@@ -126,4 +116,21 @@ public function getEnvString(): string
126116 }
127117 return trim ($ str );
128118 }
119+
120+ /**
121+ * @param string $cmd
122+ * @return string
123+ */
124+ private function getExecString (string $ cmd ): string
125+ {
126+ logger ()->debug ('Executed at: ' . debug_backtrace ()[0 ]['file ' ] . ': ' . debug_backtrace ()[0 ]['line ' ]);
127+ $ env_str = $ this ->getEnvString ();
128+ if (!empty ($ env_str )) {
129+ $ cmd = "{$ env_str } {$ cmd }" ;
130+ }
131+ if ($ this ->cd !== null ) {
132+ $ cmd = 'cd ' . escapeshellarg ($ this ->cd ) . ' && ' . $ cmd ;
133+ }
134+ return $ cmd ;
135+ }
129136}
0 commit comments