浏览代码

InstallationManager: notifyInstalls: append authorization header for repository

Boris Momčilović 9 年之前
父节点
当前提交
b05b52ff7e

+ 1 - 1
src/Composer/Command/CreateProjectCommand.php

@@ -318,7 +318,7 @@ EOT
         $im = $this->createInstallationManager();
         $im->addInstaller($projectInstaller);
         $im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package));
-        $im->notifyInstalls();
+        $im->notifyInstalls($io);
 
         $installedFromVcs = 'source' === $package->getInstallationSource();
 

+ 2 - 2
src/Composer/Installer.php

@@ -234,11 +234,11 @@ class Installer
                 return $res;
             }
         } catch (\Exception $e) {
-            $this->installationManager->notifyInstalls();
+            $this->installationManager->notifyInstalls($this->io);
 
             throw $e;
         }
-        $this->installationManager->notifyInstalls();
+        $this->installationManager->notifyInstalls($this->io);
 
         // output suggestions if we're in dev mode
         if ($this->devMode) {

+ 16 - 1
src/Composer/Installer/InstallationManager.php

@@ -12,6 +12,7 @@
 
 namespace Composer\Installer;
 
+use Composer\IO\IOInterface;
 use Composer\Package\PackageInterface;
 use Composer\Package\AliasPackage;
 use Composer\Repository\RepositoryInterface;
@@ -230,9 +231,17 @@ class InstallationManager
         return $installer->getInstallPath($package);
     }
 
-    public function notifyInstalls()
+    public function notifyInstalls(IOInterface $io)
     {
         foreach ($this->notifiablePackages as $repoUrl => $packages) {
+            $repositoryName = parse_url ($repoUrl, PHP_URL_HOST);
+            if ($io->hasAuthentication ($repositoryName))
+            {
+                $auth = $io->getAuthentication ($repositoryName);
+                $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
+                $authHeader = 'Authorization: Basic '.$authStr;
+            }
+
             // non-batch API, deprecated
             if (strpos($repoUrl, '%package%')) {
                 foreach ($packages as $package) {
@@ -250,6 +259,9 @@ class InstallationManager
                             'timeout' => 3,
                         ),
                     );
+                    if (isset($authHeader)) {
+                        $opts['http']['header'][] = $authHeader;
+                    }
 
                     $context = StreamContextFactory::getContext($url, $opts);
                     @file_get_contents($url, false, $context);
@@ -274,6 +286,9 @@ class InstallationManager
                     'timeout' => 6,
                 ),
             );
+            if (isset($authHeader)) {
+                $opts['http']['header'][] = $authHeader;
+            }
 
             $context = StreamContextFactory::getContext($repoUrl, $opts);
             @file_get_contents($repoUrl, false, $context);