@@ -93,6 +93,11 @@ class Autoloader
9393 */
9494 protected $ helpers = ['url ' ];
9595
96+ /**
97+ * Whether this autoloader has been registered with SPL.
98+ */
99+ private bool $ registered = false ;
100+
96101 public function __construct (private readonly string $ composerPath = COMPOSER_PATH )
97102 {
98103 }
@@ -170,8 +175,13 @@ private function loadComposerAutoloader(Modules $modules): void
170175 */
171176 public function register ()
172177 {
173- spl_autoload_register ($ this ->loadClassmap (...), true );
174- spl_autoload_register ($ this ->loadClass (...), true );
178+ if ($ this ->registered ) {
179+ return ;
180+ }
181+
182+ spl_autoload_register ([$ this , 'loadClassmap ' ], true );
183+ spl_autoload_register ([$ this , 'loadClass ' ], true );
184+ $ this ->registered = true ;
175185
176186 foreach ($ this ->files as $ file ) {
177187 $ this ->includeFile ($ file );
@@ -183,8 +193,13 @@ public function register()
183193 */
184194 public function unregister (): void
185195 {
186- spl_autoload_unregister ($ this ->loadClass (...));
187- spl_autoload_unregister ($ this ->loadClassmap (...));
196+ if (! $ this ->registered ) {
197+ return ;
198+ }
199+
200+ spl_autoload_unregister ([$ this , 'loadClass ' ]);
201+ spl_autoload_unregister ([$ this , 'loadClassmap ' ]);
202+ $ this ->registered = false ;
188203 }
189204
190205 /**
0 commit comments