mirror of
https://github.com/composer/composer
synced 2025-05-09 16:42:57 +00:00
Allow the authentications to be loaded in the IO independently
This commit is contained in:
parent
472037fb90
commit
14fcff8aa8
5 changed files with 87 additions and 80 deletions
75
src/Composer/IO/BaseIO.php
Normal file
75
src/Composer/IO/BaseIO.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\IO;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Composer\Config;
|
||||
|
||||
class BaseIO implements IOInterface
|
||||
{
|
||||
protected $authentications = array();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAuthentications()
|
||||
{
|
||||
return $this->authentications;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hasAuthentication($repositoryName)
|
||||
{
|
||||
return isset($this->authentications[$repositoryName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAuthentication($repositoryName)
|
||||
{
|
||||
if (isset($this->authentications[$repositoryName])) {
|
||||
return $this->authentications[$repositoryName];
|
||||
}
|
||||
|
||||
return array('username' => null, 'password' => null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setAuthentication($repositoryName, $username, $password = null)
|
||||
{
|
||||
$this->authentications[$repositoryName] = array('username' => $username, 'password' => $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function loadConfiguration(Config $config)
|
||||
{
|
||||
// reload oauth token from config if available
|
||||
if ($tokens = $config->get('github-oauth')) {
|
||||
foreach ($tokens as $domain => $token) {
|
||||
if (!preg_match('{^[a-z0-9]+$}', $token)) {
|
||||
throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
|
||||
}
|
||||
$io->setAuthentication($domain, $token, 'x-oauth-basic');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue