diff --git a/.github/workflows/autoloader.yml b/.github/workflows/autoloader.yml new file mode 100644 index 000000000..5955d5304 --- /dev/null +++ b/.github/workflows/autoloader.yml @@ -0,0 +1,40 @@ +name: "Autoloader" + +on: + push: + paths-ignore: + - 'doc/**' + pull_request: + paths-ignore: + - 'doc/**' + +permissions: + contents: read + +jobs: + tests: + name: "Autoloader" + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: "actions/checkout@v3" + + - name: "Install Composer dependencies" + run: "composer config platform --unset && composer install" + + - name: "Dump autoloader in the test directory using latest Composer" + run: "./bin/composer install -d tests/Composer/Test/Autoload/MinimumVersionSupport" + + - name: "Install oldest supported PHP version for autoloader" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "intl, zip" + ini-values: "memory_limit=-1" + php-version: "5.6" + + - name: "Check the autoloader can be executed" + run: "php main.php" + working-directory: tests/Composer/Test/Autoload/MinimumVersionSupport diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index fc097a683..a16e6b67b 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -1029,7 +1029,7 @@ REGISTER_LOADER; } }, null, null); foreach (\$filesToLoad as \$fileIdentifier => \$file) { - (\$requireFile)(\$fileIdentifier, \$file); + \$requireFile(\$fileIdentifier, \$file); } diff --git a/src/Composer/Autoload/ClassLoader.php b/src/Composer/Autoload/ClassLoader.php index 44ee4c819..a72151c77 100644 --- a/src/Composer/Autoload/ClassLoader.php +++ b/src/Composer/Autoload/ClassLoader.php @@ -429,7 +429,8 @@ class ClassLoader public function loadClass($class) { if ($file = $this->findFile($class)) { - (self::$includeFile)($file); + $includeFile = self::$includeFile; + $includeFile($file); return true; } @@ -560,7 +561,10 @@ class ClassLoader return false; } - private static function initializeIncludeClosure(): void + /** + * @return void + */ + private static function initializeIncludeClosure() { if (self::$includeFile !== null) { return; diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php index e9344b8a8..b796e5613 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php @@ -40,7 +40,7 @@ class ComposerAutoloaderInitFilesAutoloadOrder } }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { - ($requireFile)($fileIdentifier, $file); + $requireFile($fileIdentifier, $file); } return $loader; diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index 8c3403612..a6122a21e 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -40,7 +40,7 @@ class ComposerAutoloaderInitFilesAutoload } }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { - ($requireFile)($fileIdentifier, $file); + $requireFile($fileIdentifier, $file); } return $loader; diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php index 164a26309..aebf8cfe6 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php @@ -44,7 +44,7 @@ class ComposerAutoloaderInitFilesAutoload } }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { - ($requireFile)($fileIdentifier, $file); + $requireFile($fileIdentifier, $file); } return $loader; diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php index 99d784bc3..0f9494393 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -42,7 +42,7 @@ class ComposerAutoloaderInitTargetDir } }, null, null); foreach ($filesToLoad as $fileIdentifier => $file) { - ($requireFile)($fileIdentifier, $file); + $requireFile($fileIdentifier, $file); } return $loader; diff --git a/tests/Composer/Test/Autoload/MinimumVersionSupport/Foo.php b/tests/Composer/Test/Autoload/MinimumVersionSupport/Foo.php new file mode 100644 index 000000000..fe50969f2 --- /dev/null +++ b/tests/Composer/Test/Autoload/MinimumVersionSupport/Foo.php @@ -0,0 +1,14 @@ +