Improve \MailSo\Base\Utils::FunctionExistsAndEnabled()

This commit is contained in:
the-djmaze 2022-03-03 10:44:15 +01:00
parent bb7d8e85a0
commit 5bb190d974
6 changed files with 23 additions and 23 deletions

View file

@ -1143,24 +1143,29 @@ abstract class Utils
return (false === $sResult) ? $sStr : $sResult;
}
public static function FunctionExistsAndEnabled($mFunctionNameOrNames) : bool
public static function FunctionsExistAndEnabled(array $aFunctionNames) : bool
{
if (\is_array($mFunctionNameOrNames))
{
foreach ($mFunctionNameOrNames as $sFunctionName)
{
if (!static::FunctionExistsAndEnabled($sFunctionName))
{
return false;
}
foreach ($aFunctionNames as $sFunctionName) {
if (!static::FunctionExistsAndEnabled($sFunctionName)) {
return false;
}
return true;
}
return true;
}
return !empty($mFunctionNameOrNames)
&& \function_exists($mFunctionNameOrNames)
&& \is_callable($mFunctionNameOrNames);
private static $disabled_functions = null;
public static function FunctionExistsAndEnabled(string $sFunctionName) : bool
{
if (null === static::$disabled_functions) {
static::$disabled_functions = \array_map('trim', \explode(',', \ini_get('disable_functions')));
}
/*
$disabled_classes = \explode(',', \ini_get('disable_classes'));
\in_array($function, $disabled_classes);
*/
return \function_exists($sFunctionName)
&& !\in_array($sFunctionName, static::$disabled_functions);
// && \is_callable($mFunctionNameOrNames);
}
public static function ClearNullBite($mValue) : string

View file

@ -547,7 +547,7 @@ class Actions
break;
case ('APCU' === $sDriver) &&
\MailSo\Base\Utils::FunctionExistsAndEnabled(array(
\MailSo\Base\Utils::FunctionsExistAndEnabled(array(
'apcu_store', 'apcu_fetch', 'apcu_delete', 'apcu_clear_cache')):
$oDriver = new \MailSo\Cache\Drivers\APCU($sKey);

View file

@ -104,7 +104,7 @@ abstract class PdoAbstract
}
// else if ('sqlite' === $sType && 'sqlite' === $sPdoType && $this->bSqliteCollate)
// {
// if (\method_exists($oPdo, 'sqliteCreateCollation') && \MailSo\Base\Utils::FunctionExistsAndEnabled('mb_strtoupper'))
// if (\method_exists($oPdo, 'sqliteCreateCollation'))
// {
// $oPdo->sqliteCreateCollation('SQLITE_NOCASE_UTF8', array($this, 'sqliteNoCaseCollationHelper'));
// $bCaseFunc = true;

View file

@ -45,7 +45,7 @@ abstract class AbstractConfig implements \JsonSerializable
$this->aData = $this->defaultValues();
$this->bUseApcCache = APP_USE_APCU_CACHE &&
\MailSo\Base\Utils::FunctionExistsAndEnabled(array('apcu_fetch', 'apcu_store'));
\MailSo\Base\Utils::FunctionsExistAndEnabled(array('apcu_fetch', 'apcu_store'));
}
protected abstract function defaultValues() : array;

View file

@ -129,7 +129,7 @@ class Property implements \JsonSerializable
}
// lower value for searching
if ($this->IsValueForLower() && \MailSo\Base\Utils::FunctionExistsAndEnabled('mb_strtolower'))
if ($this->IsValueForLower())
{
$this->ValueLower = (string) \mb_strtolower($this->Value, 'UTF-8');
}

View file

@ -1382,11 +1382,6 @@ SQLITEINITIAL;
private function specialConvertSearchValueLower(string $sSearch, string $sEscapeSign = '=') : string
{
if (!\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_strtolower'))
{
return '';
}
return '%'.\str_replace(array($sEscapeSign, '_', '%'),
array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'),
(string) \mb_strtolower($sSearch, 'UTF-8')).'%';