From 28801420836b61ddc757f30d691bd81ccfb98dbc Mon Sep 17 00:00:00 2001 From: Ambrose Casanova <279373485+ambrose5773@users.noreply.github.com> Date: Wed, 2 Sep 2026 01:46:22 +0000 Subject: [PATCH 1/2] Restore Flight::path() autoloading after the 3.19 autoload rework. PR 709 dropped the Composer files entry for flight/autoload.php and that file returned early when vendor/autoload.php existed, so Loader::autoload() never registered. path() still added directories; namespaced app classes never loaded. Upgrades must not break that. --- composer.json | 3 +++ flight/autoload.php | 4 ++-- tests/AutoloadTest.php | 14 ++++++++++++++ .../app/middleware/Something.php | 9 +++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/path_autoload_fixtures/app/middleware/Something.php diff --git a/composer.json b/composer.json index 75120950..9db2f5c7 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,9 @@ "ext-json": "*" }, "autoload": { + "files": [ + "flight/autoload.php" + ], "classmap": [ "flight/Flight.php" ], diff --git a/flight/autoload.php b/flight/autoload.php index e4017284..0b0e7674 100644 --- a/flight/autoload.php +++ b/flight/autoload.php @@ -8,7 +8,7 @@ require_once __DIR__ . '/core/Loader.php'; if (file_exists(__DIR__ . '/../vendor/autoload.php')) { - return require_once __DIR__ . '/../vendor/autoload.php'; + require_once __DIR__ . '/../vendor/autoload.php'; } -Loader::autoload(true, dirname(__DIR__)); +Loader::autoload(true, [dirname(__DIR__)]); diff --git a/tests/AutoloadTest.php b/tests/AutoloadTest.php index 97ee31aa..7d8959a6 100644 --- a/tests/AutoloadTest.php +++ b/tests/AutoloadTest.php @@ -4,6 +4,7 @@ namespace tests; +use Flight; use flight\Engine; use tests\classes\User; use PHPUnit\Framework\TestCase; @@ -44,4 +45,17 @@ public function testMissingClass(): void self::assertNull($test); } + + // Flight::path() must load namespaced classes that Composer PSR-4 does not map + public function testPathAutoloadsNamespacedClassOutsideComposerPsr4(): void + { + $class = \app\middleware\Something::class; + + self::assertFalse(class_exists($class)); + + Flight::path(__DIR__ . '/path_autoload_fixtures'); + + self::assertTrue(class_exists($class)); + self::assertTrue(class_exists(Engine::class)); + } } diff --git a/tests/path_autoload_fixtures/app/middleware/Something.php b/tests/path_autoload_fixtures/app/middleware/Something.php new file mode 100644 index 00000000..67675bb8 --- /dev/null +++ b/tests/path_autoload_fixtures/app/middleware/Something.php @@ -0,0 +1,9 @@ + Date: Wed, 2 Sep 2026 01:54:26 +0000 Subject: [PATCH 2/2] Do not add the package root to Loader::$dirs under Composer. files autoload still registers Loader::autoload() so Flight::path() works. Composer PSR-4 already loads flight\*. Reset leftover path() dirs in AutoloadTest so LoaderTest can assert the exact list. --- flight/autoload.php | 5 +++-- tests/AutoloadTest.php | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/flight/autoload.php b/flight/autoload.php index 0b0e7674..9ae0c69d 100644 --- a/flight/autoload.php +++ b/flight/autoload.php @@ -9,6 +9,7 @@ if (file_exists(__DIR__ . '/../vendor/autoload.php')) { require_once __DIR__ . '/../vendor/autoload.php'; + Loader::autoload(true); +} else { + Loader::autoload(true, [dirname(__DIR__)]); } - -Loader::autoload(true, [dirname(__DIR__)]); diff --git a/tests/AutoloadTest.php b/tests/AutoloadTest.php index 7d8959a6..a6ad8631 100644 --- a/tests/AutoloadTest.php +++ b/tests/AutoloadTest.php @@ -5,9 +5,11 @@ namespace tests; use Flight; +use flight\core\Loader; use flight\Engine; use tests\classes\User; use PHPUnit\Framework\TestCase; +use ReflectionClass; class AutoloadTest extends TestCase { @@ -19,6 +21,17 @@ protected function setUp(): void $this->app->path(__DIR__ . '/classes'); } + protected function tearDown(): void + { + $dirsProperty = (new ReflectionClass(Loader::class))->getProperty('dirs'); + + if (PHP_VERSION_ID < 80100) { + $dirsProperty->setAccessible(true); + } + + $dirsProperty->setValue(null, []); + } + // Autoload a class public function testAutoload(): void {