diff --git a/src/Exceptions/VendorAutoloadException.php b/src/Exceptions/VendorAutoloadException.php new file mode 100644 index 0000000..b518f7e --- /dev/null +++ b/src/Exceptions/VendorAutoloadException.php @@ -0,0 +1,6 @@ + add_submenu_page( // $ilabClassLoader = new Composer\Autoload\ClassLoader(); // $ilabLoader->unregister(); - include 'vendor/autoload.php'; + $localVendorAutoloadPath = 'vendor/autoload.php'; + $projectVendorAutoloadPath = ABSPATH . 'vendor/autoload.php'; - $dotenv = Dotenv\Dotenv::createImmutable(__DIR__); - $dotenv->load(); + if (file_exists($localVendorAutoloadPath)) { + include $localVendorAutoloadPath; + } elseif (file_exists($projectVendorAutoloadPath)) { + include $projectVendorAutoloadPath; + } else { + throw new VendorAutoloadException('Unable to find appropriate composer autoloader'); + } + + $dotEnvFile = __DIR__ . '/.env'; + + if (file_exists($dotEnvFile)) { + $dotenv = Dotenv\Dotenv::createImmutable(__DIR__); + $dotenv->load(); + } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $logger = new Logger();