瀏覽代碼

Moved 401 handling from ComposerRepository to RemoteFilesystem and
displaying the url when asking for the credentials.

Stephan Hochdörfer 12 年之前
父節點
當前提交
dcdcf57f3f
共有 2 個文件被更改,包括 12 次插入25 次删除
  1. 0 13
      src/Composer/Repository/ComposerRepository.php
  2. 12 12
      src/Composer/Util/RemoteFilesystem.php

+ 0 - 13
src/Composer/Repository/ComposerRepository.php

@@ -17,7 +17,6 @@ use Composer\Package\PackageInterface;
 use Composer\Package\AliasPackage;
 use Composer\Package\AliasPackage;
 use Composer\Package\Version\VersionParser;
 use Composer\Package\Version\VersionParser;
 use Composer\DependencyResolver\Pool;
 use Composer\DependencyResolver\Pool;
-use Composer\Downloader\TransportException;
 use Composer\Json\JsonFile;
 use Composer\Json\JsonFile;
 use Composer\Cache;
 use Composer\Cache;
 use Composer\Config;
 use Composer\Config;
@@ -499,18 +498,6 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
                     continue;
                     continue;
                 }
                 }
 
 
-                // in case the remote filesystem responds with an 401 error ask for credentials
-                if($e instanceof TransportException && ($e->getCode() == 401))
-                {
-                    $this->io->write('Enter the access credentials needed to access the repository');
-                    $username = $this->io->ask('Username: ');
-                    $password = $this->io->askAndHideAnswer('Password: ');
-                    $this->rfs->setAuthentication($filename, $username, $password);
-
-                    // try fetching the file again
-                    return $this->fetchFile($filename, $cacheKey, $sha256);
-                }
-
                 if ($e instanceof RepositorySecurityException) {
                 if ($e instanceof RepositorySecurityException) {
                     throw $e;
                     throw $e;
                 }
                 }

+ 12 - 12
src/Composer/Util/RemoteFilesystem.php

@@ -44,18 +44,6 @@ class RemoteFilesystem
         $this->options = $options;
         $this->options = $options;
     }
     }
 
 
-    /**
-     * Set the authentication information for the repository.
-     *
-     * @param string $originUrl The origin URL
-     * @param string $username  The username
-     * @param string $password  The password
-     */
-    public function setAuthentication($originUrl, $username, $password = null)
-    {
-        return $this->io->setAuthentication($originUrl, $username, $password);
-    }
-
     /**
     /**
      * Copy the remote file in local.
      * Copy the remote file in local.
      *
      *
@@ -137,6 +125,18 @@ class RemoteFilesystem
             if ($e instanceof TransportException && !empty($http_response_header[0])) {
             if ($e instanceof TransportException && !empty($http_response_header[0])) {
                 $e->setHeaders($http_response_header);
                 $e->setHeaders($http_response_header);
             }
             }
+
+            // in case the remote filesystem responds with an 401 error ask for credentials
+            if($e instanceof TransportException && ($e->getCode() == 401))
+            {
+                $this->io->write('Enter the access credentials needed to access the resource at '.$originUrl);
+                $username = $this->io->ask('Username: ');
+                $password = $this->io->askAndHideAnswer('Password: ');
+                $this->io->setAuthentication($originUrl, $username, $password);
+
+                // try getting the file again
+                return $this->get($originUrl, $fileUrl, $additionalOptions, $fileName, $progress);
+            }
         }
         }
         if ($errorMessage && !ini_get('allow_url_fopen')) {
         if ($errorMessage && !ini_get('allow_url_fopen')) {
             $errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';
             $errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';