<commit_before><?php

/**
 * Errno Extension
 *
 * Author <NAME> <<EMAIL>>
 * Author 秋水之冰 <<EMAIL>>
 *
 * Copyright 2017 <NAME>
 * Copyright 2017 秋水之冰
 *
 * This file is part of NervSys.
 *
 * NervSys is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * NervSys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NervSys. If not, see <http://www.gnu.org/licenses/>.
 */

namespace ext;

class errno
{
    /**
     * Error file directory
     * Related to "ROOT/module/"
     * Error file should be located in "ROOT/module/$dir/filename.ini"
     *
     * @var string
     */
    public static $dir = 'error';

    //Multi-language support
    public static $lang = true;

    //Error message pool
    private static $pool = [];

    /**
     * Load error file from module
     *
     * @param string $module
     * @param string $file
     */
    public static function load(string $module, string $file): void
    {
        $path = realpath(ROOT . '/' . $module . '/' . self::$dir . '/' . $file . '.ini');

        if (false === $path) {
            debug('"' . $file . '.ini" NOT exist in "' . $module . '"!');
            return;
        }

        $error = parse_ini_file($path, false);

        if (!is_array($error) || empty($error)) {
            debug('"' . $file . '.ini" in "' . $module . '" is incorrect or empty!');
            return;
        }

        self::$pool += $error;

        unset($module, $file, $path, $error);
    }

    /**
     * Get a standard error result
     * Language pack needs to be loaded before getting an error message on multi-language support system
     *
     * @param int $code
     *
     * @return array
     */
    public static function get(int $code): array
    {
        return isset(self::$pool[$code])
            ? ['code' => $code, 'msg' => self::$lang ? gettext(self::$pool[$code]) : self::$pool[$code]]
            : ['code' => $code, 'msg' => 'Error message NOT found!'];
    }
}<commit_msg>add "errno" to errno extension<commit_after><?php

/**
 * Errno Extension
 *
 * Author <NAME> <<EMAIL>>
 * Author 秋水之冰 <<EMAIL>>
 *
 * Copyright 2017 <NAME>
 * Copyright 2017 秋水之冰
 *
 * This file is part of NervSys.
 *
 * NervSys is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * NervSys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NervSys. If not, see <http://www.gnu.org/licenses/>.
 */

namespace ext;

class errno
{
    /**
     * Error file directory
     * Related to "ROOT/module/"
     * Error file should be located in "ROOT/module/$dir/filename.ini"
     *
     * @var string
     */
    public static $dir = 'error';

    //Multi-language support
    public static $lang = true;

    //Error message pool
    private static $pool = [];

    /**
     * Load error file from module
     *
     * @param string $module
     * @param string $file
     */
    public static function load(string $module, string $file): void
    {
        $path = realpath(ROOT . '/' . $module . '/' . self::$dir . '/' . $file . '.ini');

        if (false === $path) {
            debug('"' . $file . '.ini" NOT exist in "' . $module . '"!');
            return;
        }

        $error = parse_ini_file($path, false);

        if (!is_array($error) || empty($error)) {
            debug('"' . $file . '.ini" in "' . $module . '" is incorrect or empty!');
            return;
        }

        self::$pool += $error;

        unset($module, $file, $path, $error);
    }

    /**
     * Get a standard error result
     * Language pack needs to be loaded before getting an error message on multi-language support system
     *
     * @param int $code
     * @param int $errno
     *
     * @return array
     */
    public static function get(int $code, int $errno = 0): array
    {
        return isset(self::$pool[$code])
            ? ['err' => &$errno, 'code' => &$code, 'msg' => self::$lang ? gettext(self::$pool[$code]) : self::$pool[$code]]
            : ['err' => &$errno, 'code' => &$code, 'msg' => 'Error message NOT found!'];
    }
}
{'fraction_non_alphanumeric': 0.13877551020408163, 'fraction_numerical': 0.0038775510204081634, 'mean_word_length': 2.3114864864864866, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1621357', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1423, 'n_words': 526}