prefixes[$key] = rtrim( string: $dir, characters: DIRECTORY_SEPARATOR ) . '/'; } public function load(string $class): void { foreach ($this->prefixes as $prefix => $dir) { if (str_starts_with(haystack: $class, needle: $prefix)) { $file = $dir . str_replace( search: '\\', replace: '/', subject: substr( string: $class, offset: strlen( string: $prefix ) ) ) . '.php'; if (file_exists(filename: $file)) { require $file; return; } } } } }