1
|
|
|
<?php |
2
|
|
|
/* @description Transformation Style Sheets - Revolutionising PHP templating * |
3
|
|
|
* @author Tom Butler [email protected] * |
4
|
|
|
* @copyright 2015 Tom Butler <[email protected]> | https://r.je/ * |
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License * |
6
|
|
|
* @version 1.0 */ |
7
|
|
|
namespace Transphporm\Pseudo; |
8
|
|
|
class Not implements \Transphporm\Pseudo { |
9
|
|
|
private $dataFunction; |
10
|
|
|
|
11
|
|
|
public function __construct(\Transphporm\Hook\DataFunction $dataFunction) { |
12
|
|
|
$this->dataFunction = $dataFunction; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function match($pseudo, \DomElement $element) { |
16
|
|
|
if (strpos($pseudo, 'not') === 0) { |
17
|
|
|
$valueParser = new \Transphporm\Parser\Value($this->dataFunction); |
18
|
|
|
$bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo); |
19
|
|
|
$css = explode(',', $bracketMatcher->match('(', ')')); |
20
|
|
|
$xpath = new \DomXpath($element->ownerDocument); |
21
|
|
|
return $this->notElement($css, $valueParser, $xpath, $element); |
22
|
|
|
} |
23
|
|
|
return true; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
private function notElement($css, $valueParser, $xpath, $element) { |
27
|
|
|
foreach ($css as $selector) { |
28
|
|
|
$cssToXpath = new \Transphporm\Parser\CssToXpath($selector, $valueParser); |
29
|
|
|
$xpathString = $cssToXpath->getXpath(); |
30
|
|
|
//Find all nodes matched by the expressions in the brackets :not(EXPR) |
31
|
|
|
foreach ($xpath->query($xpathString) as $matchedElement) { |
32
|
|
|
//Check to see whether this node was matched by the not query |
33
|
|
|
if ($element->isSameNode($matchedElement)) return false; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
return true; |
37
|
|
|
} |
38
|
|
|
} |