Back to LanguageHelper class

Method parseIniFile

public static array
parseIniFile
(mixed $fileName, mixed $debug = false)
Parse strings from a language file.
Parameters
  • string $fileName The language ini file path.
  • bool $debug If set to true debug language ini file.
Returns
  • array The strings parsed.
Since
  • 3.9.0

Method parseIniFile - Source code

/**
 * Parse strings from a language file.
 *
 * @param   string   $fileName  The language ini file path.
 * @param   boolean  $debug     If set to true debug language ini file.
 *
 * @return  array  The strings parsed.
 *
 * @since   3.9.0
 */
public static function parseIniFile($fileName, $debug = false)
{
    // Check if file exists.
    if (!is_file($fileName)) {
        return array();
    }
    // Capture hidden PHP errors from the parsing.
    if ($debug === true) {
        // See https://www.php.net/manual/en/reserved.variables.phperrormsg.php
        $php_errormsg = null;
        $trackErrors = ini_get('track_errors');
        ini_set('track_errors', true);
    }
    // This was required for https://github.com/joomla/joomla-cms/issues/17198 but not sure what server setup
    // issue it is solving
    $disabledFunctions = explode(',', ini_get('disable_functions'));
    $isParseIniFileDisabled = \in_array('parse_ini_file', array_map('trim', $disabledFunctions));
    if (!\function_exists('parse_ini_file') || $isParseIniFileDisabled) {
        $contents = file_get_contents($fileName);
        $strings = @parse_ini_string($contents);
    } else {
        $strings = @parse_ini_file($fileName);
    }
    // Restore error tracking to what it was before.
    if ($debug === true) {
        ini_set('track_errors', $trackErrors);
    }
    return \is_array($strings) ? $strings : array();
}