function UpdateProcessor::parseXml

Same name in other branches
  1. 8.9.x core/modules/update/src/UpdateProcessor.php \Drupal\update\UpdateProcessor::parseXml()
  2. 10 core/modules/update/src/UpdateProcessor.php \Drupal\update\UpdateProcessor::parseXml()
  3. 11.x core/modules/update/src/UpdateProcessor.php \Drupal\update\UpdateProcessor::parseXml()

Parses the XML of the Drupal release history info files.

Parameters

string $raw_xml: A raw XML string of available release data for a given project.

Return value

array Array of parsed data about releases for a given project, or NULL if there was an error parsing the string.

1 call to UpdateProcessor::parseXml()
UpdateProcessor::processFetchTask in core/modules/update/src/UpdateProcessor.php
Processes a task to fetch available update data for a single project.

File

core/modules/update/src/UpdateProcessor.php, line 219

Class

UpdateProcessor
Process project update information.

Namespace

Drupal\update

Code

protected function parseXml($raw_xml) {
    try {
        $xml = new \SimpleXMLElement($raw_xml);
    } catch (\Exception $e) {
        // SimpleXMLElement::__construct produces an E_WARNING error message for
        // each error found in the XML data and throws an exception if errors
        // were detected. Catch any exception and return failure (NULL).
        return NULL;
    }
    // If there is no valid project data, the XML is invalid, so return failure.
    if (!isset($xml->short_name)) {
        return NULL;
    }
    $data = [];
    foreach ($xml as $k => $v) {
        $data[$k] = (string) $v;
    }
    $data['releases'] = [];
    if (isset($xml->releases)) {
        foreach ($xml->releases
            ->children() as $release) {
            $version = (string) $release->version;
            $data['releases'][$version] = [];
            foreach ($release->children() as $k => $v) {
                $data['releases'][$version][$k] = (string) $v;
            }
            $data['releases'][$version]['terms'] = [];
            if ($release->terms) {
                foreach ($release->terms
                    ->children() as $term) {
                    if (!isset($data['releases'][$version]['terms'][(string) $term->name])) {
                        $data['releases'][$version]['terms'][(string) $term->name] = [];
                    }
                    $data['releases'][$version]['terms'][(string) $term->name][] = (string) $term->value;
                }
            }
        }
    }
    return $data;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.