<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 reading and editing the configuration
 *
 * @author  <NAME> <<EMAIL>>
 */
class Settings {

    /**
     * All loaded settings
     * @var     array
     * @access  private
     * @static
     */
    private static $_settings = array();

    /**
     * Loads all settings
     * @return  void
     * @access  public
     * @static
     */
    public static function init() {
        $cache = new Cache('settings');
        if ($cache->active) {
            // load settings from cache
            self::$_settings = $cache->read();
        } else {
            // load settings from config files in settings dir
            self::$_settings = self::_loadFromDir(WW_DIR_SETTINGS);
            
            // write to cache if enabled
            $cache->store(self::$_settings);
        }
    }

    /**
     * Gets all settings of a section (as array) or the value of a specific setting
     * @param   string  $section  From this section...
     * @param   string  $setting  ... grab this setting, optional
     * @return  mixed
     * @access  public
     * @static
     */
    public static function get($section, $setting = null) {
        if (is_string($setting)) {
            return self::$_settings[$section][$setting];
        } else {
            return self::$_settings[$section];
        }
    }

    /**
     * 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
     * @return  bool
     * @access  public
     * @static
     */
    public static function write($section, $settings) {<commit_msg>Class Settings: Method get() can now be used to retrieve all settings<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 reading and editing the configuration
 *
 * @author  <NAME> <<EMAIL>>
 */
class Settings {

    /**
     * All loaded settings
     * @var     array
     * @access  private
     * @static
     */
    private static $_settings = array();

    /**
     * Loads all settings
     * @return  void
     * @access  public
     * @static
     */
    public static function init() {
        $cache = new Cache('settings');
        if ($cache->active) {
            // load settings from cache
            self::$_settings = $cache->read();
        } else {
            // load settings from config files in settings dir
            self::$_settings = self::_loadFromDir(WW_DIR_SETTINGS);
            
            // write to cache if enabled
            $cache->store(self::$_settings);
        }
    }

    /**
     * Gets all settings, the settings of a section (as array) or the value of a specific setting
     * @param   string  $section  Get setting(s) from this section. Optional.
     * @param   string  $setting  Get this setting from the given section. Optional.
     * @return  mixed
     * @access  public
     * @static
     */
    public static function get($section = null, $setting = null) {
        if (isset($section) && isset($setting)) {
            return self::$_settings[$section][$setting];
        } elseif (isset($section)) {
            return self::$_settings[$section];
        } else {
            return self::$_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
     * @return  bool
     * @access  public
     * @static
     */
    public static function write($section, $settings) {
{'fraction_non_alphanumeric': 0.09742846794639623, 'fraction_numerical': 0.0021731256791017745, 'mean_word_length': 2.343220338983051, 'pattern_counts': {'":': 0, '<': 11, '<?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': '802679', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1440, 'n_words': 580}