Skip to content

Commit 89171a2

Browse files
[10.x] Composer helper improvements (#48448)
* [10.x] Composer helper improvements Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * Apply fixes from StyleCI --------- Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent c01443d commit 89171a2

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/Illuminate/Support/Composer.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ protected function hasPackage($package)
6060
* @param array<int, string> $packages
6161
* @param bool $dev
6262
* @param \Closure|\Symfony\Component\Console\Output\OutputInterface|null $output
63+
* @param string|null $composerBinary
6364
* @return bool
6465
*/
65-
public function requirePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null)
66+
public function requirePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null, $composerBinary = null)
6667
{
6768
$command = collect([
68-
...$this->findComposer(),
69+
...$this->findComposer($composerBinary),
6970
'require',
7071
...$packages,
7172
])
@@ -88,12 +89,13 @@ public function requirePackages(array $packages, bool $dev = false, Closure|Outp
8889
* @param array<int, string> $packages
8990
* @param bool $dev
9091
* @param \Closure|\Symfony\Component\Console\Output\OutputInterface|null $output
92+
* @param string|null $composerBinary
9193
* @return bool
9294
*/
93-
public function removePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null)
95+
public function removePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null, $composerBinary = null)
9496
{
9597
$command = collect([
96-
...$this->findComposer(),
98+
...$this->findComposer($composerBinary),
9799
'remove',
98100
...$packages,
99101
])
@@ -137,35 +139,40 @@ public function modify(callable $callback)
137139
* Regenerate the Composer autoloader files.
138140
*
139141
* @param string|array $extra
142+
* @param string|null $composerBinary
140143
* @return int
141144
*/
142-
public function dumpAutoloads($extra = '')
145+
public function dumpAutoloads($extra = '', $composerBinary = null)
143146
{
144147
$extra = $extra ? (array) $extra : [];
145148

146-
$command = array_merge($this->findComposer(), ['dump-autoload'], $extra);
149+
$command = array_merge($this->findComposer($composerBinary), ['dump-autoload'], $extra);
147150

148151
return $this->getProcess($command)->run();
149152
}
150153

151154
/**
152155
* Regenerate the optimized Composer autoloader files.
153156
*
157+
* @param string|null $composerBinary
154158
* @return int
155159
*/
156-
public function dumpOptimized()
160+
public function dumpOptimized($composerBinary = null)
157161
{
158-
return $this->dumpAutoloads('--optimize');
162+
return $this->dumpAutoloads('--optimize', $composerBinary);
159163
}
160164

161165
/**
162166
* Get the Composer binary / command for the environment.
163167
*
168+
* @param string|null $composerBinary
164169
* @return array
165170
*/
166-
public function findComposer()
171+
public function findComposer($composerBinary = null)
167172
{
168-
if ($this->files->exists($this->workingPath.'/composer.phar')) {
173+
if (! is_null($composerBinary) && $this->files->exists($composerBinary)) {
174+
return [$this->phpBinary(), $composerBinary];
175+
} elseif ($this->files->exists($this->workingPath.'/composer.phar')) {
169176
return [$this->phpBinary(), 'composer.phar'];
170177
}
171178

0 commit comments

Comments
 (0)