check php extensions when loading libraries

This commit is contained in:
Pekka Laiho 2020-12-10 19:51:49 +07:00
parent 167711c4f0
commit 882bbe8405
2 changed files with 26 additions and 17 deletions

View File

@ -67,7 +67,7 @@ class IO implements ILib
)); ));
// Readline support // Readline support
if (extension_loaded('readline')) {
$env->set('readline', new CoreFunc('readline', 'Read line of user input.', 0, 1, $env->set('readline', new CoreFunc('readline', 'Read line of user input.', 0, 1,
fn ($prompt = null) => readline($prompt) fn ($prompt = null) => readline($prompt)
)); ));
@ -85,3 +85,4 @@ class IO implements ILib
)); ));
} }
} }
}

View File

@ -19,17 +19,25 @@ class LispFactory
// Register core libraries // Register core libraries
(new Lib\Collections())->register($env); (new Lib\Collections())->register($env);
(new Lib\Compare())->register($env); (new Lib\Compare())->register($env);
if (extension_loaded('json')) {
(new Lib\Json())->register($env); (new Lib\Json())->register($env);
}
(new Lib\Math())->register($env); (new Lib\Math())->register($env);
if (extension_loaded('pcre')) {
(new Lib\Regex())->register($env); (new Lib\Regex())->register($env);
}
(new Lib\Strings())->register($env); (new Lib\Strings())->register($env);
(new Lib\Time())->register($env); (new Lib\Time())->register($env);
(new Lib\Types())->register($env); (new Lib\Types())->register($env);
// Register unsafe libraries if not in safe-mode // Register unsafe libraries if not in safe-mode
if (!$safemode) { if (!$safemode) {
if (extension_loaded('PDO')) {
(new Lib\Database())->register($env); (new Lib\Database())->register($env);
}
if (extension_loaded('curl')) {
(new Lib\Http())->register($env); (new Lib\Http())->register($env);
}
(new Lib\IO())->register($env); (new Lib\IO())->register($env);
} }