diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 39e95fd03..ced0007c6 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -28,7 +28,7 @@ class Config public static $defaultRepositories = array( 'packagist' => array( 'type' => 'composer', - 'url' => 'http://packagist.org', + 'url' => 'https?://packagist.org', ) ); diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 5904e6a94..0c53643a6 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -38,11 +38,16 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository public function __construct(array $repoConfig, IOInterface $io, Config $config) { - if (!preg_match('{^[\w.]+://}', $repoConfig['url'])) { + if (!preg_match('{^[\w.]+\??://}', $repoConfig['url'])) { // assume http as the default protocol $repoConfig['url'] = 'http://'.$repoConfig['url']; } $repoConfig['url'] = rtrim($repoConfig['url'], '/'); + + if ('https?' === substr($repoConfig['url'], 0, 6)) { + $repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6); + } + if (function_exists('filter_var') && version_compare(PHP_VERSION, '5.3.3', '>=') && !filter_var($repoConfig['url'], FILTER_VALIDATE_URL)) { throw new \UnexpectedValueException('Invalid url given for Composer repository: '.$repoConfig['url']); }