<commit_before><?php
/*"******************************************************************************************************
*   (c) 2015 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
********************************************************************************************************/


namespace Kajona\System\System;

use class_apc_cache;
use class_config;
use class_filesystem;

/**
 * The bootstrap cache is used by various kernel-components of the system in order to
 * cache lookups and path-resolvings.
 * There's no usecase to access this cache by other components, so leave this cache "as is" and feel happy.
 *
 * @author <EMAIL>
 * @since 5.0
 *
 * @todo make the caches configurable
 */
class BootstrapCache
{

    const CACHE_TEMPLATES = "templates.cache";
    const CACHE_FOLDERCONTENT = "foldercontent.cache";
    const CACHE_PHARCONTENT = "pharcontent.cache";
    const CACHE_LANG = "lang.cache";
    const CACHE_MODULES = "modules.cache";
    const CACHE_PHARMODULES = "pharmodules.cache";
    const CACHE_PHARSUMS = "pharsums.cache";
    const CACHE_CLASSES = "classes.cache";
    const CACHE_REFLECTION = "reflection.cache";
    const CACHE_OBJECTS = "objects.cache";


    /**
     * @var BootstrapCache
     */
    private static $objInstance = null;

    private static $arrCaches = array();
    private static $arrCacheSavesRequired = array();


    private function getCacheNames()
    {
        return array(
            self::CACHE_TEMPLATES,
            self::CACHE_FOLDERCONTENT,
            self::CACHE_PHARCONTENT,
            self::CACHE_LANG,
            self::CACHE_MODULES,
            self::CACHE_PHARMODULES,
            self::CACHE_CLASSES,
            self::CACHE_PHARSUMS,
            self::CACHE_REFLECTION,
            self::CACHE_OBJECTS
        );
    }


    /**
     * BootstrapCache constructor.
     */
    private function __construct()
    {
        foreach($this->getCacheNames() as $strOneFile) {
            self::$arrCaches[$strOneFile] = CacheManager::getInstance()->getValue(__CLASS__.$strOneFile);
        }
    }

    public function __destruct()
    {
        foreach($this->getCacheNames() as $strOneFile) {
            if(isset(self::$arrCacheSavesRequired[$strOneFile]) && class_config::getInstance()->getConfig("bootstrapcache_".$strOneFile) === true && isset(self::$arrCaches[$strOneFile])) {
                CacheManager::getInstance()->addValue(__CLASS__.$strOneFile, self::$arrCaches[$strOneFile]);
            }
        }
    }

    public static function getInstance()
    {
        if(self::$objInstance == null) {
            self::$objInstance = new BootstrapCache();
        }

        return self::$objInstance;
    }

    public function updateCache($strCacheIdentifier, array $arrContent)
    {
        self::$arrCaches[$strCacheIdentifier] = $arrContent;
        self::$arrCacheSavesRequired[$strCacheIdentifier] = true;
    }

    public function addCacheRow($strCacheIdentifier, $strKey, $strValue)
    {
        self::$arrCaches[$strCacheIdentifier][$strKey] = $strValue;
        self::$arrCacheSavesRequired[$strCacheIdentifier] = true;
    }

    public function removeCacheRow($strCacheIdentifier, $strKey)
    {
        unset(self::$arrCaches[$strCacheIdentifier][$strKey]);
        self::$arrCacheSavesRequired[$strCacheIdentifier] = true;
    }

    /**
     * @param $strCacheIdentifier
     * @param $strKey
     *
     * @return bool|mixed
     */
    public function getCacheRow($strCacheIdentifier, $strKey)
    {
        if(isset(self::$arrCaches[$strCacheIdentifier][$strKey])) {
            return self::$arrCaches[$strCacheIdentifier][$strKey];
        }
        else {
            return false;
        }
    }

    /**
     * Returns the content of a cache.
     * @param $strCacheIdentifier
     *
     * @return mixed
     */
    public function getCacheContent($strCacheIdentifier)
    {
        if(isset(self::$arrCaches[$strCacheIdentifier])) {
            return self::$arrCaches[$strCacheIdentifier];
        }
        else {
            return false;
        }
    }


    public function flushCache()
    {
        CacheManager::getInstance()->flushCache();
        self::$arrCaches = array();
    }
}

<commit_msg>UPDATE: module_system | BootstrapCache.php > require cache manager since autoloading is not available at this stage<commit_after><?php
/*"******************************************************************************************************
*   (c) 2015 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
********************************************************************************************************/


namespace Kajona\System\System;

use class_apc_cache;
use class_config;
use class_filesystem;

/**
 * The bootstrap cache is used by various kernel-components of the system in order to
 * cache lookups and path-resolvings.
 * There's no usecase to access this cache by other components, so leave this cache "as is" and feel happy.
 *
 * @author <EMAIL>
 * @since 5.0
 *
 * @todo make the caches configurable
 */
class BootstrapCache
{

    const CACHE_TEMPLATES = "templates.cache";
    const CACHE_FOLDERCONTENT = "foldercontent.cache";
    const CACHE_PHARCONTENT = "pharcontent.cache";
    const CACHE_LANG = "lang.cache";
    const CACHE_MODULES = "modules.cache";
    const CACHE_PHARMODULES = "pharmodules.cache";
    const CACHE_PHARSUMS = "pharsums.cache";
    const CACHE_CLASSES = "classes.cache";
    const CACHE_REFLECTION = "reflection.cache";
    const CACHE_OBJECTS = "objects.cache";


    /**
     * @var BootstrapCache
     */
    private static $objInstance = null;

    private static $arrCaches = array();
    private static $arrCacheSavesRequired = array();


    private function getCacheNames()
    {
        return array(
            self::CACHE_TEMPLATES,
            self::CACHE_FOLDERCONTENT,
            self::CACHE_PHARCONTENT,
            self::CACHE_LANG,
            self::CACHE_MODULES,
            self::CACHE_PHARMODULES,
            self::CACHE_CLASSES,
            self::CACHE_PHARSUMS,
            self::CACHE_REFLECTION,
            self::CACHE_OBJECTS
        );
    }


    /**
     * BootstrapCache constructor.
     */
    private function __construct()
    {
        require_once __DIR__ . "/CacheManager.php";

        foreach($this->getCacheNames() as $strOneFile) {
            self::$arrCaches[$strOneFile] = CacheManager::getInstance()->getValue(__CLASS__.$strOneFile);
        }
    }

    public function __destruct()
    {
        foreach($this->getCacheNames() as $strOneFile) {
            if(isset(self::$arrCacheSavesRequired[$strOneFile]) && class_config::getInstance()->getConfig("bootstrapcache_".$strOneFile) === true && isset(self::$arrCaches[$strOneFile])) {
                CacheManager::getInstance()->addValue(__CLASS__.$strOneFile, self::$arrCaches[$strOneFile]);
            }
        }
    }

    public static function getInstance()
    {
        if(self::$objInstance == null) {
            self::$objInstance = new BootstrapCache();
        }

        return self::$objInstance;
    }

    public function updateCache($strCacheIdentifier, array $arrContent)
    {
        self::$arrCaches[$strCacheIdentifier] = $arrContent;
        self::$arrCacheSavesRequired[$strCacheIdentifier] = true;
    }

    public function addCacheRow($strCacheIdentifier, $strKey, $strValue)
    {
        self::$arrCaches[$strCacheIdentifier][$strKey] = $strValue;
        self::$arrCacheSavesRequired[$strCacheIdentifier] = true;
    }

    public function removeCacheRow($strCacheIdentifier, $strKey)
    {
        unset(self::$arrCaches[$strCacheIdentifier][$strKey]);
        self::$arrCacheSavesRequired[$strCacheIdentifier] = true;
    }

    /**
     * @param $strCacheIdentifier
     * @param $strKey
     *
     * @return bool|mixed
     */
    public function getCacheRow($strCacheIdentifier, $strKey)
    {
        if(isset(self::$arrCaches[$strCacheIdentifier][$strKey])) {
            return self::$arrCaches[$strCacheIdentifier][$strKey];
        }
        else {
            return false;
        }
    }

    /**
     * Returns the content of a cache.
     * @param $strCacheIdentifier
     *
     * @return mixed
     */
    public function getCacheContent($strCacheIdentifier)
    {
        if(isset(self::$arrCaches[$strCacheIdentifier])) {
            return self::$arrCaches[$strCacheIdentifier];
        }
        else {
            return false;
        }
    }


    public function flushCache()
    {
        CacheManager::getInstance()->flushCache();
        self::$arrCaches = array();
    }
}


{'fraction_non_alphanumeric': 0.15699045480067378, 'fraction_numerical': 0.0017967434025828186, 'mean_word_length': 2.6756087494841108, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3939527', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2458, 'n_words': 472}