Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a8dfe6

Browse files
authored
Clarify that autoloader-suffix should be a non-empty-string, fixes #10720 (#10725)
1 parent bb0edce commit 0a8dfe6

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

doc/06-config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ with other autoloaders.
315315

316316
## autoloader-suffix
317317

318-
Defaults to `null`. String to be used as a suffix for the generated Composer
319-
autoloader. When null a random one will be generated.
318+
Defaults to `null`. Non-empty string to be used as a suffix for the generated
319+
Composer autoloader. When null a random one will be generated.
320320

321321
## optimize-autoloader
322322

phpstan/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parameters:
1616
- '../src/Composer/Console/HtmlOutputFormatter.php'
1717

1818
reportUnmatchedIgnoredErrors: false
19+
treatPhpDocTypesAsCertain: false
1920

2021
ignoreErrors:
2122
# unused parameters

src/Composer/Autoload/AutoloadGenerator.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ public function setPlatformRequirementFilter(PlatformRequirementFilterInterface
159159
/**
160160
* @param string $targetDir
161161
* @param bool $scanPsrPackages
162-
* @param string $suffix
162+
* @param string|null $suffix
163163
* @return int
164164
* @throws \Seld\JsonLint\ParsingException
165165
* @throws \RuntimeException
166166
*/
167-
public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, $targetDir, $scanPsrPackages = false, $suffix = '')
167+
public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, $targetDir, $scanPsrPackages = false, $suffix = null)
168168
{
169169
if ($this->classMapAuthoritative) {
170170
// Force scanPsrPackages when classmap is authoritative
@@ -374,16 +374,23 @@ public static function autoload(\$class)
374374
}
375375
$classmapFile .= ");\n";
376376

377-
if (!$suffix) {
378-
if (!$config->get('autoloader-suffix') && Filesystem::isReadable($vendorPath.'/autoload.php')) {
377+
if ('' === $suffix) {
378+
$suffix = null;
379+
}
380+
if (null === $suffix) {
381+
$suffix = $config->get('autoloader-suffix');
382+
383+
// carry over existing autoload.php's suffix if possible and none is configured
384+
if (null === $suffix && Filesystem::isReadable($vendorPath.'/autoload.php')) {
379385
$content = file_get_contents($vendorPath.'/autoload.php');
380386
if (Preg::isMatch('{ComposerAutoloaderInit([^:\s]+)::}', $content, $match)) {
381387
$suffix = $match[1];
382388
}
383389
}
384390

385-
if (!$suffix) {
386-
$suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true));
391+
// generate one if we still haven't got a suffix
392+
if (null === $suffix) {
393+
$suffix = md5(uniqid('', true));
387394
}
388395
}
389396

src/Composer/Config.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ public function get($key, $flags = 0)
427427

428428
return $protos;
429429

430+
case 'autoloader-suffix':
431+
if ($this->config[$key] === '') { // we need to guarantee null or non-empty-string
432+
return null;
433+
}
434+
435+
return $this->process($this->config[$key], $flags);
436+
430437
default:
431438
if (!isset($this->config[$key])) {
432439
return null;

0 commit comments

Comments
 (0)