From cbf62169fe9f76d7f70da80b3481c20cb3439121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Kel=C4=8D=C3=A1k?= Date: Wed, 30 Aug 2023 20:53:19 +0200 Subject: [PATCH] Check if predis is installed via Composer --- index.php | 16 +++++++++++++--- src/functions.php | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index b0ad521..4b870bf 100644 --- a/index.php +++ b/index.php @@ -10,25 +10,35 @@ declare(strict_types=1); +use Composer\InstalledVersions; use RobiNN\Pca\Admin; use RobiNN\Pca\Config; use RobiNN\Pca\Http; use RobiNN\Pca\Template; if (PHP_VERSION_ID < 70400) { - die('PHP >= 7.4 is required.
Currently installed version is: '.PHP_VERSION); + die('PHP >= 7.4 is required.
The current version of php is: '.PHP_VERSION); } -// always display errors +// Always display errors ini_set('display_errors', 'On'); ini_set('display_startup_errors', 'On'); error_reporting(E_ALL); +$path = __DIR__.'/'; + if (is_file(__DIR__.'/vendor/autoload.php')) { require_once __DIR__.'/vendor/autoload.php'; + + if (!extension_loaded('redis') && + InstalledVersions::isInstalled('predis/predis') === false && + is_file($path.'predis.phar') + ) { + require_once 'phar://'.$path.'predis.phar/vendor/autoload.php'; + } } else { require_once __DIR__.'/src/functions.php'; - autoload(__DIR__.'/'); + autoload($path); } if (is_callable(Config::get('auth'))) { diff --git a/src/functions.php b/src/functions.php index d04b76d..54f434b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -80,7 +80,6 @@ function autoload(string $path): void { spl_autoload_register(static function (string $class_name) use ($path): void { $class_name = str_replace("RobiNN\\Pca\\", '', $class_name); $filename = str_replace("\\", DIRECTORY_SEPARATOR, $class_name); - $fullpath = $path.'src/'.$filename.'.php'; if (is_file($fullpath)) {