1
0
mirror of https://github.com/php/phd.git synced 2026-03-25 15:42:14 +01:00
Files
archived-phd/phpdotnet/phd/Reader.php
haszi 15284136ff Separate regular PhD output from error handling (#176)
- Move error handling code into a class and remove PhD message output handling from it.
- Introduce a new class to handle PhD message output.
- Make the implicit dependency on the output functionality of classes explicit.
- Update PEAR package.xml.
- Fix tests.
- Use proper variadic parameters
- Use class constants
- Use first-class callable syntax

---------

Co-authored-by: haszi <haszika80@gmail.com>
2024-11-10 17:57:05 +00:00

45 lines
1.4 KiB
PHP

<?php
namespace phpdotnet\phd;
class Reader extends \XMLReader
{
const XMLNS_XML = "http://www.w3.org/XML/1998/namespace";
const XMLNS_XLINK = "http://www.w3.org/1999/xlink";
const XMLNS_PHD = "http://www.php.net/ns/phd";
const XMLNS_DOCBOOK = "http://docbook.org/ns/docbook";
protected OutputHandler $outputHandler;
public function __construct(OutputHandler $outputHandler) {
$this->outputHandler = $outputHandler;
}
/* Get the content of a named node, or the current node. */
public function readContent(?string $node = null): string {
$retval = "";
if($this->isEmptyElement) {
return $retval;
}
if (!$node) {
// We need libxml2.6.20 to be able to read the textual content of the node without skipping over the markup too
if (\LIBXML_VERSION >= 20620) {
return self::readString();
}
$this->outputHandler->v("You are using libxml2 v%d, but v20620 or newer is preferred", \LIBXML_VERSION, VERBOSE_OLD_LIBXML);
$node = $this->name;
}
while (self::readNode($node)) {
$retval .= $this->value;
}
return $retval;
}
private function readNode(string $nodeName): bool {
return self::read() && !($this->nodeType === self::END_ELEMENT && $this->name === $nodeName);
}
}