diff --git a/autoload.php b/autoload.php index 71a73d36..c0e7fdf6 100644 --- a/autoload.php +++ b/autoload.php @@ -21,14 +21,46 @@ class Autoload */ private static ?\Composer\Autoload\ClassLoader $composerAutoloader = null; - public static function load(string $class) + public static function load(string $class): void { if (self::$composerAutoloader === null) { - self::$composerAutoloader = require __DIR__ . '/vendor/autoload.php'; + self::$composerAutoloader = require self::getAutoloadFile(); } self::$composerAutoloader->loadClass($class); } + + private static function getAutoloadFile(): string + { + if (isset($_composer_autoload_path)) { + $possibleAutoloadPaths = [ + dirname($_composer_autoload_path) + ]; + $autoloader = basename($_composer_autoload_path); + } else { + $possibleAutoloadPaths = [ + // local dev repository + __DIR__, + // dependency + dirname(__DIR__, 3), + ]; + $autoloader = 'vendor/autoload.php'; + } + + foreach ($possibleAutoloadPaths as $possibleAutoloadPath) { + if (file_exists($possibleAutoloadPath . DIRECTORY_SEPARATOR . $autoloader)) { + return $possibleAutoloadPath . DIRECTORY_SEPARATOR . $autoloader; + } + } + + throw new \RuntimeException( + sprintf( + 'Unable to find "%s" in "%s" paths.', + $autoloader, + implode('", "', $possibleAutoloadPaths) + ) + ); + } } spl_autoload_register(__NAMESPACE__ . '\Autoload::load', true, true); diff --git a/config/bootstrap.php b/config/bootstrap.php deleted file mode 100644 index 657ba84f..00000000 --- a/config/bootstrap.php +++ /dev/null @@ -1,50 +0,0 @@ -