You are here

protected function Dbug::varIsXmlResource in dBug for Drupal 2.0.x

Same name and namespace in other branches
  1. 8 src/Dbug.php \Drupal\dbug\Dbug::varIsXmlResource()
  2. 1.0.x src/Dbug.php \Drupal\dbug\Dbug::varIsXmlResource()

If variable is an xml resource type.

Parameters

mixed $var: The variable.

2 calls to Dbug::varIsXmlResource()
Dbug::varIsResource in src/Dbug.php
If variable is a resource type.
Dbug::varIsXml in src/Dbug.php
If variable is an xml type.

File

src/Dbug.php, line 567

Class

Dbug
Implementation of dBug for Drupal.

Namespace

Drupal\dbug

Code

protected function varIsXmlResource($var) {
  $xml_parser = xml_parser_create();
  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
  xml_set_element_handler($xml_parser, [
    &$this,
    "xmlStartElement",
  ], [
    &$this,
    "xmlEndElement",
  ]);
  xml_set_character_data_handler($xml_parser, [
    &$this,
    "xmlCharacterData",
  ]);
  xml_set_default_handler($xml_parser, [
    &$this,
    "xmlDefaultHandler",
  ]);
  $this
    ->makeTableHeader("xml", "xml document", 2);
  $this
    ->makeTdHeader("xml", "xmlRoot");

  // Attempt to open xml file.
  $bFile = !($fp = @fopen($var, "r")) ? FALSE : TRUE;

  // Read xml file.
  if ($bFile) {
    while ($data = str_replace("\n", "", fread($fp, 4096))) {
      $this
        ->xmlParse($xml_parser, $data, feof($fp));
    }
  }
  else {
    if (!is_string($var)) {
      $this->output[] = $this
        ->error("xml") . $this
        ->closeTdRow() . "</table>\n";
      return;
    }
    $data = $var;
    $this
      ->xmlParse($xml_parser, $data, 1);
  }
  $this->output[] = $this
    ->closeTdRow() . "</table>\n";
}