1 | <?php |
||
5 | class CssTranslator |
||
6 | { |
||
7 | const TOKEN = '/{([[:alpha:]]+)(\d+)}/i'; |
||
8 | const MAP = [ |
||
9 | // Empty part of #id and .class |
||
10 | [ '(?<=^|\s) # The begining or an empty space. |
||
11 | (?=[.#\[]) # . | # | [', |
||
12 | '*', |
||
13 | 'TAG', |
||
14 | false ], |
||
15 | // #id |
||
16 | [ '\# |
||
17 | ([\w\-]+)', |
||
18 | '[@id="\1"]', |
||
19 | 'ID', |
||
20 | false ], |
||
21 | // .class |
||
22 | [ '\. |
||
23 | ([\w\-]+)', |
||
24 | '[ contains( concat(" ", normalize-space(@class), " "), concat(" ", "\1", " ") ) ]', |
||
25 | 'CLASS', |
||
26 | false ], |
||
27 | // [attr] |
||
28 | [ '\[ |
||
29 | ([\w\-]+) |
||
30 | \]', |
||
31 | '[@\1]', |
||
32 | 'ATTR', |
||
33 | false ], |
||
34 | // [attr="val"] |
||
35 | [ '\[ |
||
36 | ([\w\-]+) |
||
37 | =["\'] |
||
38 | (.*) |
||
39 | ["\'] |
||
40 | \]', |
||
41 | '[@\1="\2"]', |
||
42 | 'ATTR', |
||
43 | false ], |
||
44 | // ns|A |
||
45 | [ '([\w\-]+) |
||
46 | \| |
||
47 | (?=\w) # A namespace must be followed at least by a character.', |
||
48 | '\1:', |
||
49 | 'NS', |
||
50 | false ], |
||
51 | // :root |
||
52 | [ ':root\b', |
||
53 | '/*', |
||
54 | 'TAG', |
||
55 | false ], |
||
56 | // A |
||
57 | [ '(?<=^|\s|\}) |
||
58 | ( [\w\-]+ | \* )', |
||
59 | '\1', |
||
60 | 'TAG', |
||
61 | false ], |
||
62 | // Aggregates the components of a tag in an expression. |
||
63 | [ '({NS\d+})? |
||
64 | ({TAG\d+}) |
||
65 | ((?:{ATTR\d+})*|) |
||
66 | ((?:{ID\d+})*|) |
||
67 | ((?:{CLASS\d+})*|)', |
||
68 | '\1\2\3\4\5', |
||
69 | 'EXP', |
||
70 | false ], |
||
71 | [ '({EXP\d+}) |
||
72 | :first-child', |
||
73 | '*[1]/self::\1', |
||
74 | 'EXP', |
||
75 | false ], |
||
76 | // {} + {} |
||
77 | [ '({EXP\d+}) |
||
78 | \s* \+ \s* |
||
79 | ({EXP\d+})', |
||
80 | '\1/following-sibling::*[1]/self::\2', |
||
81 | 'EXP', |
||
82 | true ], |
||
83 | // {} ~ {} |
||
84 | [ '({EXP\d+}) |
||
85 | \s* \~ \s* |
||
86 | ({EXP\d+})', |
||
87 | '\1/following-sibling::*/self::\2', |
||
88 | 'EXP', |
||
89 | true ], |
||
90 | // {} > {} |
||
91 | [ '({EXP\d+}) |
||
92 | \s* > \s* |
||
93 | ({EXP\d+})', |
||
94 | '\1/\2', |
||
95 | 'EXP', |
||
96 | true ], |
||
97 | // {} {} |
||
98 | [ '({EXP\d+}) |
||
99 | \s+ |
||
100 | ({EXP\d+})', |
||
101 | '\1//\2', |
||
102 | 'EXP', |
||
103 | true ], |
||
104 | // {}, {} |
||
105 | [ '({EXP\d+}) |
||
106 | \s* , \s* |
||
107 | ({EXP\d+})', |
||
108 | '\1|\2', |
||
109 | 'EXP', |
||
110 | true ] |
||
111 | ]; |
||
112 | |||
113 | public static function xpath($css) |
||
140 | |||
141 | protected static function tokenize($search, $replace, $id, &$xpath, &$stack, &$index) |
||
173 | |||
174 | protected static function translateStack(&$stack, &$xpath) |
||
194 | } |
||
195 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.