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