1
0
Fork 0

Fix autoloading on PHP 5.6 (#11285)

* Add a CI check to ensure the autoloader can run on php5.6+

* Fix autoloading on PHP 5.6
pull/11292/head
Jordi Boggiano 2023-01-27 16:26:04 +01:00 committed by GitHub
parent 5165792f9c
commit 0a2846cb24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 88 additions and 7 deletions

40
.github/workflows/autoloader.yml vendored Normal file
View File

@ -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

View File

@ -1029,7 +1029,7 @@ REGISTER_LOADER;
}
}, null, null);
foreach (\$filesToLoad as \$fileIdentifier => \$file) {
(\$requireFile)(\$fileIdentifier, \$file);
\$requireFile(\$fileIdentifier, \$file);
}

View File

@ -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;

View File

@ -40,7 +40,7 @@ class ComposerAutoloaderInitFilesAutoloadOrder
}
}, null, null);
foreach ($filesToLoad as $fileIdentifier => $file) {
($requireFile)($fileIdentifier, $file);
$requireFile($fileIdentifier, $file);
}
return $loader;

View File

@ -40,7 +40,7 @@ class ComposerAutoloaderInitFilesAutoload
}
}, null, null);
foreach ($filesToLoad as $fileIdentifier => $file) {
($requireFile)($fileIdentifier, $file);
$requireFile($fileIdentifier, $file);
}
return $loader;

View File

@ -44,7 +44,7 @@ class ComposerAutoloaderInitFilesAutoload
}
}, null, null);
foreach ($filesToLoad as $fileIdentifier => $file) {
($requireFile)($fileIdentifier, $file);
$requireFile($fileIdentifier, $file);
}
return $loader;

View File

@ -42,7 +42,7 @@ class ComposerAutoloaderInitTargetDir
}
}, null, null);
foreach ($filesToLoad as $fileIdentifier => $file) {
($requireFile)($fileIdentifier, $file);
$requireFile($fileIdentifier, $file);
}
return $loader;

View File

@ -0,0 +1,14 @@
<?php
namespace Test;
class Foo
{
/**
* @return void
*/
public static function test()
{
echo 'psr-4 autoloading: OK'.PHP_EOL;
}
}

View File

@ -0,0 +1,11 @@
{
"name": "root/pkg",
"autoload": {
"files": [
"test.php"
],
"psr-4": {
"Test\\": "."
}
}
}

View File

@ -0,0 +1,9 @@
<?php
include 'vendor/autoload.php';
Test\Foo::test();
if (Composer\InstalledVersions::isInstalled('root/pkg')) {
echo 'isInstalled: OK'.PHP_EOL;
}

View File

@ -0,0 +1,3 @@
<?php
echo 'files autoloading: OK'.PHP_EOL;