From 0ff5d315c58581274e21ccb3381dc669fe1d2856 Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 2 Aug 2024 21:40:12 +0000 Subject: [PATCH] fix: check if classes are loaded by a different autoloader --- CHANGELOG.md | 2 ++ src/Autoloader.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e6ecfe9..2449ef87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +- fix: Check if classes are loaded by a different autoloader before attempting to autoload them. + ## v0.13.0 **:warning: This release contains multiple breaking changes.** diff --git a/src/Autoloader.php b/src/Autoloader.php index fd2af6fe..ef8154df 100644 --- a/src/Autoloader.php +++ b/src/Autoloader.php @@ -32,10 +32,16 @@ public static function autoload(): bool { return true; } + // If the autoloader has already been loaded, then return true. if ( self::$is_loaded ) { return self::$is_loaded; } + // If the main class has already been loaded, then they must be using a different autoloader. + if ( class_exists( 'WPGraphQL\GF\GF' ) ) { + return true; + } + $autoloader = dirname( __DIR__ ) . '/vendor/autoload.php'; self::$is_loaded = self::require_autoloader( $autoloader );