From 2c7002dfd319fd8a1942b07c14f01435675529da Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 9 Apr 2026 02:44:10 +0800 Subject: [PATCH] refactor: prepend `Autoloader`'s own autoload functions --- .github/workflows/test-random-execution.yml | 4 +-- system/Autoloader/Autoloader.php | 30 +++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test-random-execution.yml b/.github/workflows/test-random-execution.yml index d1ef81937284..df3078eaea21 100644 --- a/.github/workflows/test-random-execution.yml +++ b/.github/workflows/test-random-execution.yml @@ -213,8 +213,8 @@ jobs: args+=("--max-jobs" "${{ inputs.max-jobs }}") fi - # Add --repeat flag (always, default is 10) - args+=("--repeat" "${{ inputs.repeat || '10' }}") + # Add --repeat flag (always, default is 50) + args+=("--repeat" "${{ inputs.repeat || '50' }}") # Add --timeout flag (always, default is 300) args+=("--timeout" "${{ inputs.timeout || '300' }}") diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 29d119727f94..d6f1bc61cf65 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -188,8 +188,8 @@ public function register() $this->registeredClosures[] = $loadClassmap; $this->registeredClosures[] = $loadClass; - spl_autoload_register($loadClassmap, true); - spl_autoload_register($loadClass, true); + spl_autoload_register($loadClassmap, prepend: true); + spl_autoload_register($loadClass, prepend: true); foreach ($this->files as $file) { $this->includeFile($file); @@ -217,22 +217,24 @@ public function unregister(): void */ public function addNamespace($namespace, ?string $path = null) { - if (is_array($namespace)) { - foreach ($namespace as $prefix => $namespacedPath) { - $prefix = trim($prefix, '\\'); + if (is_string($namespace)) { + if ($path === null) { + return $this; + } - if (is_array($namespacedPath)) { - foreach ($namespacedPath as $dir) { - $this->prefixes[$prefix][] = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR; - } + $namespace = [$namespace => $path]; + } - continue; - } + foreach ($namespace as $prefix => $paths) { + $prefix = trim($prefix, '\\'); - $this->prefixes[$prefix][] = rtrim($namespacedPath, '\\/') . DIRECTORY_SEPARATOR; + if (is_string($paths)) { + $paths = [$paths]; + } + + foreach ($paths as $path) { + $this->prefixes[$prefix][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR; } - } else { - $this->prefixes[trim($namespace, '\\')][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR; } return $this;