mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°7068 - Add emulation for apc_exists function (#460)
* Emulate missing apc_exists * Apply suggestions from code review Co-authored-by: Molkobain <lajarige.guillaume@free.fr> * Update core/apc-emulation.php --------- Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
This commit is contained in:
@@ -97,6 +97,28 @@ function apc_delete($key)
|
||||
return $bRet1 || $bRet2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if APCu emulation key exists
|
||||
* @param string|string[] $keys A string, or an array of strings, that contain keys.
|
||||
* @return bool|string[] Returns TRUE if the key exists, otherwise FALSE
|
||||
* Or if an array was passed to keys, then an array is returned that
|
||||
* contains all existing keys, or an empty array if none exist.
|
||||
*/
|
||||
function apc_exists($keys)
|
||||
{
|
||||
if (is_array($keys)) {
|
||||
$aExistingKeys = [];
|
||||
foreach ($keys as $sKey) {
|
||||
if (apcFile::ExistsOneFile($sKey)) {
|
||||
$aExistingKeys[] = $sKey;
|
||||
}
|
||||
}
|
||||
return $aExistingKeys;
|
||||
} else {
|
||||
return apcFile::ExistsOneFile($keys);
|
||||
}
|
||||
}
|
||||
|
||||
class apcFile
|
||||
{
|
||||
// Check only once per request
|
||||
@@ -183,6 +205,15 @@ class apcFile
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if cache key exists
|
||||
* @param $sKey
|
||||
* @return bool
|
||||
*/
|
||||
static public function ExistsOneFile($sKey) {
|
||||
return is_file(self::GetCacheFileName('-' . $sKey)) || is_file(self::GetCacheFileName($sKey));
|
||||
}
|
||||
|
||||
/** Get one cache entry content.
|
||||
* @param $sKey
|
||||
* @return bool|mixed
|
||||
|
||||
Reference in New Issue
Block a user