Skip to content

Instantly share code, notes, and snippets.

@m8rge
Created May 29, 2015 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m8rge/94da626514a30d09f4fc to your computer and use it in GitHub Desktop.
Save m8rge/94da626514a30d09f4fc to your computer and use it in GitHub Desktop.
<?php
namespace console\components;
class XMLReader extends \XMLReader
{
/**
* @param string $nodeName
* @return $this
*/
public function readUntil($nodeName)
{
while (!($this->nodeType == XMLReader::ELEMENT && $this->name == $nodeName) && $this->read()) {
}
return $this;
}
/**
* @param string $nodeName
* @param callable $callback
* @return $this
*/
public function readAll($nodeName, $callback)
{
$this->read();
do {
if ($this->nodeType == XMLReader::ELEMENT && $this->name == $nodeName) {
call_user_func($callback);
}
} while ($this->next($nodeName));
return $this;
}
/**
* @inheritdoc
*/
public function open($URI, $encoding = null, $options = null)
{
if (is_null($options)) {
$options = LIBXML_NONET | LIBXML_NOBLANKS | LIBXML_NOERROR | LIBXML_NOWARNING;
}
return parent::open($URI, $encoding, $options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment