1 | <?php |
||
26 | final class SaxParser |
||
27 | { |
||
28 | /** |
||
29 | * @var StreamAdapterInterface[] |
||
30 | */ |
||
31 | private $streamAdapters; |
||
32 | |||
33 | /** |
||
34 | * SaxParser constructor. |
||
35 | * |
||
36 | * @param StreamAdapterInterface[] $streamAdapters Stream adapters to register to parser. |
||
37 | */ |
||
38 | 4 | public function __construct(array $streamAdapters = array()) |
|
46 | |||
47 | /** |
||
48 | * Register stream adapter to parser. |
||
49 | * |
||
50 | * @param StreamAdapterInterface $streamAdapter Stream adapter to register. |
||
51 | * @return SaxParser $this Fluent interface. |
||
52 | */ |
||
53 | 4 | public function addStreamAdapter(StreamAdapterInterface $streamAdapter) |
|
58 | |||
59 | /** |
||
60 | * Parse XML document using provided SAX handler. |
||
61 | * |
||
62 | * @param SaxHandlerInterface $saxHandler Handler to user for parsing document. |
||
63 | * @param mixed $xmlDocument XML document source. |
||
64 | * @param callable|null $onResult Callable to execute when parsing is done. |
||
65 | */ |
||
66 | 4 | public function parse(SaxHandlerInterface $saxHandler, $xmlDocument, callable $onResult = null) |
|
71 | |||
72 | /** |
||
73 | * Convert XML document to stream source. |
||
74 | * |
||
75 | * @param mixed $xmlDocument XML document source. |
||
76 | * @return StreamInterface Converted XML document to stream. |
||
77 | * |
||
78 | * @throws \RuntimeException |
||
79 | */ |
||
80 | 4 | private function getDocumentStream($xmlDocument) |
|
94 | |||
95 | /** |
||
96 | * Default SAX parser factory. |
||
97 | * |
||
98 | * @param string $streamClass FQCN to use when converting to XML document source to stream. |
||
99 | * @return SaxParser New SAX parser instance. |
||
100 | */ |
||
101 | 2 | public static function factory($streamClass = 'GuzzleHttp\\Psr7\\Stream') |
|
109 | } |
||
110 |