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
53
public static function toXPath($selector)
22
{
23
53
if (isset(self::$compiled[$selector])) {
24
42
return self::$compiled[$selector];
25
}
26
27
// Select DOMText
28
25
if ($selector === 'text') {
29
3
return '//text()';
30
}
31
32
// Select DOMComment
33
22
if ($selector === 'comment') {
34
2
return '//comment()';
35
}
36
37
20
if (!class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) {
38
throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector 2.8+ is not installed (you can use filterXPath instead).');