-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAbstractNodeProcessor.php
40 lines (35 loc) · 1.28 KB
/
AbstractNodeProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace Netlogix\XmlProcessor\NodeProcessor;
use Netlogix\XmlProcessor\XmlProcessor;
use Netlogix\XmlProcessor\XmlProcessorContext;
class AbstractNodeProcessor implements NodeProcessorInterface
{
public function getNodePath(): string
{
$constName = get_class($this) . '::NODE_PATH';
if (!defined($constName)) {
throw new \Exception('NODE_PATH not defined in ' . static::class);
}
return constant($constName);
}
public function getSubscribedEvents(string $nodePath, XmlProcessorContext $context): \Iterator
{
if ($this->isNode($nodePath)) {
if ($this instanceof OpenNodeProcessorInterface) {
yield 'NodeType_' . \XMLReader::ELEMENT => [$this, 'openElement'];
}
if ($this instanceof CloseNodeProcessorInterface) {
yield 'NodeType_' . \XMLReader::END_ELEMENT => [$this, 'closeElement'];
}
if ($this instanceof TextNodeProcessorInterface) {
yield 'NodeType_' . \XMLReader::TEXT => [$this, 'textElement'];
}
}
yield from [];
}
public function isNode(string $nodePath): bool
{
return XmlProcessor::checkNodePath($nodePath, $this->getNodePath());
}
}