Skip to content

Commit 2c7002d

Browse files
committed
refactor: prepend Autoloader's own autoload functions
1 parent c67b0a7 commit 2c7002d

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

.github/workflows/test-random-execution.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ jobs:
213213
args+=("--max-jobs" "${{ inputs.max-jobs }}")
214214
fi
215215
216-
# Add --repeat flag (always, default is 10)
217-
args+=("--repeat" "${{ inputs.repeat || '10' }}")
216+
# Add --repeat flag (always, default is 50)
217+
args+=("--repeat" "${{ inputs.repeat || '50' }}")
218218
219219
# Add --timeout flag (always, default is 300)
220220
args+=("--timeout" "${{ inputs.timeout || '300' }}")

system/Autoloader/Autoloader.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ public function register()
188188
$this->registeredClosures[] = $loadClassmap;
189189
$this->registeredClosures[] = $loadClass;
190190

191-
spl_autoload_register($loadClassmap, true);
192-
spl_autoload_register($loadClass, true);
191+
spl_autoload_register($loadClassmap, prepend: true);
192+
spl_autoload_register($loadClass, prepend: true);
193193

194194
foreach ($this->files as $file) {
195195
$this->includeFile($file);
@@ -217,22 +217,24 @@ public function unregister(): void
217217
*/
218218
public function addNamespace($namespace, ?string $path = null)
219219
{
220-
if (is_array($namespace)) {
221-
foreach ($namespace as $prefix => $namespacedPath) {
222-
$prefix = trim($prefix, '\\');
220+
if (is_string($namespace)) {
221+
if ($path === null) {
222+
return $this;
223+
}
223224

224-
if (is_array($namespacedPath)) {
225-
foreach ($namespacedPath as $dir) {
226-
$this->prefixes[$prefix][] = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR;
227-
}
225+
$namespace = [$namespace => $path];
226+
}
228227

229-
continue;
230-
}
228+
foreach ($namespace as $prefix => $paths) {
229+
$prefix = trim($prefix, '\\');
231230

232-
$this->prefixes[$prefix][] = rtrim($namespacedPath, '\\/') . DIRECTORY_SEPARATOR;
231+
if (is_string($paths)) {
232+
$paths = [$paths];
233+
}
234+
235+
foreach ($paths as $path) {
236+
$this->prefixes[$prefix][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
233237
}
234-
} else {
235-
$this->prefixes[trim($namespace, '\\')][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
236238
}
237239

238240
return $this;

0 commit comments

Comments
 (0)