<commit_before><?php

//instanceof operator geht für strings ned korrekt, von php.net gfladad
function is_instance_of($sub, $super)
{
    $sub = is_object($sub) ? get_class($sub) : (string)$sub;
    $sub = strpos($sub, '.') ? substr($sub, 0, strpos($sub, '.')) : $sub;
    $super = is_object($super) ? get_class($super) : (string)$super;
    Zend_Loader::loadClass($sub);
    Zend_Loader::loadClass($super);

    switch(true)
    {
        case $sub === $super:
        case is_subclass_of($sub, $super):
        case in_array($super, class_implements($sub)):
            return true;
        default:
            return false;
    }
}

class Kwf_Setup
{
    public static $configClass;
    public static $configSection;
    const CACHE_SETUP_VERSION = 3; //increase version if incompatible changes to generated file are made

    public static function setUp($configClass = 'Kwf_Config_Web')
    {
        error_reporting(E_ALL & ~E_STRICT);
        define('APP_PATH', getcwd());
        Kwf_Setup::$configClass = $configClass;
        if (!@include('./cache/setup'.self::CACHE_SETUP_VERSION.'.php')) {
            if (!file_exists('cache/setup'.self::CACHE_SETUP_VERSION.'.php')) {
                require_once dirname(__FILE__).'/../Kwf/Util/Setup.php';
                Kwf_Util_Setup::minimalBootstrapAndGenerateFile();
            }
            include('cache/setup'.self::CACHE_SETUP_VERSION.'.php');
        }
        if (self::getBaseUrl() === null) {
            //if server.baseUrl is not set try to auto detect it and generate config.local.ini accordingly
            //this code is not used if server.baseUrl is set to "" in vkwf
            if (php_sapi_name() == 'cli') {
                echo "Please create config.local.ini with server.domain and server.baseUrl\n";
                exit(1);
            }
            if (!isset($_SERVER['PHP_SELF'])) {
                echo "Can't detect baseUrl, PHP_SELF is not set\n";
                exit(1);
            }
            $baseUrl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
            $cfg  = "[production]\n";
            $cfg .= "server.domain = \"$_SERVER[HTTP_HOST]\"\n";
            $cfg .= "server.baseUrl = \"$baseUrl\"\n";
            $cfg .= "setupFinished = false\n";

            if (file_exists('config.local.ini') && filesize('config.local.ini')>0) {
                echo "config.local.ini already exists but server.baseUrl is not set\n";
                exit(1);
            }
            if (!is_writable('.')) {
                echo "'".getcwd()."' is not writable, can't create config.local.ini\n";<commit_msg>don't execute baseUrl check if running with vkwf<commit_after><?php

//instanceof operator geht für strings ned korrekt, von php.net gfladad
function is_instance_of($sub, $super)
{
    $sub = is_object($sub) ? get_class($sub) : (string)$sub;
    $sub = strpos($sub, '.') ? substr($sub, 0, strpos($sub, '.')) : $sub;
    $super = is_object($super) ? get_class($super) : (string)$super;
    Zend_Loader::loadClass($sub);
    Zend_Loader::loadClass($super);

    switch(true)
    {
        case $sub === $super:
        case is_subclass_of($sub, $super):
        case in_array($super, class_implements($sub)):
            return true;
        default:
            return false;
    }
}

class Kwf_Setup
{
    public static $configClass;
    public static $configSection;
    const CACHE_SETUP_VERSION = 3; //increase version if incompatible changes to generated file are made

    public static function setUp($configClass = 'Kwf_Config_Web')
    {
        error_reporting(E_ALL & ~E_STRICT);
        define('APP_PATH', getcwd());
        Kwf_Setup::$configClass = $configClass;
        if (!@include('./cache/setup'.self::CACHE_SETUP_VERSION.'.php')) {
            if (!file_exists('cache/setup'.self::CACHE_SETUP_VERSION.'.php')) {
                require_once dirname(__FILE__).'/../Kwf/Util/Setup.php';
                Kwf_Util_Setup::minimalBootstrapAndGenerateFile();
            }
            include('cache/setup'.self::CACHE_SETUP_VERSION.'.php');
        }
        if (defined('VKWF_PATH') && self::getBaseUrl() === null) {
            //if server.baseUrl is not set try to auto detect it and generate config.local.ini accordingly
            //this code is not used if server.baseUrl is set to "" in vkwf
            if (php_sapi_name() == 'cli') {
                echo "Please create config.local.ini with server.domain and server.baseUrl\n";
                exit(1);
            }
            if (!isset($_SERVER['PHP_SELF'])) {
                echo "Can't detect baseUrl, PHP_SELF is not set\n";
                exit(1);
            }
            $baseUrl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
            $cfg  = "[production]\n";
            $cfg .= "server.domain = \"$_SERVER[HTTP_HOST]\"\n";
            $cfg .= "server.baseUrl = \"$baseUrl\"\n";
            $cfg .= "setupFinished = false\n";

            if (file_exists('config.local.ini') && filesize('config.local.ini')>0) {
                echo "config.local.ini already exists but server.baseUrl is not set\n";
                exit(1);
            }
            if (!is_writable('.')) {
                echo "'".getcwd()."' is not writable, can't create config.local.ini\n";
{'fraction_non_alphanumeric': 0.15072627806074326, 'fraction_numerical': 0.0026410111299754765, 'mean_word_length': 2.285006195786865, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5579469', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1602, 'n_words': 357}