1
0
Fork 0

InstallationManager: notifyInstalls: append authorization header for repository

pull/4530/head
Boris Momčilović 2015-10-24 00:58:34 +02:00
parent f85d965732
commit b05b52ff7e
3 changed files with 19 additions and 4 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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);