<commit_before><?php
namespace LazyRecord\Command;
use LazyRecord\ConfigLoader;

class CommandUtils
{
    static $logger;

    static $loader;

    static function init_config_loader() {
        $loader = ConfigLoader::getInstance();
        $loader->loadFromSymbol();
        $loader->initForBuild();
        return static::$loader = $loader;
    }

    static function set_logger($logger) {
        static::$logger = $logger;
    }

    static function log($msg , $style = null) {
        if( static::$logger ) {
            if( $style ) {
                static::$logger->info( static::$logger->formatter->format( $msg ,'green') );
            } else {
                static::$logger->info($msg);
            }
        }
    }

    static function get_logger() {
        return static::$logger;
    }

    static function build_basedata($schemas) {
        foreach( $schemas as $schema ) {
            if( $modelClass = $schema->getModelClass() ) {
                static::log("Creating base data of $modelClass",'green');
                $schema->bootstrap( new $modelClass );
            }
        }

        $loader = ConfigLoader::getInstance();
        if( $seeds = $loader->getSeedScripts() ) {
            foreach( $seeds as $seed ) {
                $seed = str_replace('::','\\',$seed);
                static::log("Running seed script: $seed",'green');
                if( file_exists($seed) ) {
                    require $seed;
                }
                elseif( class_exists($seed,true) ) {
                    $seed::seed();
                }
            }
        }
    }

    static function find_schemas_with_arguments($arguments) {
        return \LazyRecord\Utils::getSchemaClassFromPathsOrClassNames( 
            static::$loader, $arguments , static::get_logger() );
    }

    static function schema_classes_to_objects($classes) {
        return array_map(function($class) { return new $class; },$classes);
    }

    static function print_schema_classes($classes) {
        static::log('Found schema classes');
        foreach( $classes as $class ) {
            static::$logger->info( static::$logger->formatter->format($class, 'green') , 1 );
        }
    }

    static function build_schemas_with_options($id, $options, $schemas) {
        $connectionManager = \LazyRecord\ConnectionManager::getInstance();
        $conn = $connectionManager->getConnection($id);
        $driver = $connectionManager->getQueryDriver($id);
        $builder = \LazyRecord\SqlBuilder\SqlBuilder::create($driver, array( 
            'rebuild' => $options->rebuild,
            'clean' => $options->clean,
        )); // driver

        $sqls = array();
        foreach( $schemas as $schema ) {
            $sqls[] = CommandUtils::build_schema_sql($builder,$schema,$conn);
        }
        return join("\n", $sqls );
    }

    static function build_schema_sql($builder,$schema,$conn) {
        $class = get_class($schema);
        static::log("Building SQL for " . $class,'green');

        $sqls = $builder->build($schema);
        foreach( $sqls as $sql ) {
            static::log( $sql );

            $conn->query( $sql );
            $error = $conn->errorInfo();
            if( $error[1] ) {
                $msg =  $class . ': ' . var_export( $error , true );
                static::$logger->error($msg);
            }
        }
        return "--- Schema $class \n" . join("\n",$sqls);
    }
}


<commit_msg>check bootstrap method<commit_after><?php
namespace LazyRecord\Command;
use LazyRecord\ConfigLoader;

class CommandUtils
{
    static $logger;

    static $loader;

    static function init_config_loader() {
        $loader = ConfigLoader::getInstance();
        $loader->loadFromSymbol();
        $loader->initForBuild();
        return static::$loader = $loader;
    }

    static function set_logger($logger) {
        static::$logger = $logger;
    }

    static function log($msg , $style = null) {
        if( static::$logger ) {
            if( $style ) {
                static::$logger->info( static::$logger->formatter->format( $msg ,'green') );
            } else {
                static::$logger->info($msg);
            }
        }
    }

    static function get_logger() {
        return static::$logger;
    }

    static function build_basedata($schemas) {
        foreach( $schemas as $schema ) {
            if( $modelClass = $schema->getModelClass() && method_exists($schema,'bootstrap') ) {
                static::log("Creating base data of $modelClass",'green');
                $schema->bootstrap( new $modelClass );
            }
        }

        $loader = ConfigLoader::getInstance();
        if( $seeds = $loader->getSeedScripts() ) {
            foreach( $seeds as $seed ) {
                $seed = str_replace('::','\\',$seed);
                static::log("Running seed script: $seed",'green');
                if( file_exists($seed) ) {
                    require $seed;
                }
                elseif( class_exists($seed,true) ) {
                    $seed::seed();
                }
            }
        }
    }

    static function find_schemas_with_arguments($arguments) {
        return \LazyRecord\Utils::getSchemaClassFromPathsOrClassNames( 
            static::$loader, $arguments , static::get_logger() );
    }

    static function schema_classes_to_objects($classes) {
        return array_map(function($class) { return new $class; },$classes);
    }

    static function print_schema_classes($classes) {
        static::log('Found schema classes');
        foreach( $classes as $class ) {
            static::$logger->info( static::$logger->formatter->format($class, 'green') , 1 );
        }
    }

    static function build_schemas_with_options($id, $options, $schemas) {
        $connectionManager = \LazyRecord\ConnectionManager::getInstance();
        $conn = $connectionManager->getConnection($id);
        $driver = $connectionManager->getQueryDriver($id);
        $builder = \LazyRecord\SqlBuilder\SqlBuilder::create($driver, array( 
            'rebuild' => $options->rebuild,
            'clean' => $options->clean,
        )); // driver

        $sqls = array();
        foreach( $schemas as $schema ) {
            $sqls[] = CommandUtils::build_schema_sql($builder,$schema,$conn);
        }
        return join("\n", $sqls );
    }

    static function build_schema_sql($builder,$schema,$conn) {
        $class = get_class($schema);
        static::log("Building SQL for " . $class,'green');

        $sqls = $builder->build($schema);
        foreach( $sqls as $sql ) {
            static::log( $sql );

            $conn->query( $sql );
            $error = $conn->errorInfo();
            if( $error[1] ) {
                $msg =  $class . ': ' . var_export( $error , true );
                static::$logger->error($msg);
            }
        }
        return "--- Schema $class \n" . join("\n",$sqls);
    }
}



{'fraction_non_alphanumeric': 0.1508452535760728, 'fraction_numerical': 0.0005779511631267157, 'mean_word_length': 2.0399648660518226, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '7306611', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1882, 'n_words': 365}