@@ -63,6 +63,9 @@ discard block |
||
| 63 | 63 | return $array; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | + /** |
|
| 67 | + * @param \DOMElement $element |
|
| 68 | + */ |
|
| 66 | 69 | private function callFunc($name, $params, $element) { |
| 67 | 70 | if ($name && is_callable([$this->dataFunction, $name])) { |
| 68 | 71 | return $this->dataFunction->$name($this->parse($params, $element), $element); |
@@ -70,6 +73,10 @@ discard block |
||
| 70 | 73 | return false; |
| 71 | 74 | } |
| 72 | 75 | |
| 76 | + /** |
|
| 77 | + * @param string $remaining |
|
| 78 | + * @param \DOMElement $element |
|
| 79 | + */ |
|
| 73 | 80 | private function parseNextValue($remaining, $result, $element) { |
| 74 | 81 | if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
| 75 | 82 | return $result; |
@@ -12,14 +12,14 @@ |
||
| 12 | 12 | private $depth; |
| 13 | 13 | |
| 14 | 14 | public function __construct($css, Value $valueParser, $prefix = '') { |
| 15 | - $this->css = str_replace([' >', '> '],['>', '>'], trim($css)); |
|
| 15 | + $this->css = str_replace([' >', '> '], ['>', '>'], trim($css)); |
|
| 16 | 16 | $this->translators = [ |
| 17 | - ' ' => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
| 18 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 19 | - '>' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 20 | - '#' => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
| 21 | - '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
| 22 | - '[' => function($string, $xpath) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . $string . '\', .)' . ']'; }, |
|
| 17 | + ' ' => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
| 18 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 19 | + '>' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 20 | + '#' => function($string) { return '[@id=\''.$string.'\']'; }, |
|
| 21 | + '.' => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
| 22 | + '[' => function($string, $xpath) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.$string.'\', .)'.']'; }, |
|
| 23 | 23 | ']' => function() { return ''; } |
| 24 | 24 | ]; |
| 25 | 25 | } |
@@ -43,8 +43,11 @@ discard block |
||
| 43 | 43 | return $valueParser->parse($val, $element[0])[0]; |
| 44 | 44 | }, $parts); |
| 45 | 45 | |
| 46 | - if ($comparator == '=') return $element[0]->getAttribute($parts[0]) == $parts[1]; |
|
| 47 | - else if ($comparator == '!=') return $element[0]->getAttribute($parts[0]) != $parts[1]; |
|
| 46 | + if ($comparator == '=') { |
|
| 47 | + return $element[0]->getAttribute($parts[0]) == $parts[1]; |
|
| 48 | + } else if ($comparator == '!=') { |
|
| 49 | + return $element[0]->getAttribute($parts[0]) != $parts[1]; |
|
| 50 | + } |
|
| 48 | 51 | } |
| 49 | 52 | } |
| 50 | 53 | return $attr; |
@@ -61,8 +64,9 @@ discard block |
||
| 61 | 64 | $selector = $this->createSelector(); |
| 62 | 65 | $selector->type = $css[$i]; |
| 63 | 66 | $selectors[] = $selector; |
| 67 | + } else { |
|
| 68 | + $selector->string .= $css[$i]; |
|
| 64 | 69 | } |
| 65 | - else $selector->string .= $css[$i]; |
|
| 66 | 70 | } |
| 67 | 71 | return $selectors; |
| 68 | 72 | } |
@@ -73,7 +77,9 @@ discard block |
||
| 73 | 77 | $this->depth = count($selectors); |
| 74 | 78 | $xpath = '/'; |
| 75 | 79 | foreach ($selectors as $selector) { |
| 76 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
| 80 | + if (isset($this->translators[$selector->type])) { |
|
| 81 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
| 82 | + } |
|
| 77 | 83 | } |
| 78 | 84 | |
| 79 | 85 | $xpath = str_replace('/[', '/*[', $xpath); |