<commit_before><?php
/**
 * Webwork
 * Copyright (C) 2011 IceFlame.net
 *
 * Permission to use, copy, modify, and/or distribute this software for
 * any purpose with or without fee is hereby granted, provided that the
 * above copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * @package     Webwork
 * @version     0.1-dev
 * @link        http://www.iceflame.net
 * @license     ISC License (http://www.opensource.org/licenses/ISC)
 */

/**
 * Class for managing the basic core features
 *
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 */
class System {

    /**
     * All loaded settings
     * @var      array
     * @access   public
     * @static
     */
    public static $settings = array();
    
    /**
     * The database driver object
     * @var      Database_Base_Driver
     * @access   public
     * @static
     */
    public static $db;
    
    /**
     * Is the system initialized?
     * @var      bool
     * @access   private
     * @static
     */
    private static $_initialized = false;

    /**
     * Initializes the system
     * @return   void
     * @access   public
     * @static
     */
    public static function startup() {
        // At first we have to load the settings
        self::$settings = get_cached('settings', function() {
            return System::loadSettings(WW_SITE_PATH.'/settings');
        });
        
        // Make sure that the required settings are available and shut down the system otherwise
        if (!isset(self::$settings['core']) || !isset(self::$settings['database']))
            ww_error('Required settings "core" and/or "database" not found!', 'system.settings_not_available');
        
        // Now we can load our database driver
        $driver = self::$settings['database']['driver'];
        $host = self::$settings['database']['host'];
        $user = self::$settings['database']['user'];
        $password = self::$settings['database']['password'];
        $database = self::$settings['database']['database'];
        $prefix = self::$settings['database']['prefix'];
        
        self::$db = Database::loadDriver($driver, $host, $user, $password, $database, $prefix);
        
        // All systems are started now and running smoothly
        self::$_initialized = true;
    }

    /**
     * Reads all settings from the given directory, works recursively through all subdirectories
     * @param    string   $dir   The absolute path to the directory to scan
     * @return   array
     * @access   public
     * @static
     */
    public static function loadSettings($dir) {
        $settings = array();
        
        if (!is_string($dir) || !is_dir($dir))
            return;
        
        // Load all configuration files, we need no sorting
        foreach (glob($dir.'/*.php', GLOB_NOSORT) as $file)
            require_once($file);
        
        // Load configuration files from all subdirectories
        foreach (glob($dir.'/*', GLOB_ONLYDIR) as $subdir)
            array_push($settings, self::loadSettings($subdir));
        
        return $settings;
    }

    /**
     * Writes the given settings to a specified settings file
     * @param    string   $section    The name of the settings section (the file, name without '.php')
     * @param    array    $settings   The settings to write. If omitted, the current settings will be written.
     * @return   bool
     * @access   public
     * @static
     */
    public static function writeSettings($section, $settings = null) {
        if (!isset($settings))
            $settings = self::$settings[$section];
        
        $export = var_export($settings);
        $contents = "\$settings['{$section}'] = {$export};";
        
        return file_put_contents(WW_SITE_PATH.'/settings/'.$section.'.php', $contents);
    }
    
    /**
     * Loads a module controller
     * @param    string   $module      The name of the module
     * @param    string   $arguments   The arguments to use
     * @return   void
     * @access   public
     * @static
     */
    public static function loadModule($module, $arguments) {
        $argsList = explode('/', $arguments);

        $modulePath = WW_SITE_PATH.'/modules/'.$module;
        $moduleFile = $modulePath.'/controller.php';

        if (!file_exists($moduleFile))
            error(404);

        WebworkLoader::setModulePath($modulePath);
        
        include $moduleFile;
    }
    
    /**
     * Loads a module controller by given path
     * @param    string   $path   The path of the module page
     * @return   void
     * @access   public
     * @static
     */
    public static function loadModuleFromPath($path) {
        @list($module, $arguments) = explode('/', $path, 2);

        $module = str_replace('-', '_', $module);
        $module = strtolower($module);

        self::loadModule($module, $arguments);
    }
    
}
<commit_msg>Added method System::isStarted()<commit_after><?php
/**
 * Webwork
 * Copyright (C) 2011 IceFlame.net
 *
 * Permission to use, copy, modify, and/or distribute this software for
 * any purpose with or without fee is hereby granted, provided that the
 * above copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * @package     Webwork
 * @version     0.1-dev
 * @link        http://www.iceflame.net
 * @license     ISC License (http://www.opensource.org/licenses/ISC)
 */

/**
 * Class for managing the basic core features
 *
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 */
class System {

    /**
     * All loaded settings
     * @var      array
     * @access   public
     * @static
     */
    public static $settings = array();
    
    /**
     * The database driver object
     * @var      Database_Base_Driver
     * @access   public
     * @static
     */
    public static $db;
    
    /**
     * Is the system initialized?
     * @var      bool
     * @access   private
     * @static
     */
    private static $_initialized = false;

    /**
     * Initializes the system
     * @return   void
     * @access   public
     * @static
     */
    public static function startup() {
        // At first we have to load the settings
        self::$settings = get_cached('settings', function() {
            return System::loadSettings(WW_SITE_PATH.'/settings');
        });
        
        // Make sure that the required settings are available and shut down the system otherwise
        if (!isset(self::$settings['core']) || !isset(self::$settings['database']))
            ww_error('Required settings "core" and/or "database" not found!', 'system.settings_not_available');
        
        // Now we can load our database driver
        $driver = self::$settings['database']['driver'];
        $host = self::$settings['database']['host'];
        $user = self::$settings['database']['user'];
        $password = self::$settings['database']['password'];
        $database = self::$settings['database']['database'];
        $prefix = self::$settings['database']['prefix'];
        
        self::$db = Database::loadDriver($driver, $host, $user, $password, $database, $prefix);
        
        // All systems are started now and running smoothly
        self::$_initialized = true;
    }
	
    /**
     * Checks if the sytem has been started
     * @return   bool
     * @access   public
     * @static
     */
    public static function isStarted() {
        return self::$_initialized;
    }

    /**
     * Reads all settings from the given directory, works recursively through all subdirectories
     * @param    string   $dir   The absolute path to the directory to scan
     * @return   array
     * @access   public
     * @static
     */
    public static function loadSettings($dir) {
        $settings = array();
        
        if (!is_string($dir) || !is_dir($dir))
            return;
        
        // Load all configuration files, we need no sorting
        foreach (glob($dir.'/*.php', GLOB_NOSORT) as $file)
            require_once($file);
        
        // Load configuration files from all subdirectories
        foreach (glob($dir.'/*', GLOB_ONLYDIR) as $subdir)
            array_push($settings, self::loadSettings($subdir));
        
        return $settings;
    }

    /**
     * Writes the given settings to a specified settings file
     * @param    string   $section    The name of the settings section (the file, name without '.php')
     * @param    array    $settings   The settings to write. If omitted, the current settings will be written.
     * @return   bool
     * @access   public
     * @static
     */
    public static function writeSettings($section, $settings = null) {
        if (!isset($settings))
            $settings = self::$settings[$section];
        
        $export = var_export($settings);
        $contents = "\$settings['{$section}'] = {$export};";
        
        return file_put_contents(WW_SITE_PATH.'/settings/'.$section.'.php', $contents);
    }
    
    /**
     * Loads a module controller
     * @param    string   $module      The name of the module
     * @param    string   $arguments   The arguments to use
     * @return   void
     * @access   public
     * @static
     */
    public static function loadModule($module, $arguments) {
        $argsList = explode('/', $arguments);

        $modulePath = WW_SITE_PATH.'/modules/'.$module;
        $moduleFile = $modulePath.'/controller.php';

        if (!file_exists($moduleFile))
            error(404);

        WebworkLoader::setModulePath($modulePath);
        
        include $moduleFile;
    }
    
    /**
     * Loads a module controller by given path
     * @param    string   $path   The path of the module page
     * @return   void
     * @access   public
     * @static
     */
    public static function loadModuleFromPath($path) {
        @list($module, $arguments) = explode('/', $path, 2);

        $module = str_replace('-', '_', $module);
        $module = strtolower($module);

        self::loadModule($module, $arguments);
    }
    
}

{'fraction_non_alphanumeric': 0.11897658439562427, 'fraction_numerical': 0.001808154778049001, 'mean_word_length': 2.302089552238806, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2857725', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2954, 'n_words': 964}