Skip to content

Commit bc74b38

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

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,6 @@ jobs:
177177
extensions: gd, curl, iconv, json, mbstring, openssl, sodium
178178
coverage: none
179179

180-
- name: Get composer cache directory
181-
id: composer-cache
182-
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
183-
184-
- name: Cache composer dependencies
185-
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
186-
with:
187-
path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }}
188-
key: PHP_${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}
189-
restore-keys: |
190-
PHP_${{ matrix.php-version }}-
191-
192180
- name: Install project dependencies
193181
run: |
194182
composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}

system/Autoloader/Autoloader.php

Lines changed: 15 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 if Composer namespaces have been loaded in this initialization.
98+
* Resets on each initialize() call to allow tests to load Composer.
99+
*/
100+
private bool $composerLoaded = 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->composerLoaded = 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 === []) {
@@ -146,13 +154,19 @@ private function loadComposerAutoloader(Modules $modules): void
146154
define('VENDORPATH', dirname($this->composerPath) . DIRECTORY_SEPARATOR);
147155
}
148156

157+
// Skip if already loaded in this initialization
158+
if ($this->composerLoaded) {
159+
return;
160+
}
161+
149162
/** @var ClassLoader $composer */
150163
$composer = include $this->composerPath;
151164

152165
// Should we load through Composer's namespaces, also?
153166
if ($modules->discoverInComposer) {
154167
$composerPackages = $modules->composerPackages;
155168
$this->loadComposerNamespaces($composer, $composerPackages ?? []);
169+
$this->composerLoaded = true;
156170
}
157171

158172
unset($composer);
@@ -170,8 +184,8 @@ private function loadComposerAutoloader(Modules $modules): void
170184
*/
171185
public function register()
172186
{
173-
spl_autoload_register($this->loadClass(...), prepend: true);
174187
spl_autoload_register($this->loadClassmap(...), prepend: true);
188+
spl_autoload_register($this->loadClass(...), prepend: true);
175189

176190
foreach ($this->files as $file) {
177191
$this->includeFile($file);

0 commit comments

Comments
 (0)