UpdateProcessor::parseXml

protected UpdateProcessor::parseXml($raw_xml)

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.

File

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

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 = array();
  foreach ($xml as $k => $v) {
    $data[$k] = (string) $v;
  }
  $data['releases'] = array();
  if (isset($xml->releases)) {
    foreach ($xml->releases->children() as $release) {
      $version = (string) $release->version;
      $data['releases'][$version] = array();
      foreach ($release->children() as $k => $v) {
        $data['releases'][$version][$k] = (string) $v;
      }
      $data['releases'][$version]['terms'] = array();
      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] = array();
          }
          $data['releases'][$version]['terms'][(string) $term->name][] = (string) $term->value;
        }
      }
    }
  }
  return $data;
}
doc_Drupal
2016-10-29 09:51:00
Comments
Leave a Comment

Please login to continue.