Selaa lähdekoodia

Add platform-check config option to disable platform_check.php generation, and disable it for Composer

Jordi Boggiano 5 vuotta sitten
vanhempi
commit
2c8a4a1b93

+ 2 - 1
composer.json

@@ -52,7 +52,8 @@
     "config": {
         "platform": {
             "php": "5.3.9"
-        }
+        },
+        "platform-check": false
     },
     "extra": {
         "branch-alias": {

+ 5 - 0
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) →

+ 4 - 0
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."
                 }
             }
         },

+ 19 - 4
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 = <<<HEADER
 <?php
@@ -714,14 +719,24 @@ class ComposerAutoloaderInit$suffix
             return self::\$loader;
         }
 
+
+HEADER;
+
+        if ($checkPlatform) {
+            $file .= <<<'PLATFORM_CHECK'
         require __DIR__ . '/platform_check.php';
 
+
+PLATFORM_CHECK;
+        }
+
+        $file .= <<<CLASSLOADER_INIT
         spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'), true, $prependAutoloader);
         self::\$loader = \$loader = new \\Composer\\Autoload\\ClassLoader();
         spl_autoload_unregister(array('ComposerAutoloaderInit$suffix', 'loadClassLoader'));
 
 
-HEADER;
+CLASSLOADER_INIT;
 
         if ($useIncludePath) {
             $file .= <<<'INCLUDE_PATH'

+ 1 - 0
src/Composer/Command/ConfigCommand.php

@@ -421,6 +421,7 @@ EOT
             'github-expose-hostname' => array($booleanValidator, $booleanNormalizer),
             'htaccess-protect' => array($booleanValidator, $booleanNormalizer),
             'lock' => array($booleanValidator, $booleanNormalizer),
+            'platform-check' => array($booleanValidator, $booleanNormalizer),
         );
         $multiConfigValues = array(
             'github-protocols' => array(

+ 3 - 1
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'));
         }

+ 1 - 0
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

+ 3 - 0
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())