Browse Source

Merge branch '1.8'

Jordi Boggiano 6 years ago
parent
commit
a186620210
2 changed files with 30 additions and 34 deletions
  1. 2 22
      src/Composer/Repository/ComposerRepository.php
  2. 28 12
      src/Composer/Util/RemoteFilesystem.php

+ 2 - 22
src/Composer/Repository/ComposerRepository.php

@@ -700,7 +700,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
                 }
 
                 $data = JsonFile::parseJson($json, $filename);
-                $this->outputWarnings($data);
+                RemoteFilesystem::outputWarnings($this->io, $this->url, $data);
 
                 if ($cacheKey) {
                     if ($storeLastModifiedTime) {
@@ -765,7 +765,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
                 }
 
                 $data = JsonFile::parseJson($json, $filename);
-                $this->outputWarnings($data);
+                RemoteFilesystem::outputWarnings($this->io, $this->url, $data);
 
                 $lastModifiedDate = $rfs->findHeaderValue($rfs->getLastHeaders(), 'last-modified');
                 if ($lastModifiedDate) {
@@ -826,24 +826,4 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
         // wipe rootData as it is fully consumed at this point and this saves some memory
         $this->rootData = true;
     }
-
-    private function outputWarnings($data)
-    {
-        foreach (array('warning', 'info') as $type) {
-            if (empty($data[$type])) {
-                continue;
-            }
-
-            if (!empty($data[$type . '-versions'])) {
-                $versionParser = new VersionParser();
-                $constraint = $versionParser->parseConstraints($data[$type . '-versions']);
-                $composer = new Constraint('==', $versionParser->normalize(Composer::getVersion()));
-                if (!$constraint->matches($composer)) {
-                    continue;
-                }
-            }
-
-            $this->io->writeError('<'.$type.'>'.ucfirst($type).' from '.$this->url.': '.$data[$type].'</'.$type.'>');
-        }
-    }
 }

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

@@ -13,6 +13,9 @@
 namespace Composer\Util;
 
 use Composer\Config;
+use Composer\Composer;
+use Composer\Semver\Constraint\Constraint;
+use Composer\Package\Version\VersionParser;
 use Composer\IO\IOInterface;
 use Composer\Downloader\TransportException;
 use Composer\CaBundle\CaBundle;
@@ -324,15 +327,12 @@ class RemoteFilesystem
 
             if (!empty($http_response_header[0])) {
                 $statusCode = $this->findStatusCode($http_response_header);
+                if ($statusCode >= 400 && $this->findHeaderValue($http_response_header, 'content-type') === 'application/json') {
+                    self::outputWarnings($this->io, $originUrl, json_decode($result, true));
+                }
+
                 if (in_array($statusCode, array(401, 403)) && $this->retryAuthFailure) {
-                    $warning = null;
-                    if ($this->findHeaderValue($http_response_header, 'content-type') === 'application/json') {
-                        $data = json_decode($result, true);
-                        if (!empty($data['warning'])) {
-                            $warning = $data['warning'];
-                        }
-                    }
-                    $this->promptAuthAndRetry($statusCode, $this->findStatusMessage($http_response_header), $warning, $http_response_header);
+                    $this->promptAuthAndRetry($statusCode, $this->findStatusMessage($http_response_header), null, $http_response_header);
                 }
             }
 
@@ -741,10 +741,6 @@ class RemoteFilesystem
                 throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.", $httpStatus);
             }
 
-            $this->io->overwriteError('');
-            if ($warning) {
-                $this->io->writeError('    <warning>'.$warning.'</warning>');
-            }
             $this->io->writeError('    Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
             $username = $this->io->ask('      Username: ');
             $password = $this->io->askAndHideAnswer('      Password: ');
@@ -1090,4 +1086,24 @@ class RemoteFilesystem
 
         return count($pathParts) >= 4 && $pathParts[3] == 'downloads';
     }
+
+    public static function outputWarnings(IOInterface $io, $url, $data)
+    {
+        foreach (array('warning', 'info') as $type) {
+            if (empty($data[$type])) {
+                continue;
+            }
+
+            if (!empty($data[$type . '-versions'])) {
+                $versionParser = new VersionParser();
+                $constraint = $versionParser->parseConstraints($data[$type . '-versions']);
+                $composer = new Constraint('==', $versionParser->normalize(Composer::getVersion()));
+                if (!$constraint->matches($composer)) {
+                    continue;
+                }
+            }
+
+            $io->writeError('<'.$type.'>'.ucfirst($type).' from '.$url.': '.$data[$type].'</'.$type.'>');
+        }
+    }
 }