1 | <?php |
||
8 | class CssToXpath { |
||
9 | private $specialChars = [' ', '.', '>', '~', '#', ':', '[', ']']; |
||
10 | private $translators = []; |
||
11 | private $css; |
||
12 | private $valueParser; |
||
13 | private static $instances = []; |
||
14 | private $functionSet; |
||
15 | |||
16 | |||
17 | public function __construct(Value $valueParser, \Transphporm\FunctionSet $functionSet, $prefix = '') { |
||
18 | $hash = $this->registerInstance(); |
||
19 | $this->valueParser = $valueParser; |
||
20 | $this->functionSet = $functionSet; |
||
21 | |||
22 | $this->translators = [ |
||
23 | ' ' => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
||
24 | '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
||
25 | '>' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
||
26 | '#' => function($string) { return '[@id=\'' . $string . '\']'; }, |
||
27 | '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
||
28 | '[' => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . $string . '\', ., "' . $hash . '")' . ']'; }, |
||
29 | ']' => function() { return ''; } |
||
30 | ]; |
||
31 | } |
||
32 | |||
33 | private function registerInstance() { |
||
38 | |||
39 | private function createSelector() { |
||
45 | |||
46 | //XPath only allows registering of static functions... this is a hacky workaround for that |
||
47 | public static function processAttr($attr, $element, $hash) { |
||
61 | |||
62 | //split the css into indivudal functions |
||
63 | private function split($css) { |
||
78 | |||
79 | public function getXpath($css) { |
||
92 | |||
93 | public function getDepth($css) { |
||
96 | |||
97 | public function getPseudo($css) { |
||
102 | } |
||
103 |