<commit_before><?php
abstract class Vps_Component_Generator_Abstract
{
    protected $_class;
    protected $_settings;

    protected $_loadTableFromComponent = false;

    private $_dataCache = array();
    protected $_idSeparator;
    private $_model;

    protected function __construct($class, $settings)
    {
        $this->_class = $class;
        $this->_settings = $settings;
        $this->_init();
        Vps_Benchmark::count('generators');
    }
    
    protected function _init()
    {
    }
    
    protected function _getModel()
    {
        if (!$this->_model) {
            if (isset($this->_settings['model'])) {
                if (is_string($this->_settings['model'])) {
                    $this->_model = new $this->_settings['model']();
                } else {
                    $this->_model = $this->_settings['model'];
                }
            } else {
                if (isset($this->_settings['table'])) {
                    if (is_string($this->_settings['table'])) {
                        $table = new $this->_settings['table'];
                    } else {
                        $table = $this->_settings['table'];
                    }
                    $this->_model = new Vps_Model_Db(array('table' => $table));
                } else if ($this->_loadTableFromComponent) {
                    $this->_model = Vpc_Abstract::createModel($this->_class);
                } else {
                    throw new Vps_Exception("Can't create model");
                }
            }
        }
        return $this->_model;
    }
    
    public static function getInstance($componentClass, $key, $settings = array())
    {
        static $instances = array();
        $instanceKey = $componentClass . '_' . $key;
        if (!isset($instances[$instanceKey])) {
            if (empty($settings)) {
                $settings = Vpc_Abstract::getSetting($componentClass, 'generators');
                if (!isset($settings[$key])) {
                    throw new Vps_Exception("Generator with key '$key' for '$componentClass' not found.");
                }
                $settings = $settings[$key];
            }
            if (!isset($settings['class'])) {
                throw new Vps_Exception("No Generator-Class set: key '$key' for '$componentClass'");
            }
            if (!class_exists($settings['class'])) {
                throw new Vps_Exception("Generator-Class '{$settings['class']}' does not exist (used in '$componentClass')");
            }
            if (!is_subclass_of($settings['class'], 'Vps_Component_Generator_Abstract')) {
                throw new Vps_Exception("Generator-Class '{$settings['class']}' is not an Vps_Component_Generator_Abstract");
            }
            if (!is_array($settings['component'])) {
                $settings['component'] = array($key => $settings['component']);
            }
            $settings['generator'] = $key;
            $instances[$instanceKey] = new $settings['class']($componentClass, $settings);
        }
        return $instances[$instanceKey];
    }
    
    private static function _getGeneratorsForComponent($componentClass, $select)
    {
        if (is_array($select)) {
            $select = new Vps_Component_Select($select);
        }
        $generators = Vpc_Abstract::getSetting($componentClass, 'generators');
        $ret = array();
        foreach ($generators as $key => $generator) {
            if ($value = $select->getPart(Vps_Component_Select::WHERE_GENERATOR)) {
                if ($value != $key) {
                    continue;
                }
            }
            if (!isset($generator['class'])) {
                throw new Vps_Exception("Generator class for '$key' ($componentClass) is not set.");
            }
            if ($select->hasPart(Vps_Component_Select::WHERE_FILENAME)) {<commit_msg>generators können gelöscht werden für: - bessere benchmarks in unit-tests - speicherverbrauch zu reduzieren (buggy wg. php)<commit_after><?php
abstract class Vps_Component_Generator_Abstract
{
    protected $_class;
    protected $_settings;

    protected $_loadTableFromComponent = false;

    private $_dataCache = array();
    protected $_idSeparator;
    private $_model;

    private static $instances = array();

    protected function __construct($class, $settings)
    {
        $this->_class = $class;
        $this->_settings = $settings;
        $this->_init();
        Vps_Benchmark::count('generators', $this->_class.'-'.$settings['generator']);
    }

    protected function _init()
    {
    }
    
    protected function _getModel()
    {
        if (!$this->_model) {
            if (isset($this->_settings['model'])) {
                if (is_string($this->_settings['model'])) {
                    $this->_model = new $this->_settings['model']();
                } else {
                    $this->_model = $this->_settings['model'];
                }
            } else {
                if (isset($this->_settings['table'])) {
                    if (is_string($this->_settings['table'])) {
                        $table = new $this->_settings['table'];
                    } else {
                        $table = $this->_settings['table'];
                    }
                    $this->_model = new Vps_Model_Db(array('table' => $table));
                } else if ($this->_loadTableFromComponent) {
                    $this->_model = Vpc_Abstract::createModel($this->_class);
                } else {
                    throw new Vps_Exception("Can't create model");
                }
            }
        }
        return $this->_model;
    }

    //um den speicherverbrauch zu reduzieren
    public static function clearInstances()
    {
        self::$instances = array();
    }

    public static function getInstance($componentClass, $key, $settings = array())
    {
        $instanceKey = $componentClass . '_' . $key;
        if (!isset(self::$instances[$instanceKey])) {
            if (empty($settings)) {
                $settings = Vpc_Abstract::getSetting($componentClass, 'generators');
                if (!isset($settings[$key])) {
                    throw new Vps_Exception("Generator with key '$key' for '$componentClass' not found.");
                }
                $settings = $settings[$key];
            }
            if (!isset($settings['class'])) {
                throw new Vps_Exception("No Generator-Class set: key '$key' for '$componentClass'");
            }
            if (!class_exists($settings['class'])) {
                throw new Vps_Exception("Generator-Class '{$settings['class']}' does not exist (used in '$componentClass')");
            }
            if (!is_subclass_of($settings['class'], 'Vps_Component_Generator_Abstract')) {
                throw new Vps_Exception("Generator-Class '{$settings['class']}' is not an Vps_Component_Generator_Abstract");
            }
            if (!is_array($settings['component'])) {
                $settings['component'] = array($key => $settings['component']);
            }
            $settings['generator'] = $key;
            self::$instances[$instanceKey] = new $settings['class']($componentClass, $settings);
        }
        return self::$instances[$instanceKey];
    }
    
    private static function _getGeneratorsForComponent($componentClass, $select)
    {
        if (is_array($select)) {
            $select = new Vps_Component_Select($select);
        }
        $generators = Vpc_Abstract::getSetting($componentClass, 'generators');
        $ret = array();
        foreach ($generators as $key => $generator) {
            if ($value = $select->getPart(Vps_Component_Select::WHERE_GENERATOR)) {
                if ($value != $key) {
                    continue;
                }
            }
            if (!isset($generator['class'])) {
                throw new Vps_Exception("Generator class for '$key' ($componentClass) is not set.");
            }
            if ($select->hasPart(Vps_Component_Select::WHERE_FILENAME)) {
{'fraction_non_alphanumeric': 0.14145187398829537, 'fraction_numerical': 0.0, 'mean_word_length': 1.9496878442893868, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '2215010', 'n_tokens_mistral': 2083, 'n_tokens_neox': 2016, 'n_words': 419}