From 03f5eee3fa2d3d87ca7372d871eb032d4db1a68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pluchino?= Date: Tue, 17 Jan 2012 14:53:50 +0100 Subject: [PATCH] Fix some improvements --- src/Composer/Downloader/FileDownloader.php | 6 ++--- src/Composer/IO/ConsoleIO.php | 26 +++++++++------------- src/Composer/IO/IOInterface.php | 20 ++++++++--------- src/Composer/Repository/Vcs/VcsDriver.php | 22 +++++++++--------- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 3f19020c4..0a25fddb8 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -94,8 +94,8 @@ abstract class FileDownloader implements DownloaderInterface ); } - if ($this->io->hasAuthentification($package->getSourceUrl())) { - $auth = $this->io->getAuthentification($package->getSourceUrl()); + if ($this->io->hasAuthorization($package->getSourceUrl())) { + $auth = $this->io->getAuthorization($package->getSourceUrl()); $authStr = base64_encode($auth['username'] . ':' . $auth['password']); $params['http'] = array_merge($params['http'], array('header' => "Authorization: Basic $authStr\r\n")); } @@ -171,7 +171,7 @@ abstract class FileDownloader implements DownloaderInterface { switch ($notificationCode) { case STREAM_NOTIFY_AUTH_REQUIRED: - throw new \LogicException("Authentification is required"); + throw new \LogicException("Authorization is required"); break; case STREAM_NOTIFY_FAILURE: diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index edc970fe8..cf11f6a57 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -28,7 +28,7 @@ class ConsoleIO implements IOInterface protected $input; protected $output; protected $helperSet; - protected $authentifications; + protected $authorizations = array(); protected $lastUsername; protected $lastPassword; @@ -242,42 +242,38 @@ class ConsoleIO implements IOInterface /** * {@inheritDoc} */ - public function getAuthentifications() + public function getAuthorizations() { - if (null === $this->authentifications) { - $this->authentifications = array(); - } - - return $this->authentifications; + return $this->authorizations; } /** * {@inheritDoc} */ - public function hasAuthentification($repositoryName) + public function hasAuthorization($repositoryName) { - $auths = $this->getAuthentifications(); - return isset($auths[$repositoryName]) ? true : false; + $auths = $this->getAuthorizations(); + return isset($auths[$repositoryName]); } /** * {@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); } /** * {@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); - $this->authentifications = $auths; + $this->authorizations = $auths; $this->lastUsername = $username; $this->lastPassword = $password; } diff --git a/src/Composer/IO/IOInterface.php b/src/Composer/IO/IOInterface.php index 8a3b77f43..e5f81facf 100644 --- a/src/Composer/IO/IOInterface.php +++ b/src/Composer/IO/IOInterface.php @@ -21,9 +21,7 @@ use Symfony\Component\Console\Helper\HelperSet; * @author François Pluchino */ interface IOInterface extends OutputInterface -{ - - +{ /** * Is this input means interactive? * @@ -116,20 +114,20 @@ interface IOInterface extends OutputInterface 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 * * @return boolean */ - function hasAuthentification($repositoryName); + function hasAuthorization($repositoryName); /** * Get the username and password of repository. @@ -138,14 +136,14 @@ interface IOInterface extends OutputInterface * * @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 $username The username * @param string $password The password */ - function setAuthentification($repositoryName, $username, $password = null); + function setAuthorization($repositoryName, $username, $password = null); } diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index 857899cd5..bd7565603 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -15,7 +15,7 @@ namespace Composer\Repository\Vcs; use Composer\IO\IOInterface; /** - * A driver implementation for driver with authentification interaction. + * A driver implementation for driver with authorization interaction. * * @author François Pluchino */ @@ -63,11 +63,11 @@ abstract class VcsDriver protected function getContents($url) { $this->contentUrl = $url; - $auth = $this->io->getAuthentification($this->url); + $auth = $this->io->getAuthorization($this->url); $params = array(); // add authorization to curl options - if ($this->io->hasAuthentification($this->url)) { + if ($this->io->hasAuthorization($this->url)) { $authStr = base64_encode($auth['username'] . ':' . $auth['password']); $params['http'] = array('header' => "Authorization: Basic $authStr\r\n"); @@ -81,7 +81,7 @@ abstract class VcsDriver $content = @file_get_contents($url, false, $ctx); - // content get after authentification + // content get after authorization if (false === $content) { $content = $this->content; $this->content = null; @@ -106,36 +106,36 @@ abstract class VcsDriver switch ($notificationCode) { case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_FAILURE: - // for private repository returning 404 error when the authentification is incorrect - $auth = $this->io->getAuthentification($this->url); + // for private repository returning 404 error when the authorization is incorrect + $auth = $this->io->getAuthorization($this->url); $ps = $this->firstCall && 404 === $messageCode && null === $this->io->getLastUsername() && null === $auth['username']; 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) { $this->firstCall = false; } - // get authentification informations + // get authorization informations if (401 === $messageCode || $ps) { if (!$this->io->isInteractive()) { $mess = "The '" . $this->contentUrl . "' URL not found"; 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 " . $this->contentUrl . ":"); $username = $this->io->ask(' Username: '); $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); }