From 07d72d24ef2888474da0230a2d316708ac8c8af6 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:38:29 -0400 Subject: [PATCH] remove Loader::autoload in favor of psr-4 --- composer.json | 4 ++-- src/Flight.php | 2 -- src/autoload.php | 9 --------- src/core/Loader.php | 18 ------------------ tests/LoaderTest.php | 22 ++-------------------- 5 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 src/autoload.php diff --git a/composer.json b/composer.json index 426f7f3..e08f86a 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,8 @@ "ext-json": "*" }, "autoload": { - "files": [ - "src/autoload.php" + "classmap": [ + "src/Flight.php" ], "psr-4": { "flight\\": "src" diff --git a/src/Flight.php b/src/Flight.php index c2e9a01..ddb536f 100644 --- a/src/Flight.php +++ b/src/Flight.php @@ -11,8 +11,6 @@ use flight\net\Route; use flight\core\EventDispatcher; use Psr\Container\ContainerInterface; -require_once __DIR__ . '/autoload.php'; - /** * The Flight class is a static representation of the framework. * diff --git a/src/autoload.php b/src/autoload.php deleted file mode 100644 index b5f84ab..0000000 --- a/src/autoload.php +++ /dev/null @@ -1,9 +0,0 @@ -instances = []; } - /** - * Starts/stops autoloader. - * @param bool $enabled Enable/disable autoloading - * @param string|iterable $dirs Autoload directories - */ - public static function autoload(bool $enabled = true, $dirs = []): void - { - if ($enabled) { - spl_autoload_register([__CLASS__, 'loadClass']); - } else { - spl_autoload_unregister([__CLASS__, 'loadClass']); // @codeCoverageIgnore - } - - if (!empty($dirs)) { - self::addDirectory($dirs); - } - } - /** * Autoloads classes. * Classes are not allowed to have underscores in their names. diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index 2ab19b3..af4a1a8 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace tests; use flight\core\Loader; -use tests\classes\Factory; -use tests\classes\User; use PHPUnit\Framework\TestCase; +use tests\classes\User; +use tests\classes\Factory; use tests\classes\TesterClass; class LoaderTest extends TestCase @@ -17,7 +17,6 @@ class LoaderTest extends TestCase protected function setUp(): void { $this->loader = new Loader(); - $this->loader->autoload(true, __DIR__ . '/classes'); } // Autoload a class @@ -137,21 +136,4 @@ class LoaderTest extends TestCase $this->assertEquals('Sally', $TesterClass->param5); $this->assertEquals('Suzie', $TesterClass->param6); } - - public function testAddDirectoryAsArray(): void - { - $loader = new class extends Loader { - public function getDirectories() - { - return self::$dirs; - } - }; - - $loader->addDirectory([__DIR__ . '/classes']); - - self::assertEquals([ - dirname(__DIR__), - __DIR__ . '/classes' - ], $loader->getDirectories()); - } }