remove directory loading in favor of psr-4

v4
fadrian06 7 days ago
parent 07d72d24ef
commit 78b8c4be60

@ -21,9 +21,6 @@ class Loader
/** @var array<string, object> Class instances */ /** @var array<string, object> Class instances */
protected array $instances = []; protected array $instances = [];
/** @var array<int, string> Autoload directories */
protected static array $dirs = [];
/** /**
* Registers a class. * Registers a class.
* @template T of object * @template T of object
@ -131,43 +128,4 @@ class Loader
$this->classes = []; $this->classes = [];
$this->instances = []; $this->instances = [];
} }
/**
* Autoloads classes.
* Classes are not allowed to have underscores in their names.
*
* @param string $class Class name
*/
public static function loadClass(string $class): void
{
$replace_chars = ['\\'];
$classFile = str_replace($replace_chars, '/', $class) . '.php';
foreach (self::$dirs as $dir) {
$filePath = "$dir/$classFile";
if (file_exists($filePath)) {
require_once $filePath;
return;
}
}
}
/**
* Adds a directory for autoloading classes.
* @param string|iterable<int, string> $dir Directory path
*/
public static function addDirectory($dir): void
{
if (is_array($dir) || is_object($dir)) {
foreach ($dir as $value) {
self::addDirectory($value);
}
} elseif (is_string($dir)) {
if (!in_array($dir, self::$dirs, true)) {
self::$dirs[] = $dir;
}
}
}
} }

@ -15,7 +15,6 @@ class AutoloadTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
$this->app = new Engine(); $this->app = new Engine();
$this->app->path(__DIR__ . '/classes');
} }
// Autoload a class // Autoload a class

@ -71,8 +71,6 @@ class FlightTest extends TestCase
// Register a class // Register a class
public function testRegister(): void public function testRegister(): void
{ {
Flight::path(__DIR__ . '/classes');
Flight::register('user', User::class); Flight::register('user', User::class);
$user = Flight::user(); $user = Flight::user();

Loading…
Cancel
Save