Created
May 29, 2015 06:51
-
-
Save m8rge/94da626514a30d09f4fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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