From 1b94934e50f691d0caa5c983cb95a9c701248bc7 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 5 Oct 2024 11:23:28 +0200 Subject: [PATCH] Improve error handling when Composer dependencies are missing Fix https://github.com/brefphp/bref/issues/1867 --- layers/bootstrap.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/layers/bootstrap.php b/layers/bootstrap.php index 505c3171..383fc187 100644 --- a/layers/bootstrap.php +++ b/layers/bootstrap.php @@ -2,11 +2,15 @@ $appRoot = getenv('LAMBDA_TASK_ROOT'); -if (getenv('BREF_AUTOLOAD_PATH')) { - require getenv('BREF_AUTOLOAD_PATH'); -} elseif (file_exists($appRoot . '/vendor/autoload.php')) { - require $appRoot . '/vendor/autoload.php'; +$autoloadPath = $_SERVER['BREF_AUTOLOAD_PATH'] ?? null; +if (! $autoloadPath) { + $autoloadPath = $appRoot . '/vendor/autoload.php'; } +if (! file_exists($autoloadPath)) { + throw new RuntimeException('Could not find the Composer vendor directory. Did you run "composer require bref/bref"? Read https://bref.sh/docs/environment/php#custom-vendor-path if your Composer vendor directory is in a custom path.'); +} + +require $autoloadPath; $runtimeClass = getenv('RUNTIME_CLASS');