Skip to content

Commit a3714af

Browse files
committed
add suggested fix from copilot
1 parent 28d4f2e commit a3714af

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

system/Autoloader/Autoloader.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class Autoloader
9393
*/
9494
protected $helpers = ['url'];
9595

96+
/**
97+
* Track whether Composer namespaces have been loaded to prevent
98+
* re-loading in parallel test execution contexts.
99+
*/
100+
private bool $composerNamespacesLoaded = false;
101+
96102
public function __construct(private readonly string $composerPath = COMPOSER_PATH)
97103
{
98104
}
@@ -109,6 +115,8 @@ public function initialize(Autoload $config, Modules $modules)
109115
$this->classmap = [];
110116
$this->files = [];
111117

118+
$this->composerNamespacesLoaded = false;
119+
112120
// We have to have one or the other, though we don't enforce the need
113121
// to have both present in order to work.
114122
if ($config->psr4 === [] && $config->classmap === []) {
@@ -150,9 +158,11 @@ private function loadComposerAutoloader(Modules $modules): void
150158
$composer = include $this->composerPath;
151159

152160
// Should we load through Composer's namespaces, also?
153-
if ($modules->discoverInComposer) {
161+
// Guard against repeated loading in parallel execution environments
162+
if ($modules->discoverInComposer && ! $this->composerNamespacesLoaded) {
154163
$composerPackages = $modules->composerPackages;
155164
$this->loadComposerNamespaces($composer, $composerPackages ?? []);
165+
$this->composerNamespacesLoaded = true;
156166
}
157167

158168
unset($composer);

0 commit comments

Comments
 (0)