@@ -46,22 +46,18 @@ public function __construct(Filesystem $files, $workingPath = null)
46
46
* @param \Closure|\Symfony\Component\Console\Output\OutputInterface|null $output
47
47
* @return bool
48
48
*/
49
- protected function requirePackages (array $ packages , bool $ dev = false , Closure |OutputInterface $ output = null )
49
+ public function requirePackages (array $ packages , bool $ dev = false , Closure |OutputInterface $ output = null )
50
50
{
51
- $ composer = $ this ->findComposer ();
52
-
53
- $ command = explode (' ' , $ composer );
54
-
55
- array_push ($ command , 'require ' );
56
-
57
- $ command = array_merge (
58
- $ command ,
59
- $ packages ,
60
- $ dev ? ['--dev ' ] : [],
61
- );
62
-
63
- return 0 === (new Process ($ command , cwd: $ this ->workingPath , env: ['COMPOSER_MEMORY_LIMIT ' => '-1 ' ]))
64
- ->setTimeout (null )
51
+ $ command = collect ([
52
+ ...$ this ->findComposer (),
53
+ 'require ' ,
54
+ ...$ packages ,
55
+ ])
56
+ ->when ($ dev , function ($ command ) {
57
+ $ command ->push ('--dev ' );
58
+ })->all ();
59
+
60
+ return 0 === $ this ->getProcess ($ command , ['COMPOSER_MEMORY_LIMIT ' => '-1 ' ])
65
61
->run (
66
62
$ output instanceof OutputInterface
67
63
? function ($ type , $ line ) use ($ output ) {
@@ -78,22 +74,18 @@ protected function requirePackages(array $packages, bool $dev = false, Closure|O
78
74
* @param \Closure|\Symfony\Component\Console\Output\OutputInterface|null $output
79
75
* @return bool
80
76
*/
81
- protected function removePackages (array $ packages , bool $ dev = false , Closure |OutputInterface $ output = null )
77
+ public function removePackages (array $ packages , bool $ dev = false , Closure |OutputInterface $ output = null )
82
78
{
83
- $ composer = $ this ->findComposer ();
84
-
85
- $ command = explode (' ' , $ composer );
86
-
87
- array_push ($ command , 'remove ' );
88
-
89
- $ command = array_merge (
90
- $ command ,
91
- $ packages ,
92
- $ dev ? ['--dev ' ] : [],
93
- );
94
-
95
- return 0 === (new Process ($ command , cwd: $ this ->workingPath , env: ['COMPOSER_MEMORY_LIMIT ' => '-1 ' ]))
96
- ->setTimeout (null )
79
+ $ command = collect ([
80
+ ...$ this ->findComposer (),
81
+ 'remove ' ,
82
+ ...$ packages ,
83
+ ])
84
+ ->when ($ dev , function ($ command ) {
85
+ $ command ->push ('--dev ' );
86
+ })->all ();
87
+
88
+ return 0 === $ this ->getProcess ($ command , ['COMPOSER_MEMORY_LIMIT ' => '-1 ' ])
97
89
->run (
98
90
$ output instanceof OutputInterface
99
91
? function ($ type , $ line ) use ($ output ) {
@@ -182,11 +174,12 @@ protected function phpBinary()
182
174
* Get a new Symfony process instance.
183
175
*
184
176
* @param array $command
177
+ * @param array $env
185
178
* @return \Symfony\Component\Process\Process
186
179
*/
187
- protected function getProcess (array $ command )
180
+ protected function getProcess (array $ command, array $ env = [] )
188
181
{
189
- return (new Process ($ command , $ this ->workingPath ))->setTimeout (null );
182
+ return (new Process ($ command , $ this ->workingPath , $ env ))->setTimeout (null );
190
183
}
191
184
192
185
/**
0 commit comments