Skip to content

Commit 28d4f2e

Browse files
committed
refactor: prepend Autoloader's own autoload functions
1 parent 35c4872 commit 28d4f2e

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
@@ -170,8 +170,8 @@ private function loadComposerAutoloader(Modules $modules): void
170170
*/
171171
public function register()
172172
{
173-
spl_autoload_register($this->loadClassmap(...), true);
174-
spl_autoload_register($this->loadClass(...), true);
173+
spl_autoload_register($this->loadClass(...), prepend: true);
174+
spl_autoload_register($this->loadClassmap(...), prepend: true);
175175

176176
foreach ($this->files as $file) {
177177
$this->includeFile($file);
@@ -196,22 +196,24 @@ public function unregister(): void
196196
*/
197197
public function addNamespace($namespace, ?string $path = null)
198198
{
199-
if (is_array($namespace)) {
200-
foreach ($namespace as $prefix => $namespacedPath) {
201-
$prefix = trim($prefix, '\\');
199+
if (is_string($namespace)) {
200+
if ($path === null) {
201+
return $this;
202+
}
202203

203-
if (is_array($namespacedPath)) {
204-
foreach ($namespacedPath as $dir) {
205-
$this->prefixes[$prefix][] = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR;
206-
}
204+
$namespace = [$namespace => $path];
205+
}
207206

208-
continue;
209-
}
207+
foreach ($namespace as $prefix => $paths) {
208+
$prefix = trim($prefix, '\\');
210209

211-
$this->prefixes[$prefix][] = rtrim($namespacedPath, '\\/') . DIRECTORY_SEPARATOR;
210+
if (is_string($paths)) {
211+
$paths = [$paths];
212+
}
213+
214+
foreach ($paths as $path) {
215+
$this->prefixes[$prefix][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
212216
}
213-
} else {
214-
$this->prefixes[trim($namespace, '\\')][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
215217
}
216218

217219
return $this;

0 commit comments

Comments
 (0)