<commit_before><?php

/*  "Yks config" by <NAME>. (131)
    distributed under the terms of GNU General Public License - © 2010
    Keep an internal reference table on ROOT_PATH hash so we can use it to clear APC cache
*/

class config extends KsimpleXMLElement {
    const cache_pfx = 'config_';      // cache key prefix
    const xattr = 'file';             // derivation attribute
    private static $_cache = array(); // prevent level 0 re-instanciation

  public static function hash_key(){ return self::cache_pfx.crpt(ROOT_PATH, "yks/confighash", 10); }
  public static function load($file_path, $use_cache = YKS_CONFIG_CACHE) {

    $key    = self::cache_pfx.crpt($file_path, "yks/config", 10);
    if(!$use_cache){
        syslog(LOG_INFO, "Skipping config cache for $key,you might want to SetEnv YKS_CONFIG_CACHE true");
        return KsimpleXML::load_file($file_path, __CLASS__);
    }


    $config = YKS_CONFIG_FORCE ? false 
        : ( self::$_cache[$key] ? self::$_cache[$key] : self::$_cache[$key] = storage::fetch($key) );
    if(!$config) {
        $config = self::load($file_path, false);
        storage::store($key, $config);
        syslog(LOG_INFO, "Reloading config for $key");

        //keep hash up to date
        $hash_key = self::hash_key();
        $hash = array_filter((array)storage::fetch($hash_key)); $hash[$key] = $file_path; //infos ?
        storage::store($hash_key, $hash);
    }
    return $config;
  }

  public function to_simplexml(){
    $tmp = simplexml_load_string("<null>".$this->asXML()."</null>");
    return $tmp->{$this->getName()};  //document != documentElement
  }

  function __get($key){
    $tmp = parent::__get($key);
    

    if(!isset($tmp[self::xattr])) return $tmp;
    list($file_path, $search) = explode(" ", $tmp[self::xattr]); //!

    $file_path = paths_merge(ROOT_PATH, $file_path);
    if(! file_exists($file_path)) return $tmp;
    $ret = self::load($file_path);
    if($search) $ret = $ret->search($search, true); //autocreate

    foreach($tmp->attributes() as $k=>$v)
        if($k != self::xattr) $ret[$k] = $v; //merge args

    return $ret;
  }

}<commit_msg>Bug fix in config parsing<commit_after><?php

/*  "Yks config" by <NAME>. (131)
    distributed under the terms of GNU General Public License - © 2010
    Keep an internal reference table on ROOT_PATH hash so we can use it to clear APC cache
*/

class config extends KsimpleXMLElement {
    const cache_pfx = 'config_';      // cache key prefix
    const xattr = 'file';             // derivation attribute
    private static $_cache = array(); // prevent level 0 re-instanciation

  public static function hash_key(){ return self::cache_pfx.crpt(ROOT_PATH, "yks/confighash", 10); }
  public static function load($file_path, $use_cache = YKS_CONFIG_CACHE) {

    $key    = self::cache_pfx.crpt($file_path, "yks/config", 10);
    if(!$use_cache){
        syslog(LOG_INFO, "Skipping config cache for $key,you might want to SetEnv YKS_CONFIG_CACHE true");
        return KsimpleXML::load_file($file_path, __CLASS__);
    }


    $config = YKS_CONFIG_FORCE ? false 
        : ( self::$_cache[$key] ? self::$_cache[$key] : self::$_cache[$key] = storage::fetch($key) );
    if(!$config) {
        $config = self::load($file_path, false);
        storage::store($key, $config);
        syslog(LOG_INFO, "Reloading config for $key");

        //keep hash up to date
        $hash_key = self::hash_key();
        $hash = array_filter((array)storage::fetch($hash_key)); $hash[$key] = $file_path; //infos ?
        storage::store($hash_key, $hash);
    }
    return $config;
  }

  public function to_simplexml(){
    $tmp = simplexml_load_string("<null>".$this->asXML()."</null>");
    return $tmp->{$this->getName()};  //document != documentElement
  }

  function __get($key){
    $tmp = parent::__get($key);
    
    if(!isset($tmp[self::xattr]))
        return $tmp;

    list($file_path, $search) = explode(" ", $tmp[self::xattr]); //!
    $file_path = paths_merge(ROOT_PATH, $file_path);
    if(! file_exists($file_path))
        return $tmp;

    $ret = self::load($file_path);
    if($search) $ret = $ret->search($search, true); //autocreate

    foreach($tmp->attributes() as $k=>$v)
        if($k != self::xattr) $ret[$k] = $v; //merge args

    $this->replace($ret, $tmp);

    return $ret;
  }

}
{'fraction_non_alphanumeric': 0.16539792387543253, 'fraction_numerical': 0.005536332179930796, 'mean_word_length': 3.34034034034034, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4698004', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1409, 'n_words': 346}