Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Composer helper improvements #48448

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/Illuminate/Support/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ protected function hasPackage($package)
* @param array<int, string> $packages
* @param bool $dev
* @param \Closure|\Symfony\Component\Console\Output\OutputInterface|null $output
* @param string|null $composerBinary
* @return bool
*/
public function requirePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null)
public function requirePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null, $composerBinary = null)
{
$command = collect([
...$this->findComposer(),
...$this->findComposer($composerBinary),
'require',
...$packages,
])
Expand All @@ -88,12 +89,13 @@ public function requirePackages(array $packages, bool $dev = false, Closure|Outp
* @param array<int, string> $packages
* @param bool $dev
* @param \Closure|\Symfony\Component\Console\Output\OutputInterface|null $output
* @param string|null $composerBinary
* @return bool
*/
public function removePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null)
public function removePackages(array $packages, bool $dev = false, Closure|OutputInterface $output = null, $composerBinary = null)
{
$command = collect([
...$this->findComposer(),
...$this->findComposer($composerBinary),
'remove',
...$packages,
])
Expand Down Expand Up @@ -137,35 +139,40 @@ public function modify(callable $callback)
* Regenerate the Composer autoloader files.
*
* @param string|array $extra
* @param string|null $composerBinary
* @return int
*/
public function dumpAutoloads($extra = '')
public function dumpAutoloads($extra = '', $composerBinary = null)
{
$extra = $extra ? (array) $extra : [];

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

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

/**
* Regenerate the optimized Composer autoloader files.
*
* @param string|null $composerBinary
* @return int
*/
public function dumpOptimized()
public function dumpOptimized($composerBinary = null)
{
return $this->dumpAutoloads('--optimize');
return $this->dumpAutoloads('--optimize', $composerBinary);
}

/**
* Get the Composer binary / command for the environment.
*
* @param string|null $composerBinary
* @return array
*/
public function findComposer()
public function findComposer($composerBinary = null)
{
if ($this->files->exists($this->workingPath.'/composer.phar')) {
if (! is_null($composerBinary) && $this->files->exists($composerBinary)) {
return [$this->phpBinary(), $composerBinary];
} elseif ($this->files->exists($this->workingPath.'/composer.phar')) {
return [$this->phpBinary(), 'composer.phar'];
}

Expand Down