Skip to content

Commit

Permalink
Feature: Allow local directory paths in repository of type composer
Browse files Browse the repository at this point in the history
Fixes: #11519
  • Loading branch information
helhum committed Jun 26, 2023
1 parent 2b18799 commit 69953c3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Composer/Repository/ComposerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,19 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
public function __construct(array $repoConfig, IOInterface $io, Config $config, HttpDownloader $httpDownloader, ?EventDispatcher $eventDispatcher = null)
{
parent::__construct();
if (!Preg::isMatch('{^[\w.]+\??://}', $repoConfig['url'])) {
// assume http as the default protocol
$repoConfig['url'] = 'http://'.$repoConfig['url'];
}
$repoConfig['url'] = rtrim($repoConfig['url'], '/');
if ($repoConfig['url'] === '') {
throw new \InvalidArgumentException('The repository url must not be an empty string');
}
if (!Preg::isMatch('{^[\w.]+\??://}', $repoConfig['url'])) {
if (($localFilePath = realpath($repoConfig['url'])) !== false) {
// it is a local path, add file scheme
$repoConfig['url'] = 'file://'.$localFilePath;
} else {
// otherwise, assume http as the default protocol
$repoConfig['url'] = 'http://'.$repoConfig['url'];
}
}
$repoConfig['url'] = rtrim($repoConfig['url'], '/');

if (str_starts_with($repoConfig['url'], 'https?')) {
$repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);
Expand Down

0 comments on commit 69953c3

Please sign in to comment.