use Symfony\Component\CssSelector\CssSelectorConverter;
6
7
/**
8
* Class SelectorConverter
9
*
10
* @package voku\helper
11
*/
12
class SelectorConverter
13
{
14
protected static $compiled = array();
15
16
/**
17
* @param $selector
18
*
19
* @return mixed|string
20
*
21
* @throws \RuntimeException
22
*/
23
81
public static function toXPath($selector)
24
{
25
81
if (isset(self::$compiled[$selector])) {
26
61
return self::$compiled[$selector];
27
}
28
29
// Select DOMText
30
38
if ($selector === 'text') {
31
3
return '//text()';
32
}
33
34
// Select DOMComment
35
35
if ($selector === 'comment') {
36
3
return '//comment()';
37
}
38
39
33
if (strpos($selector, '//') === 0) {
40
1
return $selector;
41
}
42
43
33
if (!class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) {
44
1
throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector 2.8+ is not installed (you can use filterXPath instead).');