From 2c8a4a1b938fc980f4a3923d9678a536b15ba030 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 21 Apr 2020 15:25:35 +0200 Subject: [PATCH] Add platform-check config option to disable platform_check.php generation, and disable it for Composer --- composer.json | 3 ++- doc/06-config.md | 5 ++++ res/composer-schema.json | 4 ++++ src/Composer/Autoload/AutoloadGenerator.php | 23 +++++++++++++++---- src/Composer/Command/ConfigCommand.php | 1 + src/Composer/Compiler.php | 4 +++- src/Composer/Config.php | 1 + .../Test/Autoload/AutoloadGeneratorTest.php | 3 +++ 8 files changed, 38 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index e0ced56f3..824d20330 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,8 @@ "config": { "platform": { "php": "5.3.9" - } + }, + "platform-check": false }, "extra": { "branch-alias": { diff --git a/doc/06-config.md b/doc/06-config.md index 603de014a..a79f3fe5d 100644 --- a/doc/06-config.md +++ b/doc/06-config.md @@ -307,4 +307,9 @@ in the composer home, cache, and data directories. Defaults to `true`. If set to `false`, Composer will not create a `composer.lock` file. +## platform-check + +Defaults to `true`. If set to `false`, Composer will not create and require a +`platform_check.php` file as part of the autoloader bootstrap. + ← [Repositories](05-repositories.md) | [Community](07-community.md) → diff --git a/res/composer-schema.json b/res/composer-schema.json index 407817b78..47666a843 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -306,6 +306,10 @@ "lock": { "type": "boolean", "description": "Defaults to true. If set to false, Composer will not create a composer.lock file." + }, + "platform-check": { + "type": "boolean", + "description": "Defaults to true. If set to false, Composer will not create and require a platform_check.php file as part of the autoloader bootstrap." } } }, diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 0a9e2928e..386c2717a 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -312,9 +312,14 @@ EOF; unlink($includeFilesFilePath); } $this->filePutContentsIfModified($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion)); - $this->filePutContentsIfModified($targetDir.'/platform_check.php', $this->getPlatformCheck($packageMap)); + $checkPlatform = $config->get('platform-check'); + if ($checkPlatform) { + $this->filePutContentsIfModified($targetDir.'/platform_check.php', $this->getPlatformCheck($packageMap)); + } elseif (file_exists($targetDir.'/platform_check.php')) { + unlink($targetDir.'/platform_check.php'); + } $this->filePutContentsIfModified($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); - $this->filePutContentsIfModified($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion)); + $this->filePutContentsIfModified($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion, $checkPlatform)); $this->safeCopy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); $this->safeCopy(__DIR__.'/../../../LICENSE', $targetDir.'/LICENSE'); @@ -687,7 +692,7 @@ return ComposerAutoloaderInit$suffix::getLoader(); AUTOLOAD; } - protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion = 70000) + protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion, $checkPlatform) { $file = <<
array($booleanValidator, $booleanNormalizer), 'htaccess-protect' => array($booleanValidator, $booleanNormalizer), 'lock' => array($booleanValidator, $booleanNormalizer), + 'platform-check' => array($booleanValidator, $booleanNormalizer), ); $multiConfigValues = array( 'github-protocols' => array( diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index f6d0cd5ac..fdae04720 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -139,7 +139,9 @@ class Compiler $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_files.php')); $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_real.php')); $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_static.php')); - $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/platform_check.php')); + if (file_exists(__DIR__.'/../../vendor/composer/platform_check.php')) { + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/platform_check.php')); + } if (file_exists(__DIR__.'/../../vendor/composer/include_paths.php')) { $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/include_paths.php')); } diff --git a/src/Composer/Config.php b/src/Composer/Config.php index e57d21cab..455ae6db7 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -64,6 +64,7 @@ class Config 'htaccess-protect' => true, 'use-github-api' => true, 'lock' => true, + 'platform-check' => true, // valid keys without defaults (auth config stuff): // bitbucket-oauth // github-oauth diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index d756b2994..f9de00199 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -101,6 +101,9 @@ class AutoloadGeneratorTest extends TestCase 'vendor-dir' => function () use ($that) { return $that->vendorDir; }, + 'platform-check' => function () { + return true; + }, ); $this->config->expects($this->atLeastOnce())