@@ -47,19 +47,39 @@ private static function pipe(string ...$commands): string
47
47
return implode (' | ' , $ commands );
48
48
}
49
49
50
+ private static function indirection (string $ command , string $ destination ): string
51
+ {
52
+ return $ command .' > ' .self ::escapeArgument ($ destination );
53
+ }
54
+
55
+ private static function and (string ...$ commands ): string
56
+ {
57
+ return implode (' \\' .\PHP_EOL .' && ' , $ commands );
58
+ }
59
+
50
60
public function __toString (): string
51
61
{
52
62
if (\count ($ this ->autoloads ) <= 0 ) {
53
63
return '' ;
54
64
}
55
65
56
- $ commands = implode (' \\' .\PHP_EOL .' && ' , array_map (fn ($ type , $ autoload ) => match ($ type ) {
57
- 'psr4 ' => self ::pipe (
58
- self ::command ('cat ' , 'composer.json ' ),
59
- self ::command ('jq ' , '--indent ' , '4 ' , sprintf ('.autoload."psr-4" |= . + %s ' , json_encode ($ autoload , \JSON_THROW_ON_ERROR ))),
60
- self ::command ('tee ' , 'composer.json ' )
66
+ $ commands = self ::and (
67
+ ...array_map (
68
+ fn ($ type , $ autoload ) => match ($ type ) {
69
+ 'psr4 ' => self ::and (
70
+ self ::pipe (
71
+ self ::command ('cat ' , 'composer.json ' ),
72
+ self ::command ('jq ' , '--indent ' , '4 ' , sprintf ('.autoload."psr-4" |= . + %s ' , json_encode ($ autoload , \JSON_THROW_ON_ERROR ))),
73
+ self ::command ('tee ' , 'composer.temp ' )
74
+ ),
75
+ self ::indirection (self ::command ('cat ' , 'composer.temp ' ), 'composer.json ' ),
76
+ self ::command ('rm ' , 'composer.temp ' ),
77
+ )
78
+ },
79
+ array_keys ($ this ->autoloads ),
80
+ array_values ($ this ->autoloads )
61
81
)
62
- }, array_keys ( $ this -> autoloads ), array_values ( $ this -> autoloads )) );
82
+ );
63
83
64
84
return (string ) new Dockerfile \Run (
65
85
<<<RUN
0 commit comments