* conditionally include vendor autoload & dot-env file if exists

This commit is contained in:
2022-07-10 14:35:37 +03:00
parent 4031ac49ae
commit 136b630994
2 changed files with 23 additions and 3 deletions

View File

@ -0,0 +1,6 @@
<?php namespace WpsMcloud\Exceptions;
class VendorAutoloadException extends WpstudioMediaCloudTransformException
{
}

View File

@ -13,6 +13,7 @@
*/
use WpsMcloud\Actions;
use WpsMcloud\Exceptions\VendorAutoloadException;
use WpsMcloud\Pages;
use WpsMcloud\Logger;
@ -30,10 +31,23 @@ add_action('admin_menu', fn () => 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();