From 60fddb2c09b40a767e997ca34a4801fafaa649e2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 17 Feb 2012 12:13:56 +0100 Subject: [PATCH] Use parse_url instead of manual parsing --- src/Composer/Util/RemoteFilesystem.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 0f245b81b..eedba8e64 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -96,7 +96,7 @@ class RemoteFilesystem $auth = $this->io->getAuthorization($originUrl); $authStr = base64_encode($auth['username'] . ':' . $auth['password']); $options['http']['header'] = "Authorization: Basic $authStr\r\n"; - } else if (null !== $this->io->getLastUsername()) { + } elseif (null !== $this->io->getLastUsername()) { $authStr = base64_encode($this->io->getLastUsername() . ':' . $this->io->getLastPassword()); $options['http'] = array('header' => "Authorization: Basic $authStr\r\n"); $this->io->setAuthorization($originUrl, $this->io->getLastUsername(), $this->io->getLastPassword()); @@ -161,7 +161,7 @@ class RemoteFilesystem throw new \RuntimeException($mess); } - $this->io->overwrite(' Authorization required (' .$this->getHostname($this->fileUrl).'):'); + $this->io->overwrite(' Authorization required ('.parse_url($this->fileUrl, PHP_URL_HOST).'):'); $username = $this->io->ask(' Username: '); $password = $this->io->askAndHideAnswer(' Password: '); $this->io->setAuthorization($this->originUrl, $username, $password); @@ -195,19 +195,4 @@ class RemoteFilesystem break; } } - - /** - * Get the hostname. - * - * @param string $url The file URL - * - * @return string The hostname - */ - protected function getHostname($url) - { - $host = substr($url, strpos($url, '://') + 3); - $host = substr($host, 0, strpos($host, '/')); - - return $host; - } } \ No newline at end of file