1
0
Fork 0

Fix some improvements

pull/198/head
François Pluchino 2012-01-17 14:53:50 +01:00
parent 9963bde367
commit 03f5eee3fa
4 changed files with 34 additions and 40 deletions

View File

@ -94,8 +94,8 @@ abstract class FileDownloader implements DownloaderInterface
); );
} }
if ($this->io->hasAuthentification($package->getSourceUrl())) { if ($this->io->hasAuthorization($package->getSourceUrl())) {
$auth = $this->io->getAuthentification($package->getSourceUrl()); $auth = $this->io->getAuthorization($package->getSourceUrl());
$authStr = base64_encode($auth['username'] . ':' . $auth['password']); $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
$params['http'] = array_merge($params['http'], array('header' => "Authorization: Basic $authStr\r\n")); $params['http'] = array_merge($params['http'], array('header' => "Authorization: Basic $authStr\r\n"));
} }
@ -171,7 +171,7 @@ abstract class FileDownloader implements DownloaderInterface
{ {
switch ($notificationCode) { switch ($notificationCode) {
case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_AUTH_REQUIRED:
throw new \LogicException("Authentification is required"); throw new \LogicException("Authorization is required");
break; break;
case STREAM_NOTIFY_FAILURE: case STREAM_NOTIFY_FAILURE:

View File

@ -28,7 +28,7 @@ class ConsoleIO implements IOInterface
protected $input; protected $input;
protected $output; protected $output;
protected $helperSet; protected $helperSet;
protected $authentifications; protected $authorizations = array();
protected $lastUsername; protected $lastUsername;
protected $lastPassword; protected $lastPassword;
@ -242,42 +242,38 @@ class ConsoleIO implements IOInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getAuthentifications() public function getAuthorizations()
{ {
if (null === $this->authentifications) { return $this->authorizations;
$this->authentifications = array();
}
return $this->authentifications;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function hasAuthentification($repositoryName) public function hasAuthorization($repositoryName)
{ {
$auths = $this->getAuthentifications(); $auths = $this->getAuthorizations();
return isset($auths[$repositoryName]) ? true : false; return isset($auths[$repositoryName]);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getAuthentification($repositoryName) public function getAuthorization($repositoryName)
{ {
$auths = $this->getAuthentifications(); $auths = $this->getAuthorizations();
return isset($auths[$repositoryName]) ? $auths[$repositoryName] : array('username' => null, 'password' => null); return isset($auths[$repositoryName]) ? $auths[$repositoryName] : array('username' => null, 'password' => null);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function setAuthentification($repositoryName, $username, $password = null) public function setAuthorization($repositoryName, $username, $password = null)
{ {
$auths = $this->getAuthentifications(); $auths = $this->getAuthorizations();
$auths[$repositoryName] = array('username' => $username, 'password' => $password); $auths[$repositoryName] = array('username' => $username, 'password' => $password);
$this->authentifications = $auths; $this->authorizations = $auths;
$this->lastUsername = $username; $this->lastUsername = $username;
$this->lastPassword = $password; $this->lastPassword = $password;
} }

View File

@ -22,8 +22,6 @@ use Symfony\Component\Console\Helper\HelperSet;
*/ */
interface IOInterface extends OutputInterface interface IOInterface extends OutputInterface
{ {
/** /**
* Is this input means interactive? * Is this input means interactive?
* *
@ -116,20 +114,20 @@ interface IOInterface extends OutputInterface
function getLastPassword(); function getLastPassword();
/** /**
* Get all authentification informations entered. * Get all authorization informations entered.
* *
* @return array The map of authentification * @return array The map of authorization
*/ */
function getAuthentifications(); function getAuthorizations();
/** /**
* Verify if the repository has a authentification informations. * Verify if the repository has a authorization informations.
* *
* @param string $repositoryName The unique name of repository * @param string $repositoryName The unique name of repository
* *
* @return boolean * @return boolean
*/ */
function hasAuthentification($repositoryName); function hasAuthorization($repositoryName);
/** /**
* Get the username and password of repository. * Get the username and password of repository.
@ -138,14 +136,14 @@ interface IOInterface extends OutputInterface
* *
* @return array The 'username' and 'password' * @return array The 'username' and 'password'
*/ */
function getAuthentification($repositoryName); function getAuthorization($repositoryName);
/** /**
* Set the authentification informations for the repository. * Set the authorization informations for the repository.
* *
* @param string $repositoryName The unique name of repository * @param string $repositoryName The unique name of repository
* @param string $username The username * @param string $username The username
* @param string $password The password * @param string $password The password
*/ */
function setAuthentification($repositoryName, $username, $password = null); function setAuthorization($repositoryName, $username, $password = null);
} }

View File

@ -15,7 +15,7 @@ namespace Composer\Repository\Vcs;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
/** /**
* A driver implementation for driver with authentification interaction. * A driver implementation for driver with authorization interaction.
* *
* @author François Pluchino <francois.pluchino@opendisplay.com> * @author François Pluchino <francois.pluchino@opendisplay.com>
*/ */
@ -63,11 +63,11 @@ abstract class VcsDriver
protected function getContents($url) protected function getContents($url)
{ {
$this->contentUrl = $url; $this->contentUrl = $url;
$auth = $this->io->getAuthentification($this->url); $auth = $this->io->getAuthorization($this->url);
$params = array(); $params = array();
// add authorization to curl options // add authorization to curl options
if ($this->io->hasAuthentification($this->url)) { if ($this->io->hasAuthorization($this->url)) {
$authStr = base64_encode($auth['username'] . ':' . $auth['password']); $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
$params['http'] = array('header' => "Authorization: Basic $authStr\r\n"); $params['http'] = array('header' => "Authorization: Basic $authStr\r\n");
@ -81,7 +81,7 @@ abstract class VcsDriver
$content = @file_get_contents($url, false, $ctx); $content = @file_get_contents($url, false, $ctx);
// content get after authentification // content get after authorization
if (false === $content) { if (false === $content) {
$content = $this->content; $content = $this->content;
$this->content = null; $this->content = null;
@ -106,36 +106,36 @@ abstract class VcsDriver
switch ($notificationCode) { switch ($notificationCode) {
case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_AUTH_REQUIRED:
case STREAM_NOTIFY_FAILURE: case STREAM_NOTIFY_FAILURE:
// for private repository returning 404 error when the authentification is incorrect // for private repository returning 404 error when the authorization is incorrect
$auth = $this->io->getAuthentification($this->url); $auth = $this->io->getAuthorization($this->url);
$ps = $this->firstCall && 404 === $messageCode $ps = $this->firstCall && 404 === $messageCode
&& null === $this->io->getLastUsername() && null === $this->io->getLastUsername()
&& null === $auth['username']; && null === $auth['username'];
if (404 === $messageCode && !$this->firstCall) { if (404 === $messageCode && !$this->firstCall) {
throw new \LogicException("The '" . $this->contentUrl . "' URL not found"); throw new \RuntimeException("The '" . $this->contentUrl . "' URL not found");
} }
if ($this->firstCall) { if ($this->firstCall) {
$this->firstCall = false; $this->firstCall = false;
} }
// get authentification informations // get authorization informations
if (401 === $messageCode || $ps) { if (401 === $messageCode || $ps) {
if (!$this->io->isInteractive()) { if (!$this->io->isInteractive()) {
$mess = "The '" . $this->contentUrl . "' URL not found"; $mess = "The '" . $this->contentUrl . "' URL not found";
if (401 === $code || $ps) { if (401 === $code || $ps) {
$mess = "The '" . $this->contentUrl . "' URL required the authentification.\nYou must be used the interactive console"; $mess = "The '" . $this->contentUrl . "' URL required the authorization.\nYou must be used the interactive console";
} }
throw new \LogicException($mess); throw new \RuntimeException($mess);
} }
$this->io->writeln("Authorization for <info>" . $this->contentUrl . "</info>:"); $this->io->writeln("Authorization for <info>" . $this->contentUrl . "</info>:");
$username = $this->io->ask(' Username: '); $username = $this->io->ask(' Username: ');
$password = $this->io->askAndHideAnswer(' Password: '); $password = $this->io->askAndHideAnswer(' Password: ');
$this->io->setAuthentification($this->url, $username, $password); $this->io->setAuthorization($this->url, $username, $password);
$this->content = $this->getContents($this->contentUrl); $this->content = $this->getContents($this->contentUrl);
} }