Skip to content

Commit

Permalink
refactor: Expose ComposerOrchestrator getVendorDir
Browse files Browse the repository at this point in the history
The goal here is to make this piece re-usable. In the end Box only cares
about the autoload but from a user (for debugging purposes) perspective,
the vendor directory is what we want.
  • Loading branch information
theofidry committed Oct 17, 2023
1 parent 1049437 commit 0dc4a97
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/Composer/ComposerOrchestrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function dumpAutoload(
return;
}

$autoloadFile = $this->retrieveAutoloadFile();
$autoloadFile = $this->getVendorDir().'/autoload.php';

$autoloadContents = AutoloadDumper::generateAutoloadStatements(
$symbolsRegistry,
Expand All @@ -129,6 +129,25 @@ public function dumpAutoload(
$this->fileSystem->dumpFile($autoloadFile, $autoloadContents);
}

public function getVendorDir(): string
{
$vendorDirProcess = $this->processFactory->getAutoloadFileProcess();

$this->logger->info($vendorDirProcess->getCommandLine());

$vendorDirProcess->run(env: $this->processFactory->getDefaultEnvVars());

if (false === $vendorDirProcess->isSuccessful()) {
throw new RuntimeException(
'Could not retrieve the vendor dir.',
0,
new ProcessFailedException($vendorDirProcess),
);
}

return trim($vendorDirProcess->getOutput());
}

private function dumpAutoloader(bool $noDev): void
{
$dumpAutoloadProcess = $this->processFactory->getDumpAutoloaderProcess($noDev);
Expand Down Expand Up @@ -162,23 +181,4 @@ private function dumpAutoloader(bool $noDev): void
);
}
}

private function retrieveAutoloadFile(): string
{
$vendorDirProcess = $this->processFactory->getAutoloadFileProcess();

$this->logger->info($vendorDirProcess->getCommandLine());

$vendorDirProcess->run(env: $this->processFactory->getDefaultEnvVars());

if (false === $vendorDirProcess->isSuccessful()) {
throw new RuntimeException(
'Could not retrieve the vendor dir.',
0,
new ProcessFailedException($vendorDirProcess),
);
}

return trim($vendorDirProcess->getOutput()).'/autoload.php';
}
}

0 comments on commit 0dc4a97

Please sign in to comment.