You are here

private function CssW3Form::parseSoapResponse in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 advagg_validator/src/Form/CssW3Form.php \Drupal\advagg_validator\Form\CssW3Form::parseSoapResponse()
  2. 8.2 advagg_validator/src/Form/CssW3Form.php \Drupal\advagg_validator\Form\CssW3Form::parseSoapResponse()
1 call to CssW3Form::parseSoapResponse()
CssW3Form::testW3C in advagg_validator/src/Form/CssW3Form.php
Given a CSS file, test to make sure it is valid CSS.

File

advagg_validator/src/Form/CssW3Form.php, line 253

Class

CssW3Form
Configure form for W3C validation of CSS files.

Namespace

Drupal\advagg_validator\Form

Code

private function parseSoapResponse($xml) {
  $doc = new DOMDocument();
  $response = [];

  // Try to load soap 1.2 XML response, and suppress warning reports if any.
  if (!@$doc
    ->loadXML($xml)) {

    // Could not load the XML document.
    return $response;
  }

  // Get the standard CDATA elements.
  $cdata = [
    'uri',
    'checkedby',
    'csslevel',
    'date',
  ];
  foreach ($cdata as $var) {
    $element = $doc
      ->getElementsByTagName($var);
    if ($element->length) {
      $response[$var] = $element
        ->item(0)->nodeValue;
    }
  }

  // Handle the element validity and get errors if not valid.
  $element = $doc
    ->getElementsByTagName('validity');
  if ($element->length && $element
    ->item(0)->nodeValue === 'true') {
    $response['validity'] = TRUE;
  }
  else {
    $response['validity'] = FALSE;
    $errors = $doc
      ->getElementsByTagName('error');
    foreach ($errors as $error) {
      $response['errors'][] = $this
        ->domExtractor($error);
    }
  }

  // Get warnings.
  $warnings = $doc
    ->getElementsByTagName('warning');
  foreach ($warnings as $warning) {
    $response['warnings'][] = $this
      ->domExtractor($warning);
  }

  // Return response array.
  return $response;
}