1 | <?php |
||
19 | class XPathQuery |
||
20 | { |
||
21 | private $_query; |
||
22 | /** @var \DOMXPath */ |
||
23 | private $_xpath; |
||
24 | private $_context; |
||
25 | |||
26 | 1 | public function with(string $prefix, string $namespace) |
|
27 | { |
||
28 | 1 | $this->_xpath->registerNamespace($prefix, $namespace); |
|
29 | |||
30 | 1 | return $this; |
|
31 | } |
||
32 | |||
33 | public function query(string $query = null) |
||
40 | |||
41 | public function evaluate(string $query = null) |
||
45 | |||
46 | 1 | public function __construct(string $query, XmlElement $context) |
|
47 | { |
||
48 | 1 | $document = new \DOMDocument(); |
|
49 | 1 | $document->loadXML($context->xml(false)); |
|
50 | 1 | $this->_xpath = new \DOMXPath($document); |
|
51 | 1 | $this->with('php', 'http://php.net/xpath'); |
|
52 | |||
53 | 1 | $this->_query = $query; |
|
54 | 1 | $this->_context = $context; |
|
55 | 1 | } |
|
56 | |||
57 | /** |
||
58 | * Hack for supporting XPath outside of standard XML implementation. |
||
59 | * Why? Becuase simplexml sucks so much. |
||
60 | * DOM suck even more, and I'm better with writing one hack for xpath |
||
61 | * than with writing hack for almost everyfuckingthing™. |
||
62 | * |
||
63 | * @param $path |
||
64 | * @return false|XmlElement |
||
65 | */ |
||
66 | private function getElementFromPath($path) |
||
91 | } |
||
92 |