@@ -163,7 +163,11 @@ func (e *Executor) DetectScriptDir() (string, error) {
163
163
return e .scriptDir , nil
164
164
}
165
165
166
- // Config determines the right version of PHP depending on the configuration (+ its configuration)
166
+ // Config determines the right version of PHP depending on the configuration
167
+ // (+ its configuration). It also creates some symlinks to ease the integration
168
+ // with underlying tools that could try to run PHP. This is the responsability
169
+ // of the caller to clean those temporary files. One can call
170
+ // CleanupTemporaryDirectories to do so.
167
171
func (e * Executor ) Config (loadDotEnv bool ) error {
168
172
// reset environment
169
173
e .environ = make ([]string , 0 )
@@ -220,8 +224,10 @@ func (e *Executor) Config(loadDotEnv bool) error {
220
224
// prepending the PHP directory in the PATH does not work well if the PHP binary is not named "php" (like php7.3 for instance)
221
225
// in that case, we create a temp directory with a symlink
222
226
// we also link php-config for pecl to pick up the right one (it is always looks for something called php-config)
223
- phpDir := filepath .Join (cliDir , "tmp" , xid .New ().String (), "bin" )
224
- e .tempDir = phpDir
227
+ if e .tempDir == "" {
228
+ e .tempDir = filepath .Join (cliDir , "tmp" , xid .New ().String ())
229
+ }
230
+ phpDir := filepath .Join (e .tempDir , "bin" )
225
231
if err := os .MkdirAll (phpDir , 0755 ); err != nil {
226
232
return err
227
233
}
@@ -284,6 +290,15 @@ func (e *Executor) Config(loadDotEnv bool) error {
284
290
return err
285
291
}
286
292
293
+ func (e * Executor ) CleanupTemporaryDirectories () {
294
+ if e .iniDir != "" {
295
+ os .RemoveAll (e .iniDir )
296
+ }
297
+ if e .tempDir != "" {
298
+ os .RemoveAll (e .tempDir )
299
+ }
300
+ }
301
+
287
302
// Find composer depending on the configuration
288
303
func (e * Executor ) findComposer (extraBin string ) (string , error ) {
289
304
if scriptDir , err := e .DetectScriptDir (); err == nil {
@@ -312,14 +327,7 @@ func (e *Executor) Execute(loadDotEnv bool) int {
312
327
fmt .Fprintln (os .Stderr , err )
313
328
return 1
314
329
}
315
- defer func () {
316
- if e .iniDir != "" {
317
- os .RemoveAll (e .iniDir )
318
- }
319
- if e .tempDir != "" {
320
- os .RemoveAll (e .tempDir )
321
- }
322
- }()
330
+ defer e .CleanupTemporaryDirectories ()
323
331
cmd := execCommand (e .Args [0 ], e .Args [1 :]... )
324
332
environ := append (os .Environ (), e .environ ... )
325
333
gpathname := "PATH"
0 commit comments