<commit_before><?php
class Kwf_Component_Data_Root extends Kwf_Component_Data
{
    private static $_instance;
    private static $_rootComponentClass;
    private static $_showInvisible;
    private $_hasChildComponentCache;
    private $_componentsByClassCache;
    private $_componentsByDbIdCache;
    private $_generatorsForClassesCache = array();
    private $_currentPage;
    private $_pageGenerators;

    //caches fuer getComponentById
    private $_dataCache = array();
    private $_dataCacheIgnoreVisible = array();

    public function __construct($config = array())
    {
        $config = array_merge(array(
                'name' => 'Root',
                'parent' => null,
                'isPage' => false,
                'isPseudoPage' => false,
                'inherits' => true,
                'componentId' => 'root',
                'filename' => false
            ), $config
        );
        parent::__construct($config);
        $this->_inheritClasses = array();
        $this->_uniqueParentDatas = array();
    }

    /**
     * @return Kwf_Component_Data_Root
     */
    public static function getInstance()
    {
        if (is_null(self::$_instance)) {
            $c = self::getComponentClass();
            if ($c) {
                self::$_instance = new self(array('componentClass' => $c));
            } else {
                self::$_instance = false;
            }
        }
        return self::$_instance;
    }

    public static function getComponentClass()
    {
        if (is_null(self::$_rootComponentClass)) {
            if (Kwf_Config::getValue('kwc.rootComponent')) {
                self::$_rootComponentClass = Kwf_Config::getValue('kwc.rootComponent');
            } else {
                self::$_rootComponentClass = false;
            }
        }
        return self::$_rootComponentClass;
    }

    public static function setComponentClass($componentClass)
    {
        self::$_rootComponentClass = $componentClass;
        self::reset();
    }

    public static function setShowInvisible($showInvisible)
    {
        self::$_showInvisible = $showInvisible;
    }

    public static function getShowInvisible()
    {
        return self::$_showInvisible;
    }

    public static function reset($resetCache = true)
    {
        self::$_instance = null;
        Kwf_Component_Generator_Abstract::clearInstances();
        Kwf_Component_Abstract::clearModelInstances();
        Kwf_Component_Events::clearCache();
        if ($resetCache) Kwf_Component_Abstract::resetSettingsCache();
    }

    /**
     * Tries to clear all cached data objects and row objects
     *
     * Usful when processing lot of components to avoid memory issues
     */
    public function freeMemory()
    {
        foreach ($this->_dataCache as $id=>$c) {
            if (isset($this->_dataCacheIgnoreVisible[$id])) {
                unset($this->_dataCacheIgnoreVisible[$id]);
            }
            $c->_freeMemory();
        }
        foreach ($this->_dataCacheIgnoreVisible as $id=>$c) {
            $c->_freeMemory();
        }
        $this->_dataCache = array();
        $this->_dataCacheIgnoreVisible = array();

        if (isset($this->_component)) unset($this->_component);
        $this->_childComponentsCache = array();
        $this->_recursiveGeneratorsCache = array();
        if (isset($this->_languageCache)) unset($this->_languageCache);

        if (isset($this->_componentsByClassCache)) unset($this->_componentsByClassCache);
        if (isset($this->_componentsByDbIdCache)) unset($this->_componentsByDbIdCache);
        $this->_generatorsForClassesCache = array();
        //Kwf_Component_Generator_Abstract::clearInstances();
        KWf_Model_Abstract::clearAllRows();

        gc_collect_cycles();
    }

    public function __get($var)
    {
        if ($var == 'filename') {
            //hier ohne rawurlencode, ist bei tetss auf 'kwf/kwctest/...' gesetzt
            return $this->_filename;
        }
        return parent::__get($var);
    }

    /*
     * @return Kwf_Component_Data
     */
    public function getPageByUrl($url, $acceptLanguage, &$exactMatch = true)
    {
        $parsedUrl = parse_url($url);<commit_msg>this method only exists in php 5.3<commit_after><?php
class Kwf_Component_Data_Root extends Kwf_Component_Data
{
    private static $_instance;
    private static $_rootComponentClass;
    private static $_showInvisible;
    private $_hasChildComponentCache;
    private $_componentsByClassCache;
    private $_componentsByDbIdCache;
    private $_generatorsForClassesCache = array();
    private $_currentPage;
    private $_pageGenerators;

    //caches fuer getComponentById
    private $_dataCache = array();
    private $_dataCacheIgnoreVisible = array();

    public function __construct($config = array())
    {
        $config = array_merge(array(
                'name' => 'Root',
                'parent' => null,
                'isPage' => false,
                'isPseudoPage' => false,
                'inherits' => true,
                'componentId' => 'root',
                'filename' => false
            ), $config
        );
        parent::__construct($config);
        $this->_inheritClasses = array();
        $this->_uniqueParentDatas = array();
    }

    /**
     * @return Kwf_Component_Data_Root
     */
    public static function getInstance()
    {
        if (is_null(self::$_instance)) {
            $c = self::getComponentClass();
            if ($c) {
                self::$_instance = new self(array('componentClass' => $c));
            } else {
                self::$_instance = false;
            }
        }
        return self::$_instance;
    }

    public static function getComponentClass()
    {
        if (is_null(self::$_rootComponentClass)) {
            if (Kwf_Config::getValue('kwc.rootComponent')) {
                self::$_rootComponentClass = Kwf_Config::getValue('kwc.rootComponent');
            } else {
                self::$_rootComponentClass = false;
            }
        }
        return self::$_rootComponentClass;
    }

    public static function setComponentClass($componentClass)
    {
        self::$_rootComponentClass = $componentClass;
        self::reset();
    }

    public static function setShowInvisible($showInvisible)
    {
        self::$_showInvisible = $showInvisible;
    }

    public static function getShowInvisible()
    {
        return self::$_showInvisible;
    }

    public static function reset($resetCache = true)
    {
        self::$_instance = null;
        Kwf_Component_Generator_Abstract::clearInstances();
        Kwf_Component_Abstract::clearModelInstances();
        Kwf_Component_Events::clearCache();
        if ($resetCache) Kwf_Component_Abstract::resetSettingsCache();
    }

    /**
     * Tries to clear all cached data objects and row objects
     *
     * Usful when processing lot of components to avoid memory issues
     */
    public function freeMemory()
    {
        foreach ($this->_dataCache as $id=>$c) {
            if (isset($this->_dataCacheIgnoreVisible[$id])) {
                unset($this->_dataCacheIgnoreVisible[$id]);
            }
            $c->_freeMemory();
        }
        foreach ($this->_dataCacheIgnoreVisible as $id=>$c) {
            $c->_freeMemory();
        }
        $this->_dataCache = array();
        $this->_dataCacheIgnoreVisible = array();

        if (isset($this->_component)) unset($this->_component);
        $this->_childComponentsCache = array();
        $this->_recursiveGeneratorsCache = array();
        if (isset($this->_languageCache)) unset($this->_languageCache);

        if (isset($this->_componentsByClassCache)) unset($this->_componentsByClassCache);
        if (isset($this->_componentsByDbIdCache)) unset($this->_componentsByDbIdCache);
        $this->_generatorsForClassesCache = array();
        //Kwf_Component_Generator_Abstract::clearInstances();
        KWf_Model_Abstract::clearAllRows();

        if (method_exists('gc_collect_cycles')) gc_collect_cycles();
    }

    public function __get($var)
    {
        if ($var == 'filename') {
            //hier ohne rawurlencode, ist bei tetss auf 'kwf/kwctest/...' gesetzt
            return $this->_filename;
        }
        return parent::__get($var);
    }

    /*
     * @return Kwf_Component_Data
     */
    public function getPageByUrl($url, $acceptLanguage, &$exactMatch = true)
    {
        $parsedUrl = parse_url($url);
{'fraction_non_alphanumeric': 0.12173810367221632, 'fraction_numerical': 0.0002361553902467824, 'mean_word_length': 2.361111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6857632', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2249, 'n_words': 447}