Browse Source

Enable https for packagist when possible

Jordi Boggiano 12 years ago
parent
commit
fb296972ef
2 changed files with 7 additions and 2 deletions
  1. 1 1
      src/Composer/Config.php
  2. 6 1
      src/Composer/Repository/ComposerRepository.php

+ 1 - 1
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',
         )
     );
 

+ 6 - 1
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']);
         }