diff --git a/composer.json b/composer.json index 7512095..9db2f5c 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 e401728..0b0e767 100644 --- a/flight/autoload.php +++ b/flight/autoload.php @@ -8,7 +8,7 @@ require_once __DIR__ . '/Flight.php'; 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 97ee31a..7d8959a 100644 --- a/tests/AutoloadTest.php +++ b/tests/AutoloadTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace tests; +use Flight; use flight\Engine; use tests\classes\User; use PHPUnit\Framework\TestCase; @@ -44,4 +45,17 @@ class AutoloadTest extends TestCase 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 0000000..67675bb --- /dev/null +++ b/tests/path_autoload_fixtures/app/middleware/Something.php @@ -0,0 +1,9 @@ +