Back to LanguageHelper class

Method parseXMLLanguageFile

public static array
parseXMLLanguageFile
(mixed $path)
Parse XML file for language information.
Parameters
  • string $path Path to the XML files.
Returns
  • array Array holding the found metadata as a key => value pair.
Since
  • 3.7.0
-
  • \RuntimeException

Method parseXMLLanguageFile - Source code

/**
 * Parse XML file for language information.
 *
 * @param   string  $path  Path to the XML files.
 *
 * @return  array  Array holding the found metadata as a key => value pair.
 *
 * @since   3.7.0
 * @throws  \RuntimeException
 */
public static function parseXMLLanguageFile($path)
{
    if (!is_readable($path)) {
        throw new \RuntimeException('File not found or not readable');
    }
    // Try to load the file
    $xml = simplexml_load_file($path);
    if (!$xml) {
        return;
    }
    // Check that it's a metadata file
    if ((string) $xml->getName() !== 'metafile') {
        return;
    }
    $metadata = array();
    foreach ($xml->metadata->children() as $child) {
        $metadata[$child->getName()] = (string) $child;
    }
    return $metadata;
}