@@ -7,27 +7,27 @@ |
||
7 | 7 | */ |
8 | 8 | abstract class CaseScanner extends BlockScanner |
9 | 9 | { |
10 | - /** |
|
11 | - * @return object |
|
12 | - */ |
|
13 | - protected function scanCase() |
|
14 | - { |
|
15 | - return $this->scan('/^case +([^\n]+)/', 'case'); |
|
16 | - } |
|
10 | + /** |
|
11 | + * @return object |
|
12 | + */ |
|
13 | + protected function scanCase() |
|
14 | + { |
|
15 | + return $this->scan('/^case +([^\n]+)/', 'case'); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return object |
|
20 | - */ |
|
21 | - protected function scanWhen() |
|
22 | - { |
|
23 | - return $this->scan('/^when +((::|[^\n:]+)+)/', 'when'); |
|
24 | - } |
|
18 | + /** |
|
19 | + * @return object |
|
20 | + */ |
|
21 | + protected function scanWhen() |
|
22 | + { |
|
23 | + return $this->scan('/^when +((::|[^\n:]+)+)/', 'when'); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return object |
|
28 | - */ |
|
29 | - protected function scanDefault() |
|
30 | - { |
|
31 | - return $this->scan('/^default */', 'default'); |
|
32 | - } |
|
26 | + /** |
|
27 | + * @return object |
|
28 | + */ |
|
29 | + protected function scanDefault() |
|
30 | + { |
|
31 | + return $this->scan('/^default */', 'default'); |
|
32 | + } |
|
33 | 33 | } |
@@ -7,36 +7,36 @@ |
||
7 | 7 | */ |
8 | 8 | class StringAttribute |
9 | 9 | { |
10 | - protected $char; |
|
10 | + protected $char; |
|
11 | 11 | |
12 | - public function __construct($char) |
|
13 | - { |
|
14 | - $this->char = $char; |
|
15 | - } |
|
12 | + public function __construct($char) |
|
13 | + { |
|
14 | + $this->char = $char; |
|
15 | + } |
|
16 | 16 | |
17 | - public function parse(AttributesState $states, &$val, &$quote) |
|
18 | - { |
|
19 | - switch ($states->current()) { |
|
20 | - case 'key': |
|
21 | - $states->push('key char'); |
|
22 | - break; |
|
17 | + public function parse(AttributesState $states, &$val, &$quote) |
|
18 | + { |
|
19 | + switch ($states->current()) { |
|
20 | + case 'key': |
|
21 | + $states->push('key char'); |
|
22 | + break; |
|
23 | 23 | |
24 | - case 'key char': |
|
25 | - $states->pop(); |
|
26 | - break; |
|
24 | + case 'key char': |
|
25 | + $states->pop(); |
|
26 | + break; |
|
27 | 27 | |
28 | - case 'string': |
|
29 | - if ($this->char === $quote) { |
|
30 | - $states->pop(); |
|
31 | - } |
|
32 | - $val .= $this->char; |
|
33 | - break; |
|
28 | + case 'string': |
|
29 | + if ($this->char === $quote) { |
|
30 | + $states->pop(); |
|
31 | + } |
|
32 | + $val .= $this->char; |
|
33 | + break; |
|
34 | 34 | |
35 | - default: |
|
36 | - $states->push('string'); |
|
37 | - $val .= $this->char; |
|
38 | - $quote = $this->char; |
|
39 | - break; |
|
40 | - } |
|
41 | - } |
|
35 | + default: |
|
36 | + $states->push('string'); |
|
37 | + $val .= $this->char; |
|
38 | + $quote = $this->char; |
|
39 | + break; |
|
40 | + } |
|
41 | + } |
|
42 | 42 | } |
@@ -7,69 +7,69 @@ |
||
7 | 7 | */ |
8 | 8 | abstract class BlockScanner extends IndentScanner |
9 | 9 | { |
10 | - /** |
|
11 | - * @return object |
|
12 | - */ |
|
13 | - protected function scanExtends() |
|
14 | - { |
|
15 | - return $this->scan('/^extends? +([^\n]+)/', 'extends'); |
|
16 | - } |
|
10 | + /** |
|
11 | + * @return object |
|
12 | + */ |
|
13 | + protected function scanExtends() |
|
14 | + { |
|
15 | + return $this->scan('/^extends? +([^\n]+)/', 'extends'); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return object |
|
20 | - */ |
|
21 | - protected function scanPrepend() |
|
22 | - { |
|
23 | - if (preg_match('/^prepend +([^\n]+)/', $this->input, $matches)) { |
|
24 | - $this->consume($matches[0]); |
|
25 | - $token = $this->token('block', $matches[1]); |
|
26 | - $token->mode = 'prepend'; |
|
18 | + /** |
|
19 | + * @return object |
|
20 | + */ |
|
21 | + protected function scanPrepend() |
|
22 | + { |
|
23 | + if (preg_match('/^prepend +([^\n]+)/', $this->input, $matches)) { |
|
24 | + $this->consume($matches[0]); |
|
25 | + $token = $this->token('block', $matches[1]); |
|
26 | + $token->mode = 'prepend'; |
|
27 | 27 | |
28 | - return $token; |
|
29 | - } |
|
30 | - } |
|
28 | + return $token; |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return object |
|
34 | - */ |
|
35 | - protected function scanAppend() |
|
36 | - { |
|
37 | - if (preg_match('/^append +([^\n]+)/', $this->input, $matches)) { |
|
38 | - $this->consume($matches[0]); |
|
39 | - $token = $this->token('block', $matches[1]); |
|
40 | - $token->mode = 'append'; |
|
32 | + /** |
|
33 | + * @return object |
|
34 | + */ |
|
35 | + protected function scanAppend() |
|
36 | + { |
|
37 | + if (preg_match('/^append +([^\n]+)/', $this->input, $matches)) { |
|
38 | + $this->consume($matches[0]); |
|
39 | + $token = $this->token('block', $matches[1]); |
|
40 | + $token->mode = 'append'; |
|
41 | 41 | |
42 | - return $token; |
|
43 | - } |
|
44 | - } |
|
42 | + return $token; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return object |
|
48 | - */ |
|
49 | - protected function scanBlock() |
|
50 | - { |
|
51 | - if (preg_match("/^block\b *(?:(prepend|append) +)?([^\n]*)/", $this->input, $matches)) { |
|
52 | - $this->consume($matches[0]); |
|
53 | - $token = $this->token('block', $matches[2]); |
|
54 | - $token->mode = strlen($matches[1]) === 0 ? 'replace' : $matches[1]; |
|
46 | + /** |
|
47 | + * @return object |
|
48 | + */ |
|
49 | + protected function scanBlock() |
|
50 | + { |
|
51 | + if (preg_match("/^block\b *(?:(prepend|append) +)?([^\n]*)/", $this->input, $matches)) { |
|
52 | + $this->consume($matches[0]); |
|
53 | + $token = $this->token('block', $matches[2]); |
|
54 | + $token->mode = strlen($matches[1]) === 0 ? 'replace' : $matches[1]; |
|
55 | 55 | |
56 | - return $token; |
|
57 | - } |
|
58 | - } |
|
56 | + return $token; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return object |
|
62 | - */ |
|
63 | - protected function scanYield() |
|
64 | - { |
|
65 | - return $this->scan('/^yield */', 'yield'); |
|
66 | - } |
|
60 | + /** |
|
61 | + * @return object |
|
62 | + */ |
|
63 | + protected function scanYield() |
|
64 | + { |
|
65 | + return $this->scan('/^yield */', 'yield'); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return object |
|
70 | - */ |
|
71 | - protected function scanInclude() |
|
72 | - { |
|
73 | - return $this->scan('/^include +([^\n]+)/', 'include'); |
|
74 | - } |
|
68 | + /** |
|
69 | + * @return object |
|
70 | + */ |
|
71 | + protected function scanInclude() |
|
72 | + { |
|
73 | + return $this->scan('/^include +([^\n]+)/', 'include'); |
|
74 | + } |
|
75 | 75 | } |
@@ -9,191 +9,191 @@ |
||
9 | 9 | */ |
10 | 10 | class Attributes |
11 | 11 | { |
12 | - protected $token; |
|
13 | - |
|
14 | - public function __construct($token = null) |
|
15 | - { |
|
16 | - $this->token = $token; |
|
17 | - } |
|
18 | - |
|
19 | - protected function parseSpace($states, $escapedAttribute, &$key, &$val, $char, $previousNonBlankChar, $nextChar) |
|
20 | - { |
|
21 | - if ( |
|
22 | - in_array($states->current(), array('expr', 'array', 'string', 'object')) || |
|
23 | - ( |
|
24 | - ($char === ' ' || $char === "\t") && |
|
25 | - ( |
|
26 | - !preg_match('/^[a-zA-Z0-9_\\x7f-\\xff"\'\\]\\)\\}]$/', $previousNonBlankChar) || |
|
27 | - !preg_match('/^[a-zA-Z0-9_]$/', $nextChar) |
|
28 | - ) |
|
29 | - ) |
|
30 | - ) { |
|
31 | - $val .= $char; |
|
32 | - |
|
33 | - return; |
|
34 | - } |
|
35 | - |
|
36 | - $states->push('key'); |
|
37 | - $val = trim($val); |
|
38 | - $key = trim($key); |
|
39 | - |
|
40 | - if (empty($key)) { |
|
41 | - return; |
|
42 | - } |
|
43 | - |
|
44 | - $key = preg_replace( |
|
45 | - array('/^[\'\"]|[\'\"]$/', '/\!/'), '', $key |
|
46 | - ); |
|
47 | - $this->token->escaped[$key] = $escapedAttribute; |
|
48 | - |
|
49 | - $this->token->attributes[$key] = ('' === $val) ? true : $this->interpolate($val); |
|
50 | - |
|
51 | - $key = ''; |
|
52 | - $val = ''; |
|
53 | - } |
|
54 | - |
|
55 | - protected function replaceInterpolationsInStrings($match) |
|
56 | - { |
|
57 | - $quote = $match[1]; |
|
58 | - |
|
59 | - return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function ($match) use ($quote) { |
|
60 | - return $quote . ' . ' . CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
61 | - '/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/', |
|
62 | - function ($match) { |
|
63 | - return CommonUtils::getGetter($match[1], $match[2]); |
|
64 | - }, |
|
65 | - $match[1] |
|
66 | - )) . ' . ' . $quote; |
|
67 | - }, $match[0])); |
|
68 | - } |
|
69 | - |
|
70 | - protected function interpolate($attr) |
|
71 | - { |
|
72 | - return preg_replace_callback('/([\'"]).*?(?<!\\\\)(?:\\\\\\\\)*\1/', array($this, 'replaceInterpolationsInStrings'), $attr); |
|
73 | - } |
|
74 | - |
|
75 | - protected function parseEqual($states, &$escapedAttribute, &$key, &$val, $char, $previousChar) |
|
76 | - { |
|
77 | - switch ($states->current()) { |
|
78 | - case 'key char': |
|
79 | - $key .= $char; |
|
80 | - break; |
|
81 | - |
|
82 | - case 'val': |
|
83 | - case 'expr': |
|
84 | - case 'array': |
|
85 | - case 'string': |
|
86 | - case 'object': |
|
87 | - $val .= $char; |
|
88 | - break; |
|
89 | - |
|
90 | - default: |
|
91 | - $escapedAttribute = '!' !== $previousChar; |
|
92 | - $states->push('val'); |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - protected function parsePairs($states, $char, &$val) |
|
97 | - { |
|
98 | - switch ($char) { |
|
99 | - case '(': |
|
100 | - $states->pushFor('expr', 'val', 'expr'); |
|
101 | - break; |
|
102 | - |
|
103 | - case ')': |
|
104 | - $states->popFor('val', 'expr'); |
|
105 | - break; |
|
106 | - |
|
107 | - case '{': |
|
108 | - $states->pushFor('object', 'val'); |
|
109 | - break; |
|
110 | - |
|
111 | - case '}': |
|
112 | - $states->popFor('object'); |
|
113 | - break; |
|
114 | - |
|
115 | - case '[': |
|
116 | - $states->pushFor('array', 'val'); |
|
117 | - break; |
|
118 | - |
|
119 | - case ']': |
|
120 | - $states->popFor('array'); |
|
121 | - break; |
|
122 | - |
|
123 | - default: |
|
124 | - return false; |
|
125 | - } |
|
126 | - $val .= $char; |
|
127 | - |
|
128 | - return true; |
|
129 | - } |
|
130 | - |
|
131 | - protected function parseString(&$states, &$key, &$val, &$quote, $char) |
|
132 | - { |
|
133 | - if (($char === '"' || $char === "'") && !CommonUtils::escapedEnd($val)) { |
|
134 | - $stringParser = new StringAttribute($char); |
|
135 | - $stringParser->parse($states, $val, $quote); |
|
136 | - |
|
137 | - return; |
|
138 | - } |
|
139 | - ${in_array($states->current(), array('key', 'key char')) ? 'key' : 'val'} .= $char; |
|
140 | - } |
|
141 | - |
|
142 | - public function parseChar($char, &$nextChar, &$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar) |
|
143 | - { |
|
144 | - if ($this->parsePairs($states, $char, $val)) { |
|
145 | - return; |
|
146 | - } |
|
147 | - |
|
148 | - switch ($char) { |
|
149 | - case ',': |
|
150 | - case "\n": |
|
151 | - case "\t": |
|
152 | - case ' ': |
|
153 | - $this->parseSpace($states, $escapedAttribute, $key, $val, $char, $previousNonBlankChar, $nextChar); |
|
154 | - break; |
|
155 | - |
|
156 | - case '=': |
|
157 | - $this->parseEqual($states, $escapedAttribute, $key, $val, $char, $previousChar); |
|
158 | - break; |
|
159 | - |
|
160 | - default: |
|
161 | - $this->parseString($states, $key, $val, $quote, $char); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - protected function getParseFunction(&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) |
|
166 | - { |
|
167 | - return function ($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
168 | - $parser->parseChar($char, $nextChar, $key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar); |
|
169 | - $previousChar = $char; |
|
170 | - if (trim($char) !== '') { |
|
171 | - $previousNonBlankChar = $char; |
|
172 | - } |
|
173 | - }; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return object |
|
178 | - */ |
|
179 | - public function parseWith($str) |
|
180 | - { |
|
181 | - $parser = $this; |
|
182 | - |
|
183 | - $key = ''; |
|
184 | - $val = ''; |
|
185 | - $quote = ''; |
|
186 | - $states = new AttributesState(); |
|
187 | - $escapedAttribute = ''; |
|
188 | - $previousChar = ''; |
|
189 | - $previousNonBlankChar = ''; |
|
190 | - |
|
191 | - $parse = $this->getParseFunction($key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar, $parser); |
|
192 | - |
|
193 | - for ($i = 0; $i < strlen($str); $i++) { |
|
194 | - $parse(substr($str, $i, 1), substr($str, $i + 1, 1)); |
|
195 | - } |
|
196 | - |
|
197 | - $parse(','); |
|
198 | - } |
|
12 | + protected $token; |
|
13 | + |
|
14 | + public function __construct($token = null) |
|
15 | + { |
|
16 | + $this->token = $token; |
|
17 | + } |
|
18 | + |
|
19 | + protected function parseSpace($states, $escapedAttribute, &$key, &$val, $char, $previousNonBlankChar, $nextChar) |
|
20 | + { |
|
21 | + if ( |
|
22 | + in_array($states->current(), array('expr', 'array', 'string', 'object')) || |
|
23 | + ( |
|
24 | + ($char === ' ' || $char === "\t") && |
|
25 | + ( |
|
26 | + !preg_match('/^[a-zA-Z0-9_\\x7f-\\xff"\'\\]\\)\\}]$/', $previousNonBlankChar) || |
|
27 | + !preg_match('/^[a-zA-Z0-9_]$/', $nextChar) |
|
28 | + ) |
|
29 | + ) |
|
30 | + ) { |
|
31 | + $val .= $char; |
|
32 | + |
|
33 | + return; |
|
34 | + } |
|
35 | + |
|
36 | + $states->push('key'); |
|
37 | + $val = trim($val); |
|
38 | + $key = trim($key); |
|
39 | + |
|
40 | + if (empty($key)) { |
|
41 | + return; |
|
42 | + } |
|
43 | + |
|
44 | + $key = preg_replace( |
|
45 | + array('/^[\'\"]|[\'\"]$/', '/\!/'), '', $key |
|
46 | + ); |
|
47 | + $this->token->escaped[$key] = $escapedAttribute; |
|
48 | + |
|
49 | + $this->token->attributes[$key] = ('' === $val) ? true : $this->interpolate($val); |
|
50 | + |
|
51 | + $key = ''; |
|
52 | + $val = ''; |
|
53 | + } |
|
54 | + |
|
55 | + protected function replaceInterpolationsInStrings($match) |
|
56 | + { |
|
57 | + $quote = $match[1]; |
|
58 | + |
|
59 | + return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function ($match) use ($quote) { |
|
60 | + return $quote . ' . ' . CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
61 | + '/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/', |
|
62 | + function ($match) { |
|
63 | + return CommonUtils::getGetter($match[1], $match[2]); |
|
64 | + }, |
|
65 | + $match[1] |
|
66 | + )) . ' . ' . $quote; |
|
67 | + }, $match[0])); |
|
68 | + } |
|
69 | + |
|
70 | + protected function interpolate($attr) |
|
71 | + { |
|
72 | + return preg_replace_callback('/([\'"]).*?(?<!\\\\)(?:\\\\\\\\)*\1/', array($this, 'replaceInterpolationsInStrings'), $attr); |
|
73 | + } |
|
74 | + |
|
75 | + protected function parseEqual($states, &$escapedAttribute, &$key, &$val, $char, $previousChar) |
|
76 | + { |
|
77 | + switch ($states->current()) { |
|
78 | + case 'key char': |
|
79 | + $key .= $char; |
|
80 | + break; |
|
81 | + |
|
82 | + case 'val': |
|
83 | + case 'expr': |
|
84 | + case 'array': |
|
85 | + case 'string': |
|
86 | + case 'object': |
|
87 | + $val .= $char; |
|
88 | + break; |
|
89 | + |
|
90 | + default: |
|
91 | + $escapedAttribute = '!' !== $previousChar; |
|
92 | + $states->push('val'); |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + protected function parsePairs($states, $char, &$val) |
|
97 | + { |
|
98 | + switch ($char) { |
|
99 | + case '(': |
|
100 | + $states->pushFor('expr', 'val', 'expr'); |
|
101 | + break; |
|
102 | + |
|
103 | + case ')': |
|
104 | + $states->popFor('val', 'expr'); |
|
105 | + break; |
|
106 | + |
|
107 | + case '{': |
|
108 | + $states->pushFor('object', 'val'); |
|
109 | + break; |
|
110 | + |
|
111 | + case '}': |
|
112 | + $states->popFor('object'); |
|
113 | + break; |
|
114 | + |
|
115 | + case '[': |
|
116 | + $states->pushFor('array', 'val'); |
|
117 | + break; |
|
118 | + |
|
119 | + case ']': |
|
120 | + $states->popFor('array'); |
|
121 | + break; |
|
122 | + |
|
123 | + default: |
|
124 | + return false; |
|
125 | + } |
|
126 | + $val .= $char; |
|
127 | + |
|
128 | + return true; |
|
129 | + } |
|
130 | + |
|
131 | + protected function parseString(&$states, &$key, &$val, &$quote, $char) |
|
132 | + { |
|
133 | + if (($char === '"' || $char === "'") && !CommonUtils::escapedEnd($val)) { |
|
134 | + $stringParser = new StringAttribute($char); |
|
135 | + $stringParser->parse($states, $val, $quote); |
|
136 | + |
|
137 | + return; |
|
138 | + } |
|
139 | + ${in_array($states->current(), array('key', 'key char')) ? 'key' : 'val'} .= $char; |
|
140 | + } |
|
141 | + |
|
142 | + public function parseChar($char, &$nextChar, &$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar) |
|
143 | + { |
|
144 | + if ($this->parsePairs($states, $char, $val)) { |
|
145 | + return; |
|
146 | + } |
|
147 | + |
|
148 | + switch ($char) { |
|
149 | + case ',': |
|
150 | + case "\n": |
|
151 | + case "\t": |
|
152 | + case ' ': |
|
153 | + $this->parseSpace($states, $escapedAttribute, $key, $val, $char, $previousNonBlankChar, $nextChar); |
|
154 | + break; |
|
155 | + |
|
156 | + case '=': |
|
157 | + $this->parseEqual($states, $escapedAttribute, $key, $val, $char, $previousChar); |
|
158 | + break; |
|
159 | + |
|
160 | + default: |
|
161 | + $this->parseString($states, $key, $val, $quote, $char); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + protected function getParseFunction(&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) |
|
166 | + { |
|
167 | + return function ($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
168 | + $parser->parseChar($char, $nextChar, $key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar); |
|
169 | + $previousChar = $char; |
|
170 | + if (trim($char) !== '') { |
|
171 | + $previousNonBlankChar = $char; |
|
172 | + } |
|
173 | + }; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return object |
|
178 | + */ |
|
179 | + public function parseWith($str) |
|
180 | + { |
|
181 | + $parser = $this; |
|
182 | + |
|
183 | + $key = ''; |
|
184 | + $val = ''; |
|
185 | + $quote = ''; |
|
186 | + $states = new AttributesState(); |
|
187 | + $escapedAttribute = ''; |
|
188 | + $previousChar = ''; |
|
189 | + $previousNonBlankChar = ''; |
|
190 | + |
|
191 | + $parse = $this->getParseFunction($key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar, $parser); |
|
192 | + |
|
193 | + for ($i = 0; $i < strlen($str); $i++) { |
|
194 | + $parse(substr($str, $i, 1), substr($str, $i + 1, 1)); |
|
195 | + } |
|
196 | + |
|
197 | + $parse(','); |
|
198 | + } |
|
199 | 199 | } |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | { |
57 | 57 | $quote = $match[1]; |
58 | 58 | |
59 | - return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function ($match) use ($quote) { |
|
60 | - return $quote . ' . ' . CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
59 | + return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function($match) use ($quote) { |
|
60 | + return $quote.' . '.CommonUtils::addDollarIfNeeded(preg_replace_callback( |
|
61 | 61 | '/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/', |
62 | - function ($match) { |
|
62 | + function($match) { |
|
63 | 63 | return CommonUtils::getGetter($match[1], $match[2]); |
64 | 64 | }, |
65 | 65 | $match[1] |
66 | - )) . ' . ' . $quote; |
|
66 | + )).' . '.$quote; |
|
67 | 67 | }, $match[0])); |
68 | 68 | } |
69 | 69 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | protected function getParseFunction(&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) |
166 | 166 | { |
167 | - return function ($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
167 | + return function($char, $nextChar = '') use (&$key, &$val, &$quote, $states, &$escapedAttribute, &$previousChar, &$previousNonBlankChar, $parser) { |
|
168 | 168 | $parser->parseChar($char, $nextChar, $key, $val, $quote, $states, $escapedAttribute, $previousChar, $previousNonBlankChar); |
169 | 169 | $previousChar = $char; |
170 | 170 | if (trim($char) !== '') { |
@@ -7,39 +7,39 @@ |
||
7 | 7 | */ |
8 | 8 | class AttributesState |
9 | 9 | { |
10 | - protected $states = array('key'); |
|
11 | - |
|
12 | - public function current() |
|
13 | - { |
|
14 | - return $this->states[count($this->states) - 1]; |
|
15 | - } |
|
16 | - |
|
17 | - protected function isIn() |
|
18 | - { |
|
19 | - return in_array($this->current(), func_get_args()); |
|
20 | - } |
|
21 | - |
|
22 | - public function pop() |
|
23 | - { |
|
24 | - array_pop($this->states); |
|
25 | - } |
|
26 | - |
|
27 | - public function push($value) |
|
28 | - { |
|
29 | - array_push($this->states, $value); |
|
30 | - } |
|
31 | - |
|
32 | - public function popFor() |
|
33 | - { |
|
34 | - if (call_user_func_array(array($this, 'isIn'), func_get_args())) { |
|
35 | - $this->pop(); |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - public function pushFor($value) |
|
40 | - { |
|
41 | - if (call_user_func_array(array($this, 'isIn'), array_slice(func_get_args(), 1))) { |
|
42 | - $this->push($value); |
|
43 | - } |
|
44 | - } |
|
10 | + protected $states = array('key'); |
|
11 | + |
|
12 | + public function current() |
|
13 | + { |
|
14 | + return $this->states[count($this->states) - 1]; |
|
15 | + } |
|
16 | + |
|
17 | + protected function isIn() |
|
18 | + { |
|
19 | + return in_array($this->current(), func_get_args()); |
|
20 | + } |
|
21 | + |
|
22 | + public function pop() |
|
23 | + { |
|
24 | + array_pop($this->states); |
|
25 | + } |
|
26 | + |
|
27 | + public function push($value) |
|
28 | + { |
|
29 | + array_push($this->states, $value); |
|
30 | + } |
|
31 | + |
|
32 | + public function popFor() |
|
33 | + { |
|
34 | + if (call_user_func_array(array($this, 'isIn'), func_get_args())) { |
|
35 | + $this->pop(); |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + public function pushFor($value) |
|
40 | + { |
|
41 | + if (call_user_func_array(array($this, 'isIn'), array_slice(func_get_args(), 1))) { |
|
42 | + $this->push($value); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
@@ -8,77 +8,77 @@ |
||
8 | 8 | */ |
9 | 9 | abstract class CompilerConfig |
10 | 10 | { |
11 | - /** |
|
12 | - * @const string |
|
13 | - */ |
|
14 | - const VARNAME = '[a-zA-Z\\\\\\x7f-\\xff][a-zA-Z0-9\\\\_\\x7f-\\xff]*'; |
|
11 | + /** |
|
12 | + * @const string |
|
13 | + */ |
|
14 | + const VARNAME = '[a-zA-Z\\\\\\x7f-\\xff][a-zA-Z0-9\\\\_\\x7f-\\xff]*'; |
|
15 | 15 | |
16 | - // This pattern matches against string constants, some php keywords, number constants and a empty string |
|
17 | - // |
|
18 | - // the pattern without php escaping: |
|
19 | - // |
|
20 | - // [ \t]*((['"])(?:\\.|[^'"\\])*\g{-1}|true|false|null|[0-9]+|\b\b)[ \t]* |
|
21 | - // |
|
22 | - // pattern explained: |
|
23 | - // |
|
24 | - // [ \t]* - we ignore spaces at the beginning and at the end: useful for the recursive pattern bellow |
|
25 | - // |
|
26 | - // the first part of the unamed subpattern matches strings: |
|
27 | - // "(?:\\.|[^"\\])*" - quoted string with " |
|
28 | - // '(?:\\.|[^'\\])*' - quoted string with ' |
|
29 | - // |
|
30 | - // the rest of the pattern: |
|
31 | - // true|false|null - language constants |
|
32 | - // 0-9 - number constants |
|
33 | - // \b\b - matches a empty string: useful for a empty array |
|
34 | - /** |
|
35 | - * @const string |
|
36 | - */ |
|
37 | - const CONSTANT_VALUE = '[ \t]*("(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\'|true|false|null|undefined|[0-9]+|\b\b)[ \t]*'; |
|
16 | + // This pattern matches against string constants, some php keywords, number constants and a empty string |
|
17 | + // |
|
18 | + // the pattern without php escaping: |
|
19 | + // |
|
20 | + // [ \t]*((['"])(?:\\.|[^'"\\])*\g{-1}|true|false|null|[0-9]+|\b\b)[ \t]* |
|
21 | + // |
|
22 | + // pattern explained: |
|
23 | + // |
|
24 | + // [ \t]* - we ignore spaces at the beginning and at the end: useful for the recursive pattern bellow |
|
25 | + // |
|
26 | + // the first part of the unamed subpattern matches strings: |
|
27 | + // "(?:\\.|[^"\\])*" - quoted string with " |
|
28 | + // '(?:\\.|[^'\\])*' - quoted string with ' |
|
29 | + // |
|
30 | + // the rest of the pattern: |
|
31 | + // true|false|null - language constants |
|
32 | + // 0-9 - number constants |
|
33 | + // \b\b - matches a empty string: useful for a empty array |
|
34 | + /** |
|
35 | + * @const string |
|
36 | + */ |
|
37 | + const CONSTANT_VALUE = '[ \t]*("(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\'|true|false|null|undefined|[0-9]+|\b\b)[ \t]*'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @const string |
|
41 | - */ |
|
42 | - const ESCAPED = 'echo \\Jade\\Compiler::getEscapedValue(%s, %s)'; |
|
39 | + /** |
|
40 | + * @const string |
|
41 | + */ |
|
42 | + const ESCAPED = 'echo \\Jade\\Compiler::getEscapedValue(%s, %s)'; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @const string |
|
46 | - */ |
|
47 | - const UNESCAPED = 'echo \\Jade\\Compiler::getUnescapedValue(%s)'; |
|
44 | + /** |
|
45 | + * @const string |
|
46 | + */ |
|
47 | + const UNESCAPED = 'echo \\Jade\\Compiler::getUnescapedValue(%s)'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - protected $doctypes = array( |
|
53 | - '5' => '<!DOCTYPE html>', |
|
54 | - 'html' => '<!DOCTYPE html>', |
|
55 | - 'default' => '<!DOCTYPE html>', |
|
56 | - 'transitional' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', |
|
57 | - 'strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', |
|
58 | - 'frameset' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', |
|
59 | - '1.1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', |
|
60 | - 'basic' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">', |
|
61 | - 'mobile' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">', |
|
62 | - 'xml' => '<<?php echo \'?xml version="1.0" encoding="utf-8" ?\'; ?>>', |
|
63 | - ); |
|
49 | + /** |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + protected $doctypes = array( |
|
53 | + '5' => '<!DOCTYPE html>', |
|
54 | + 'html' => '<!DOCTYPE html>', |
|
55 | + 'default' => '<!DOCTYPE html>', |
|
56 | + 'transitional' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', |
|
57 | + 'strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', |
|
58 | + 'frameset' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', |
|
59 | + '1.1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', |
|
60 | + 'basic' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">', |
|
61 | + 'mobile' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">', |
|
62 | + 'xml' => '<<?php echo \'?xml version="1.0" encoding="utf-8" ?\'; ?>>', |
|
63 | + ); |
|
64 | 64 | |
65 | - /** |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $selfClosing = array('meta', 'img', 'link', 'input', 'source', 'area', 'base', 'col', 'br', 'hr'); |
|
65 | + /** |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $selfClosing = array('meta', 'img', 'link', 'input', 'source', 'area', 'base', 'col', 'br', 'hr'); |
|
69 | 69 | |
70 | - /** |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - protected $phpKeywords = array('true', 'false', 'null', 'switch', 'case', 'default', 'endswitch', 'if', 'elseif', 'else', 'endif', 'while', 'endwhile', 'do', 'for', 'endfor', 'foreach', 'endforeach', 'as', 'unless'); |
|
70 | + /** |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + protected $phpKeywords = array('true', 'false', 'null', 'switch', 'case', 'default', 'endswitch', 'if', 'elseif', 'else', 'endif', 'while', 'endwhile', 'do', 'for', 'endfor', 'foreach', 'endforeach', 'as', 'unless'); |
|
74 | 74 | |
75 | - /** |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - protected $phpOpenBlock = array('switch', 'if', 'else if', 'elseif', 'else', 'while', 'do', 'foreach', 'for', 'unless'); |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + protected $phpOpenBlock = array('switch', 'if', 'else if', 'elseif', 'else', 'while', 'do', 'foreach', 'for', 'unless'); |
|
79 | 79 | |
80 | - /** |
|
81 | - * @var array |
|
82 | - */ |
|
83 | - protected $phpCloseBlock = array('endswitch', 'endif', 'endwhile', 'endfor', 'endforeach'); |
|
80 | + /** |
|
81 | + * @var array |
|
82 | + */ |
|
83 | + protected $phpCloseBlock = array('endswitch', 'endif', 'endwhile', 'endfor', 'endforeach'); |
|
84 | 84 | } |
@@ -8,55 +8,55 @@ |
||
8 | 8 | */ |
9 | 9 | abstract class Indenter extends CompilerConfig |
10 | 10 | { |
11 | - /** |
|
12 | - * @var bool |
|
13 | - */ |
|
14 | - protected $prettyprint = false; |
|
15 | - /** |
|
16 | - * @var int |
|
17 | - */ |
|
18 | - protected $indents = 0; |
|
19 | - /** |
|
20 | - * @var int |
|
21 | - */ |
|
22 | - protected $indentSize = 2; |
|
23 | - /** |
|
24 | - * @var string (chr) |
|
25 | - */ |
|
26 | - protected $indentChar = ' '; |
|
11 | + /** |
|
12 | + * @var bool |
|
13 | + */ |
|
14 | + protected $prettyprint = false; |
|
15 | + /** |
|
16 | + * @var int |
|
17 | + */ |
|
18 | + protected $indents = 0; |
|
19 | + /** |
|
20 | + * @var int |
|
21 | + */ |
|
22 | + protected $indentSize = 2; |
|
23 | + /** |
|
24 | + * @var string (chr) |
|
25 | + */ |
|
26 | + protected $indentChar = ' '; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - protected function indent() |
|
32 | - { |
|
33 | - return $this->prettyprint ? str_repeat(str_repeat($this->indentChar, $this->indentSize), $this->indents) : ''; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + protected function indent() |
|
32 | + { |
|
33 | + return $this->prettyprint ? str_repeat(str_repeat($this->indentChar, $this->indentSize), $this->indents) : ''; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function newline() |
|
40 | - { |
|
41 | - return $this->prettyprint ? "\n" : ''; |
|
42 | - } |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function newline() |
|
40 | + { |
|
41 | + return $this->prettyprint ? "\n" : ''; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Disable or enable temporary the prettyprint setting then come back |
|
46 | - * to previous setting. |
|
47 | - * |
|
48 | - * @param bool prettyprint temporary setting |
|
49 | - * @param callable action to execute with the prettyprint setting |
|
50 | - * |
|
51 | - * @return mixed |
|
52 | - */ |
|
53 | - protected function tempPrettyPrint($newSetting, $method) |
|
54 | - { |
|
55 | - $previousSetting = $this->prettyprint; |
|
56 | - $this->prettyprint = $newSetting; |
|
57 | - $result = call_user_func_array(array($this, $method), array_slice(func_get_args(), 2)); |
|
58 | - $this->prettyprint = $previousSetting; |
|
44 | + /** |
|
45 | + * Disable or enable temporary the prettyprint setting then come back |
|
46 | + * to previous setting. |
|
47 | + * |
|
48 | + * @param bool prettyprint temporary setting |
|
49 | + * @param callable action to execute with the prettyprint setting |
|
50 | + * |
|
51 | + * @return mixed |
|
52 | + */ |
|
53 | + protected function tempPrettyPrint($newSetting, $method) |
|
54 | + { |
|
55 | + $previousSetting = $this->prettyprint; |
|
56 | + $this->prettyprint = $newSetting; |
|
57 | + $result = call_user_func_array(array($this, $method), array_slice(func_get_args(), 2)); |
|
58 | + $this->prettyprint = $previousSetting; |
|
59 | 59 | |
60 | - return $result; |
|
61 | - } |
|
60 | + return $result; |
|
61 | + } |
|
62 | 62 | } |
@@ -8,61 +8,61 @@ |
||
8 | 8 | */ |
9 | 9 | class FilterHelper |
10 | 10 | { |
11 | - protected $filters = array(); |
|
12 | - protected $filterAutoLoad = true; |
|
11 | + protected $filters = array(); |
|
12 | + protected $filterAutoLoad = true; |
|
13 | 13 | |
14 | - public function __construct(array $filters, $filterAutoLoad) |
|
15 | - { |
|
16 | - $this->filters = $filters; |
|
17 | - $this->filterAutoLoad = $filterAutoLoad; |
|
18 | - } |
|
14 | + public function __construct(array $filters, $filterAutoLoad) |
|
15 | + { |
|
16 | + $this->filters = $filters; |
|
17 | + $this->filterAutoLoad = $filterAutoLoad; |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param $name |
|
22 | - * |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - public function hasFilter($name) |
|
26 | - { |
|
27 | - return !is_null($this->getFilter($name)); |
|
28 | - } |
|
20 | + /** |
|
21 | + * @param $name |
|
22 | + * |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + public function hasFilter($name) |
|
26 | + { |
|
27 | + return !is_null($this->getFilter($name)); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param $name |
|
32 | - * |
|
33 | - * @return callable |
|
34 | - */ |
|
35 | - public function getFilter($name) |
|
36 | - { |
|
37 | - // Check that filter is registered |
|
38 | - if (array_key_exists($name, $this->filters)) { |
|
39 | - return $this->filters[$name]; |
|
40 | - } |
|
30 | + /** |
|
31 | + * @param $name |
|
32 | + * |
|
33 | + * @return callable |
|
34 | + */ |
|
35 | + public function getFilter($name) |
|
36 | + { |
|
37 | + // Check that filter is registered |
|
38 | + if (array_key_exists($name, $this->filters)) { |
|
39 | + return $this->filters[$name]; |
|
40 | + } |
|
41 | 41 | |
42 | - if (!$this->filterAutoLoad) { |
|
43 | - return; |
|
44 | - } |
|
42 | + if (!$this->filterAutoLoad) { |
|
43 | + return; |
|
44 | + } |
|
45 | 45 | |
46 | - // Else check if a class with a name that match can be loaded |
|
47 | - foreach (array('Pug', 'Jade') as $namespace) { |
|
48 | - $filter = $namespace . '\\Filter\\' . implode('', array_map('ucfirst', explode('-', $name))); |
|
49 | - if (class_exists($filter)) { |
|
50 | - return $filter; |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
46 | + // Else check if a class with a name that match can be loaded |
|
47 | + foreach (array('Pug', 'Jade') as $namespace) { |
|
48 | + $filter = $namespace . '\\Filter\\' . implode('', array_map('ucfirst', explode('-', $name))); |
|
49 | + if (class_exists($filter)) { |
|
50 | + return $filter; |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param $name |
|
57 | - * |
|
58 | - * @return callable |
|
59 | - */ |
|
60 | - public function getValidFilter($name) |
|
61 | - { |
|
62 | - if ($filter = $this->getFilter($name)) { |
|
63 | - return $filter; |
|
64 | - } |
|
55 | + /** |
|
56 | + * @param $name |
|
57 | + * |
|
58 | + * @return callable |
|
59 | + */ |
|
60 | + public function getValidFilter($name) |
|
61 | + { |
|
62 | + if ($filter = $this->getFilter($name)) { |
|
63 | + return $filter; |
|
64 | + } |
|
65 | 65 | |
66 | - throw new \InvalidArgumentException($name . ': Filter doesn\'t exists', 17); |
|
67 | - } |
|
66 | + throw new \InvalidArgumentException($name . ': Filter doesn\'t exists', 17); |
|
67 | + } |
|
68 | 68 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | // Else check if a class with a name that match can be loaded |
47 | 47 | foreach (array('Pug', 'Jade') as $namespace) { |
48 | - $filter = $namespace . '\\Filter\\' . implode('', array_map('ucfirst', explode('-', $name))); |
|
48 | + $filter = $namespace.'\\Filter\\'.implode('', array_map('ucfirst', explode('-', $name))); |
|
49 | 49 | if (class_exists($filter)) { |
50 | 50 | return $filter; |
51 | 51 | } |
@@ -63,6 +63,6 @@ discard block |
||
63 | 63 | return $filter; |
64 | 64 | } |
65 | 65 | |
66 | - throw new \InvalidArgumentException($name . ': Filter doesn\'t exists', 17); |
|
66 | + throw new \InvalidArgumentException($name.': Filter doesn\'t exists', 17); |
|
67 | 67 | } |
68 | 68 | } |
@@ -4,80 +4,80 @@ |
||
4 | 4 | |
5 | 5 | abstract class ValuesCompiler extends CompilerUtils |
6 | 6 | { |
7 | - /** |
|
8 | - * Value treatment if it must not be escaped. |
|
9 | - * |
|
10 | - * @param string input value |
|
11 | - * |
|
12 | - * @return string |
|
13 | - */ |
|
14 | - public static function getUnescapedValue($val) |
|
15 | - { |
|
16 | - if (is_null($val) || $val === false || $val === '') { |
|
17 | - return ''; |
|
18 | - } |
|
7 | + /** |
|
8 | + * Value treatment if it must not be escaped. |
|
9 | + * |
|
10 | + * @param string input value |
|
11 | + * |
|
12 | + * @return string |
|
13 | + */ |
|
14 | + public static function getUnescapedValue($val) |
|
15 | + { |
|
16 | + if (is_null($val) || $val === false || $val === '') { |
|
17 | + return ''; |
|
18 | + } |
|
19 | 19 | |
20 | - return is_array($val) || is_bool($val) || is_int($val) || is_float($val) ? json_encode($val) : strval($val); |
|
21 | - } |
|
20 | + return is_array($val) || is_bool($val) || is_int($val) || is_float($val) ? json_encode($val) : strval($val); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Value treatment if it must be escaped. |
|
25 | - * |
|
26 | - * @param string input value |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public static function getEscapedValue($val, $quote) |
|
31 | - { |
|
32 | - $val = htmlspecialchars(static::getUnescapedValue($val), ENT_NOQUOTES); |
|
23 | + /** |
|
24 | + * Value treatment if it must be escaped. |
|
25 | + * |
|
26 | + * @param string input value |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public static function getEscapedValue($val, $quote) |
|
31 | + { |
|
32 | + $val = htmlspecialchars(static::getUnescapedValue($val), ENT_NOQUOTES); |
|
33 | 33 | |
34 | - return str_replace($quote, $quote === '"' ? '"' : ''', $val); |
|
35 | - } |
|
34 | + return str_replace($quote, $quote === '"' ? '"' : ''', $val); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Convert style object to CSS string. |
|
39 | - * |
|
40 | - * @param mixed value to be computed into style. |
|
41 | - * |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - public static function styleValue($val) |
|
45 | - { |
|
46 | - if (is_array($val) && !is_string(key($val))) { |
|
47 | - $val = implode(';', $val); |
|
48 | - } elseif (is_array($val) || is_object($val)) { |
|
49 | - $style = array(); |
|
50 | - foreach ($val as $key => $property) { |
|
51 | - $style[] = $key . ':' . $property; |
|
52 | - } |
|
37 | + /** |
|
38 | + * Convert style object to CSS string. |
|
39 | + * |
|
40 | + * @param mixed value to be computed into style. |
|
41 | + * |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + public static function styleValue($val) |
|
45 | + { |
|
46 | + if (is_array($val) && !is_string(key($val))) { |
|
47 | + $val = implode(';', $val); |
|
48 | + } elseif (is_array($val) || is_object($val)) { |
|
49 | + $style = array(); |
|
50 | + foreach ($val as $key => $property) { |
|
51 | + $style[] = $key . ':' . $property; |
|
52 | + } |
|
53 | 53 | |
54 | - $val = implode(';', $style); |
|
55 | - } |
|
54 | + $val = implode(';', $style); |
|
55 | + } |
|
56 | 56 | |
57 | - return $val; |
|
58 | - } |
|
57 | + return $val; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Convert style object to CSS string and return PHP code to escape then display it. |
|
62 | - * |
|
63 | - * @param mixed value to be computed into style and escaped. |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public static function getEscapedStyle($val, $quote) |
|
68 | - { |
|
69 | - return static::getEscapedValue(static::styleValue($val), $quote); |
|
70 | - } |
|
60 | + /** |
|
61 | + * Convert style object to CSS string and return PHP code to escape then display it. |
|
62 | + * |
|
63 | + * @param mixed value to be computed into style and escaped. |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public static function getEscapedStyle($val, $quote) |
|
68 | + { |
|
69 | + return static::getEscapedValue(static::styleValue($val), $quote); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Convert style object to CSS string and return PHP code to display it. |
|
74 | - * |
|
75 | - * @param mixed value to be computed into style and stringified. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function getUnescapedStyle($val) |
|
80 | - { |
|
81 | - return static::getUnescapedValue(static::styleValue($val)); |
|
82 | - } |
|
72 | + /** |
|
73 | + * Convert style object to CSS string and return PHP code to display it. |
|
74 | + * |
|
75 | + * @param mixed value to be computed into style and stringified. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function getUnescapedStyle($val) |
|
80 | + { |
|
81 | + return static::getUnescapedValue(static::styleValue($val)); |
|
82 | + } |
|
83 | 83 | } |
@@ -48,7 +48,7 @@ |
||
48 | 48 | } elseif (is_array($val) || is_object($val)) { |
49 | 49 | $style = array(); |
50 | 50 | foreach ($val as $key => $property) { |
51 | - $style[] = $key . ':' . $property; |
|
51 | + $style[] = $key.':'.$property; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $val = implode(';', $style); |