@@ -34,28 +34,28 @@ discard block |
||
34 | 34 | */ |
35 | 35 | class PluginExtends extends Plugin implements ICompilable |
36 | 36 | { |
37 | - protected static $childSource; |
|
38 | - protected static $regex; |
|
39 | - protected static $l; |
|
40 | - protected static $r; |
|
41 | - protected static $lastReplacement; |
|
42 | - |
|
43 | - public function process() |
|
44 | - { |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @param Compiler $compiler |
|
49 | - * @param $file |
|
50 | - * |
|
51 | - * @throws CompilationException |
|
52 | - */ |
|
53 | - public static function compile(Compiler $compiler, $file) |
|
54 | - { |
|
55 | - list($l, $r) = $compiler->getDelimiters(); |
|
56 | - self::$l = preg_quote($l, '/'); |
|
57 | - self::$r = preg_quote($r, '/'); |
|
58 | - self::$regex = '/ |
|
37 | + protected static $childSource; |
|
38 | + protected static $regex; |
|
39 | + protected static $l; |
|
40 | + protected static $r; |
|
41 | + protected static $lastReplacement; |
|
42 | + |
|
43 | + public function process() |
|
44 | + { |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @param Compiler $compiler |
|
49 | + * @param $file |
|
50 | + * |
|
51 | + * @throws CompilationException |
|
52 | + */ |
|
53 | + public static function compile(Compiler $compiler, $file) |
|
54 | + { |
|
55 | + list($l, $r) = $compiler->getDelimiters(); |
|
56 | + self::$l = preg_quote($l, '/'); |
|
57 | + self::$r = preg_quote($r, '/'); |
|
58 | + self::$regex = '/ |
|
59 | 59 | ' . self::$l . 'block\s(["\']?)(.+?)\1' . self::$r . '(?:\r?\n?) |
60 | 60 | ((?: |
61 | 61 | (?R) |
@@ -70,137 +70,137 @@ discard block |
||
70 | 70 | ' . self::$l . '\/block' . self::$r . ' |
71 | 71 | /six'; |
72 | 72 | |
73 | - if ($compiler->getLooseOpeningHandling()) { |
|
74 | - self::$l .= '\s*'; |
|
75 | - self::$r = '\s*' . self::$r; |
|
76 | - } |
|
77 | - $inheritanceTree = array(array('source' => $compiler->getTemplateSource())); |
|
78 | - $curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()) . DIRECTORY_SEPARATOR; |
|
79 | - $curTpl = $compiler->getDwoo()->getTemplate(); |
|
80 | - |
|
81 | - while (!empty($file)) { |
|
82 | - if ($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'')) { |
|
83 | - throw new CompilationException($compiler, 'Extends : The file name must be a non-empty string'); |
|
84 | - } |
|
85 | - |
|
86 | - if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) { |
|
87 | - // resource:identifier given, extract them |
|
88 | - $resource = $m[1]; |
|
89 | - $identifier = $m[2]; |
|
90 | - } else { |
|
91 | - // get the current template's resource |
|
92 | - $resource = $curTpl->getResourceName(); |
|
93 | - $identifier = substr($file, 1, - 1); |
|
94 | - } |
|
95 | - |
|
96 | - try { |
|
97 | - $parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl); |
|
98 | - } |
|
99 | - catch (SecurityException $e) { |
|
100 | - throw new CompilationException($compiler, 'Extends : Security restriction : ' . $e->getMessage()); |
|
101 | - } |
|
102 | - catch (Exception $e) { |
|
103 | - throw new CompilationException($compiler, 'Extends : ' . $e->getMessage()); |
|
104 | - } |
|
105 | - |
|
106 | - if ($parent === null) { |
|
107 | - throw new CompilationException($compiler, 'Extends : Resource "' . $resource . ':' . $identifier . '" not found.'); |
|
108 | - } elseif ($parent === false) { |
|
109 | - throw new CompilationException($compiler, 'Extends : Resource "' . $resource . '" does not support extends.'); |
|
110 | - } |
|
111 | - |
|
112 | - $curTpl = $parent; |
|
113 | - $newParent = array( |
|
114 | - 'source' => $parent->getSource(), |
|
115 | - 'resource' => $resource, |
|
116 | - 'identifier' => $parent->getResourceIdentifier(), |
|
117 | - 'uid' => $parent->getUid() |
|
118 | - ); |
|
119 | - if (array_search($newParent, $inheritanceTree, true) !== false) { |
|
120 | - throw new CompilationException($compiler, 'Extends : Recursive template inheritance detected'); |
|
121 | - } |
|
122 | - $inheritanceTree[] = $newParent; |
|
123 | - |
|
124 | - if (preg_match('/^' . self::$l . 'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?' . self::$r . '/i', $parent->getSource(), $match)) { |
|
125 | - $curPath = dirname($identifier) . DIRECTORY_SEPARATOR; |
|
126 | - if (isset($match[2]) && $match[2] == '"') { |
|
127 | - $file = '"' . str_replace('"', '\\"', substr($match[1], 1, - 1)) . '"'; |
|
128 | - } elseif (isset($match[2]) && $match[2] == "'") { |
|
129 | - $file = '"' . substr($match[1], 1, - 1) . '"'; |
|
130 | - } else { |
|
131 | - $file = '"' . $match[1] . '"'; |
|
132 | - } |
|
133 | - } else { |
|
134 | - $file = false; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - while (true) { |
|
139 | - $parent = array_pop($inheritanceTree); |
|
140 | - $child = end($inheritanceTree); |
|
141 | - self::$childSource = $child['source']; |
|
142 | - self::$lastReplacement = count($inheritanceTree) === 1; |
|
143 | - if (!isset($newSource)) { |
|
144 | - $newSource = $parent['source']; |
|
145 | - } |
|
146 | - $newSource = preg_replace_callback(self::$regex, array( |
|
147 | - 'Dwoo\Plugins\Functions\PluginExtends', |
|
148 | - 'replaceBlock' |
|
149 | - ), $newSource); |
|
150 | - $newSource = $l . 'do extendsCheck(' . var_export($parent['resource'] . ':' . $parent['identifier'], true) . ')' . $r . $newSource; |
|
151 | - |
|
152 | - if (self::$lastReplacement) { |
|
153 | - break; |
|
154 | - } |
|
155 | - } |
|
156 | - $compiler->setTemplateSource($newSource); |
|
157 | - $compiler->recompile(); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param array $matches |
|
162 | - * |
|
163 | - * @return mixed|string |
|
164 | - */ |
|
165 | - protected static function replaceBlock(array $matches) |
|
166 | - { |
|
167 | - $matches[3] = self::removeTrailingNewline($matches[3]); |
|
168 | - |
|
169 | - if (preg_match_all(self::$regex, self::$childSource, $override) && in_array($matches[2], $override[2])) { |
|
170 | - $key = array_search($matches[2], $override[2]); |
|
171 | - $override = self::removeTrailingNewline($override[3][$key]); |
|
172 | - |
|
173 | - $l = stripslashes(self::$l); |
|
174 | - $r = stripslashes(self::$r); |
|
175 | - |
|
176 | - if (self::$lastReplacement) { |
|
177 | - return preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override); |
|
178 | - } |
|
179 | - |
|
180 | - return $l . 'block ' . $matches[1] . $matches[2] . $matches[1] . $r . preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override) . $l . '/block' . $r; |
|
181 | - } |
|
182 | - |
|
183 | - if (preg_match(self::$regex, $matches[3])) { |
|
184 | - return preg_replace_callback(self::$regex, array( |
|
185 | - 'Dwoo\Plugins\Functions\PluginExtends', |
|
186 | - 'replaceBlock' |
|
187 | - ), $matches[3]); |
|
188 | - } |
|
189 | - |
|
190 | - if (self::$lastReplacement) { |
|
191 | - return $matches[3]; |
|
192 | - } |
|
193 | - |
|
194 | - return $matches[0]; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $text |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - protected static function removeTrailingNewline($text) |
|
203 | - { |
|
204 | - return substr($text, - 1) === "\n" ? substr($text, - 2, 1) === "\r" ? substr($text, 0, - 2) : substr($text, 0, - 1) : $text; |
|
205 | - } |
|
73 | + if ($compiler->getLooseOpeningHandling()) { |
|
74 | + self::$l .= '\s*'; |
|
75 | + self::$r = '\s*' . self::$r; |
|
76 | + } |
|
77 | + $inheritanceTree = array(array('source' => $compiler->getTemplateSource())); |
|
78 | + $curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()) . DIRECTORY_SEPARATOR; |
|
79 | + $curTpl = $compiler->getDwoo()->getTemplate(); |
|
80 | + |
|
81 | + while (!empty($file)) { |
|
82 | + if ($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '\'')) { |
|
83 | + throw new CompilationException($compiler, 'Extends : The file name must be a non-empty string'); |
|
84 | + } |
|
85 | + |
|
86 | + if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) { |
|
87 | + // resource:identifier given, extract them |
|
88 | + $resource = $m[1]; |
|
89 | + $identifier = $m[2]; |
|
90 | + } else { |
|
91 | + // get the current template's resource |
|
92 | + $resource = $curTpl->getResourceName(); |
|
93 | + $identifier = substr($file, 1, - 1); |
|
94 | + } |
|
95 | + |
|
96 | + try { |
|
97 | + $parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl); |
|
98 | + } |
|
99 | + catch (SecurityException $e) { |
|
100 | + throw new CompilationException($compiler, 'Extends : Security restriction : ' . $e->getMessage()); |
|
101 | + } |
|
102 | + catch (Exception $e) { |
|
103 | + throw new CompilationException($compiler, 'Extends : ' . $e->getMessage()); |
|
104 | + } |
|
105 | + |
|
106 | + if ($parent === null) { |
|
107 | + throw new CompilationException($compiler, 'Extends : Resource "' . $resource . ':' . $identifier . '" not found.'); |
|
108 | + } elseif ($parent === false) { |
|
109 | + throw new CompilationException($compiler, 'Extends : Resource "' . $resource . '" does not support extends.'); |
|
110 | + } |
|
111 | + |
|
112 | + $curTpl = $parent; |
|
113 | + $newParent = array( |
|
114 | + 'source' => $parent->getSource(), |
|
115 | + 'resource' => $resource, |
|
116 | + 'identifier' => $parent->getResourceIdentifier(), |
|
117 | + 'uid' => $parent->getUid() |
|
118 | + ); |
|
119 | + if (array_search($newParent, $inheritanceTree, true) !== false) { |
|
120 | + throw new CompilationException($compiler, 'Extends : Recursive template inheritance detected'); |
|
121 | + } |
|
122 | + $inheritanceTree[] = $newParent; |
|
123 | + |
|
124 | + if (preg_match('/^' . self::$l . 'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?' . self::$r . '/i', $parent->getSource(), $match)) { |
|
125 | + $curPath = dirname($identifier) . DIRECTORY_SEPARATOR; |
|
126 | + if (isset($match[2]) && $match[2] == '"') { |
|
127 | + $file = '"' . str_replace('"', '\\"', substr($match[1], 1, - 1)) . '"'; |
|
128 | + } elseif (isset($match[2]) && $match[2] == "'") { |
|
129 | + $file = '"' . substr($match[1], 1, - 1) . '"'; |
|
130 | + } else { |
|
131 | + $file = '"' . $match[1] . '"'; |
|
132 | + } |
|
133 | + } else { |
|
134 | + $file = false; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + while (true) { |
|
139 | + $parent = array_pop($inheritanceTree); |
|
140 | + $child = end($inheritanceTree); |
|
141 | + self::$childSource = $child['source']; |
|
142 | + self::$lastReplacement = count($inheritanceTree) === 1; |
|
143 | + if (!isset($newSource)) { |
|
144 | + $newSource = $parent['source']; |
|
145 | + } |
|
146 | + $newSource = preg_replace_callback(self::$regex, array( |
|
147 | + 'Dwoo\Plugins\Functions\PluginExtends', |
|
148 | + 'replaceBlock' |
|
149 | + ), $newSource); |
|
150 | + $newSource = $l . 'do extendsCheck(' . var_export($parent['resource'] . ':' . $parent['identifier'], true) . ')' . $r . $newSource; |
|
151 | + |
|
152 | + if (self::$lastReplacement) { |
|
153 | + break; |
|
154 | + } |
|
155 | + } |
|
156 | + $compiler->setTemplateSource($newSource); |
|
157 | + $compiler->recompile(); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param array $matches |
|
162 | + * |
|
163 | + * @return mixed|string |
|
164 | + */ |
|
165 | + protected static function replaceBlock(array $matches) |
|
166 | + { |
|
167 | + $matches[3] = self::removeTrailingNewline($matches[3]); |
|
168 | + |
|
169 | + if (preg_match_all(self::$regex, self::$childSource, $override) && in_array($matches[2], $override[2])) { |
|
170 | + $key = array_search($matches[2], $override[2]); |
|
171 | + $override = self::removeTrailingNewline($override[3][$key]); |
|
172 | + |
|
173 | + $l = stripslashes(self::$l); |
|
174 | + $r = stripslashes(self::$r); |
|
175 | + |
|
176 | + if (self::$lastReplacement) { |
|
177 | + return preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override); |
|
178 | + } |
|
179 | + |
|
180 | + return $l . 'block ' . $matches[1] . $matches[2] . $matches[1] . $r . preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override) . $l . '/block' . $r; |
|
181 | + } |
|
182 | + |
|
183 | + if (preg_match(self::$regex, $matches[3])) { |
|
184 | + return preg_replace_callback(self::$regex, array( |
|
185 | + 'Dwoo\Plugins\Functions\PluginExtends', |
|
186 | + 'replaceBlock' |
|
187 | + ), $matches[3]); |
|
188 | + } |
|
189 | + |
|
190 | + if (self::$lastReplacement) { |
|
191 | + return $matches[3]; |
|
192 | + } |
|
193 | + |
|
194 | + return $matches[0]; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $text |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + protected static function removeTrailingNewline($text) |
|
203 | + { |
|
204 | + return substr($text, - 1) === "\n" ? substr($text, - 2, 1) === "\r" ? substr($text, 0, - 2) : substr($text, 0, - 1) : $text; |
|
205 | + } |
|
206 | 206 | } |
@@ -56,26 +56,26 @@ discard block |
||
56 | 56 | self::$l = preg_quote($l, '/'); |
57 | 57 | self::$r = preg_quote($r, '/'); |
58 | 58 | self::$regex = '/ |
59 | - ' . self::$l . 'block\s(["\']?)(.+?)\1' . self::$r . '(?:\r?\n?) |
|
59 | + ' . self::$l.'block\s(["\']?)(.+?)\1'.self::$r.'(?:\r?\n?) |
|
60 | 60 | ((?: |
61 | 61 | (?R) |
62 | 62 | | |
63 | - [^' . self::$l . ']* |
|
63 | + [^' . self::$l.']* |
|
64 | 64 | (?: |
65 | - (?! ' . self::$l . '\/?block\b ) |
|
66 | - ' . self::$l . ' |
|
67 | - [^' . self::$l . ']*+ |
|
65 | + (?! ' . self::$l.'\/?block\b ) |
|
66 | + ' . self::$l.' |
|
67 | + [^' . self::$l.']*+ |
|
68 | 68 | )* |
69 | 69 | )*) |
70 | - ' . self::$l . '\/block' . self::$r . ' |
|
70 | + ' . self::$l.'\/block'.self::$r.' |
|
71 | 71 | /six'; |
72 | 72 | |
73 | 73 | if ($compiler->getLooseOpeningHandling()) { |
74 | 74 | self::$l .= '\s*'; |
75 | - self::$r = '\s*' . self::$r; |
|
75 | + self::$r = '\s*'.self::$r; |
|
76 | 76 | } |
77 | 77 | $inheritanceTree = array(array('source' => $compiler->getTemplateSource())); |
78 | - $curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()) . DIRECTORY_SEPARATOR; |
|
78 | + $curPath = dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()).DIRECTORY_SEPARATOR; |
|
79 | 79 | $curTpl = $compiler->getDwoo()->getTemplate(); |
80 | 80 | |
81 | 81 | while (!empty($file)) { |
@@ -97,16 +97,16 @@ discard block |
||
97 | 97 | $parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl); |
98 | 98 | } |
99 | 99 | catch (SecurityException $e) { |
100 | - throw new CompilationException($compiler, 'Extends : Security restriction : ' . $e->getMessage()); |
|
100 | + throw new CompilationException($compiler, 'Extends : Security restriction : '.$e->getMessage()); |
|
101 | 101 | } |
102 | 102 | catch (Exception $e) { |
103 | - throw new CompilationException($compiler, 'Extends : ' . $e->getMessage()); |
|
103 | + throw new CompilationException($compiler, 'Extends : '.$e->getMessage()); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | if ($parent === null) { |
107 | - throw new CompilationException($compiler, 'Extends : Resource "' . $resource . ':' . $identifier . '" not found.'); |
|
107 | + throw new CompilationException($compiler, 'Extends : Resource "'.$resource.':'.$identifier.'" not found.'); |
|
108 | 108 | } elseif ($parent === false) { |
109 | - throw new CompilationException($compiler, 'Extends : Resource "' . $resource . '" does not support extends.'); |
|
109 | + throw new CompilationException($compiler, 'Extends : Resource "'.$resource.'" does not support extends.'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $curTpl = $parent; |
@@ -121,14 +121,14 @@ discard block |
||
121 | 121 | } |
122 | 122 | $inheritanceTree[] = $newParent; |
123 | 123 | |
124 | - if (preg_match('/^' . self::$l . 'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?' . self::$r . '/i', $parent->getSource(), $match)) { |
|
125 | - $curPath = dirname($identifier) . DIRECTORY_SEPARATOR; |
|
124 | + if (preg_match('/^'.self::$l.'extends(?:\(?\s*|\s+)(?:file=)?\s*((["\']).+?\2|\S+?)\s*\)?\s*?'.self::$r.'/i', $parent->getSource(), $match)) { |
|
125 | + $curPath = dirname($identifier).DIRECTORY_SEPARATOR; |
|
126 | 126 | if (isset($match[2]) && $match[2] == '"') { |
127 | - $file = '"' . str_replace('"', '\\"', substr($match[1], 1, - 1)) . '"'; |
|
127 | + $file = '"'.str_replace('"', '\\"', substr($match[1], 1, - 1)).'"'; |
|
128 | 128 | } elseif (isset($match[2]) && $match[2] == "'") { |
129 | - $file = '"' . substr($match[1], 1, - 1) . '"'; |
|
129 | + $file = '"'.substr($match[1], 1, - 1).'"'; |
|
130 | 130 | } else { |
131 | - $file = '"' . $match[1] . '"'; |
|
131 | + $file = '"'.$match[1].'"'; |
|
132 | 132 | } |
133 | 133 | } else { |
134 | 134 | $file = false; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | 'Dwoo\Plugins\Functions\PluginExtends', |
148 | 148 | 'replaceBlock' |
149 | 149 | ), $newSource); |
150 | - $newSource = $l . 'do extendsCheck(' . var_export($parent['resource'] . ':' . $parent['identifier'], true) . ')' . $r . $newSource; |
|
150 | + $newSource = $l.'do extendsCheck('.var_export($parent['resource'].':'.$parent['identifier'], true).')'.$r.$newSource; |
|
151 | 151 | |
152 | 152 | if (self::$lastReplacement) { |
153 | 153 | break; |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | $r = stripslashes(self::$r); |
175 | 175 | |
176 | 176 | if (self::$lastReplacement) { |
177 | - return preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override); |
|
177 | + return preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override); |
|
178 | 178 | } |
179 | 179 | |
180 | - return $l . 'block ' . $matches[1] . $matches[2] . $matches[1] . $r . preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override) . $l . '/block' . $r; |
|
180 | + return $l.'block '.$matches[1].$matches[2].$matches[1].$r.preg_replace('/'.self::$l.'\$dwoo\.parent'.self::$r.'/is', $matches[3], $override).$l.'/block'.$r; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | if (preg_match(self::$regex, $matches[3])) { |
@@ -95,11 +95,9 @@ |
||
95 | 95 | |
96 | 96 | try { |
97 | 97 | $parent = $compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl); |
98 | - } |
|
99 | - catch (SecurityException $e) { |
|
98 | + } catch (SecurityException $e) { |
|
100 | 99 | throw new CompilationException($compiler, 'Extends : Security restriction : ' . $e->getMessage()); |
101 | - } |
|
102 | - catch (Exception $e) { |
|
100 | + } catch (Exception $e) { |
|
103 | 101 | throw new CompilationException($compiler, 'Extends : ' . $e->getMessage()); |
104 | 102 | } |
105 | 103 |
@@ -74,10 +74,10 @@ |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | if ($advance) { |
77 | - if ($this->cycles[$name]['index'] >= count($values) - 1) { |
|
77 | + if ($this->cycles[$name]['index'] >= count($values)-1) { |
|
78 | 78 | $this->cycles[$name]['index'] = 0; |
79 | 79 | } else { |
80 | - ++ $this->cycles[$name]['index']; |
|
80 | + ++$this->cycles[$name]['index']; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 |
@@ -34,58 +34,58 @@ |
||
34 | 34 | */ |
35 | 35 | class PluginCycle extends Plugin |
36 | 36 | { |
37 | - protected $cycles = array(); |
|
37 | + protected $cycles = array(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @param null $values |
|
42 | - * @param bool $print |
|
43 | - * @param bool $advance |
|
44 | - * @param string $delimiter |
|
45 | - * @param null $assign |
|
46 | - * @param bool $reset |
|
47 | - * |
|
48 | - * @return string|null |
|
49 | - */ |
|
50 | - public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false) |
|
51 | - { |
|
52 | - if ($values !== null) { |
|
53 | - if (is_string($values)) { |
|
54 | - $values = explode($delimiter, $values); |
|
55 | - } |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @param null $values |
|
42 | + * @param bool $print |
|
43 | + * @param bool $advance |
|
44 | + * @param string $delimiter |
|
45 | + * @param null $assign |
|
46 | + * @param bool $reset |
|
47 | + * |
|
48 | + * @return string|null |
|
49 | + */ |
|
50 | + public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false) |
|
51 | + { |
|
52 | + if ($values !== null) { |
|
53 | + if (is_string($values)) { |
|
54 | + $values = explode($delimiter, $values); |
|
55 | + } |
|
56 | 56 | |
57 | - if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) { |
|
58 | - $this->cycles[$name]['index'] = 0; |
|
59 | - } |
|
57 | + if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) { |
|
58 | + $this->cycles[$name]['index'] = 0; |
|
59 | + } |
|
60 | 60 | |
61 | - $this->cycles[$name]['values'] = array_values($values); |
|
62 | - } elseif (isset($this->cycles[$name])) { |
|
63 | - $values = $this->cycles[$name]['values']; |
|
64 | - } |
|
61 | + $this->cycles[$name]['values'] = array_values($values); |
|
62 | + } elseif (isset($this->cycles[$name])) { |
|
63 | + $values = $this->cycles[$name]['values']; |
|
64 | + } |
|
65 | 65 | |
66 | - if ($reset) { |
|
67 | - $this->cycles[$name]['index'] = 0; |
|
68 | - } |
|
66 | + if ($reset) { |
|
67 | + $this->cycles[$name]['index'] = 0; |
|
68 | + } |
|
69 | 69 | |
70 | - if ($print) { |
|
71 | - $out = $values[$this->cycles[$name]['index']]; |
|
72 | - } else { |
|
73 | - $out = null; |
|
74 | - } |
|
70 | + if ($print) { |
|
71 | + $out = $values[$this->cycles[$name]['index']]; |
|
72 | + } else { |
|
73 | + $out = null; |
|
74 | + } |
|
75 | 75 | |
76 | - if ($advance) { |
|
77 | - if ($this->cycles[$name]['index'] >= count($values) - 1) { |
|
78 | - $this->cycles[$name]['index'] = 0; |
|
79 | - } else { |
|
80 | - ++ $this->cycles[$name]['index']; |
|
81 | - } |
|
82 | - } |
|
76 | + if ($advance) { |
|
77 | + if ($this->cycles[$name]['index'] >= count($values) - 1) { |
|
78 | + $this->cycles[$name]['index'] = 0; |
|
79 | + } else { |
|
80 | + ++ $this->cycles[$name]['index']; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - if ($assign === null) { |
|
85 | - return $out; |
|
86 | - } |
|
87 | - $this->core->assignInScope($out, $assign); |
|
84 | + if ($assign === null) { |
|
85 | + return $out; |
|
86 | + } |
|
87 | + $this->core->assignInScope($out, $assign); |
|
88 | 88 | |
89 | - return null; |
|
90 | - } |
|
89 | + return null; |
|
90 | + } |
|
91 | 91 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | $out .= $this->export($var, $scope); |
64 | 64 | |
65 | - return $out . '</div></div>'; |
|
65 | + return $out.'</div></div>'; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | protected function export($var, $scope) |
@@ -70,16 +70,16 @@ discard block |
||
70 | 70 | $out = ''; |
71 | 71 | foreach ($var as $i => $v) { |
72 | 72 | if (is_array($v) || (is_object($v) && $v instanceof Iterator)) { |
73 | - $out .= $i . ' (' . (is_array($v) ? 'array' : 'object: ' . get_class($v)) . ')'; |
|
73 | + $out .= $i.' ('.(is_array($v) ? 'array' : 'object: '.get_class($v)).')'; |
|
74 | 74 | if ($v === $scope) { |
75 | - $out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">' . $this->export($v, $scope) . '</div>'; |
|
75 | + $out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">'.$this->export($v, $scope).'</div>'; |
|
76 | 76 | } else { |
77 | - $out .= ':<div style="padding-left:20px;">' . $this->export($v, $scope) . '</div>'; |
|
77 | + $out .= ':<div style="padding-left:20px;">'.$this->export($v, $scope).'</div>'; |
|
78 | 78 | } |
79 | 79 | } elseif (is_object($v)) { |
80 | - $out .= $this->exportObj($i . ' (object: ' . get_class($v) . '):', $v); |
|
80 | + $out .= $this->exportObj($i.' (object: '.get_class($v).'):', $v); |
|
81 | 81 | } else { |
82 | - $out .= $this->exportVar($i . ' = ', $v); |
|
82 | + $out .= $this->exportVar($i.' = ', $v); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -89,27 +89,27 @@ discard block |
||
89 | 89 | protected function exportVar($i, $v) |
90 | 90 | { |
91 | 91 | if (is_string($v) || is_bool($v) || is_numeric($v)) { |
92 | - return $i . htmlentities(var_export($v, true)) . '<br />'; |
|
92 | + return $i.htmlentities(var_export($v, true)).'<br />'; |
|
93 | 93 | } elseif (is_null($v)) { |
94 | - return $i . 'null<br />'; |
|
94 | + return $i.'null<br />'; |
|
95 | 95 | } elseif (is_resource($v)) { |
96 | - return $i . 'resource(' . get_resource_type($v) . ')<br />'; |
|
96 | + return $i.'resource('.get_resource_type($v).')<br />'; |
|
97 | 97 | } else { |
98 | - return $i . htmlentities(var_export($v, true)) . '<br />'; |
|
98 | + return $i.htmlentities(var_export($v, true)).'<br />'; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | 102 | protected function exportObj($i, $obj) |
103 | 103 | { |
104 | 104 | if (array_search($obj, $this->outputObjects, true) !== false) { |
105 | - return $i . ' [recursion, skipped]<br />'; |
|
105 | + return $i.' [recursion, skipped]<br />'; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | $this->outputObjects[] = $obj; |
109 | 109 | |
110 | - $list = (array)$obj; |
|
110 | + $list = (array) $obj; |
|
111 | 111 | |
112 | - $protectedLength = strlen(get_class($obj)) + 2; |
|
112 | + $protectedLength = strlen(get_class($obj))+2; |
|
113 | 113 | |
114 | 114 | $out = array(); |
115 | 115 | |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | |
128 | 128 | $params = array(); |
129 | 129 | foreach ($method->getParameters() as $param) { |
130 | - $params[] = ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName() . ($param->isOptional() ? ' = ' . var_export($param->getDefaultValue(), true) : ''); |
|
130 | + $params[] = ($param->isPassedByReference() ? '&' : '').'$'.$param->getName().($param->isOptional() ? ' = '.var_export($param->getDefaultValue(), true) : ''); |
|
131 | 131 | } |
132 | 132 | |
133 | - $out['method'] .= '(method) ' . $method->getName() . '(' . implode(', ', $params) . ')<br />'; |
|
133 | + $out['method'] .= '(method) '.$method->getName().'('.implode(', ', $params).')<br />'; |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -149,19 +149,19 @@ discard block |
||
149 | 149 | $out[$key] = ''; |
150 | 150 | } |
151 | 151 | |
152 | - $out[$key] .= '(' . $key . ') '; |
|
152 | + $out[$key] .= '('.$key.') '; |
|
153 | 153 | |
154 | 154 | if (is_array($attributeValue)) { |
155 | - $out[$key] .= $attributeName . ' (array):<br /> |
|
156 | - <div style="padding-left:20px;">' . $this->export($attributeValue, false) . '</div>'; |
|
155 | + $out[$key] .= $attributeName.' (array):<br /> |
|
156 | + <div style="padding-left:20px;">' . $this->export($attributeValue, false).'</div>'; |
|
157 | 157 | } elseif (is_object($attributeValue)) { |
158 | - $out[$key] .= $this->exportObj($attributeName . ' (object: ' . get_class($attributeValue) . '):', $attributeValue); |
|
158 | + $out[$key] .= $this->exportObj($attributeName.' (object: '.get_class($attributeValue).'):', $attributeValue); |
|
159 | 159 | } else { |
160 | - $out[$key] .= $this->exportVar($attributeName . ' = ', $attributeValue); |
|
160 | + $out[$key] .= $this->exportVar($attributeName.' = ', $attributeValue); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | - $return = $i . '<br /><div style="padding-left:20px;">'; |
|
164 | + $return = $i.'<br /><div style="padding-left:20px;">'; |
|
165 | 165 | |
166 | 166 | if (!empty($out['method'])) { |
167 | 167 | $return .= $out['method']; |
@@ -179,6 +179,6 @@ discard block |
||
179 | 179 | $return .= $out['private']; |
180 | 180 | } |
181 | 181 | |
182 | - return $return . '</div>'; |
|
182 | + return $return.'</div>'; |
|
183 | 183 | } |
184 | 184 | } |
@@ -31,180 +31,180 @@ |
||
31 | 31 | */ |
32 | 32 | class PluginDump extends Plugin |
33 | 33 | { |
34 | - protected $outputObjects; |
|
35 | - protected $outputMethods; |
|
36 | - |
|
37 | - /** |
|
38 | - * @param string $var |
|
39 | - * @param bool $show_methods |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function process($var = '$', $show_methods = false) |
|
44 | - { |
|
45 | - $this->outputMethods = $show_methods; |
|
46 | - if ($var === '$') { |
|
47 | - $var = $this->core->getData(); |
|
48 | - $out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">data'; |
|
49 | - } else { |
|
50 | - $out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">dump'; |
|
51 | - } |
|
52 | - |
|
53 | - $this->outputObjects = array(); |
|
54 | - |
|
55 | - if (!is_array($var)) { |
|
56 | - if (is_object($var)) { |
|
57 | - return $this->exportObj('', $var); |
|
58 | - } else { |
|
59 | - return $this->exportVar('', $var); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - $scope = $this->core->getScope(); |
|
64 | - |
|
65 | - if ($var === $scope) { |
|
66 | - $out .= ' (current scope): <div style="background:#ccc;">'; |
|
67 | - } else { |
|
68 | - $out .= ':<div style="padding-left:20px;">'; |
|
69 | - } |
|
70 | - |
|
71 | - $out .= $this->export($var, $scope); |
|
72 | - |
|
73 | - return $out . '</div></div>'; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param $var |
|
78 | - * @param $scope |
|
79 | - * |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - protected function export($var, $scope) |
|
83 | - { |
|
84 | - $out = ''; |
|
85 | - foreach ($var as $i => $v) { |
|
86 | - if (is_array($v) || (is_object($v) && $v instanceof Iterator)) { |
|
87 | - $out .= $i . ' (' . (is_array($v) ? 'array' : 'object: ' . get_class($v)) . ')'; |
|
88 | - if ($v === $scope) { |
|
89 | - $out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">' . $this->export($v, $scope) . '</div>'; |
|
90 | - } else { |
|
91 | - $out .= ':<div style="padding-left:20px;">' . $this->export($v, $scope) . '</div>'; |
|
92 | - } |
|
93 | - } elseif (is_object($v)) { |
|
94 | - $out .= $this->exportObj($i . ' (object: ' . get_class($v) . '):', $v); |
|
95 | - } else { |
|
96 | - $out .= $this->exportVar($i . ' = ', $v); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - return $out; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param $i |
|
105 | - * @param $v |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - protected function exportVar($i, $v) |
|
110 | - { |
|
111 | - if (is_string($v) || is_bool($v) || is_numeric($v)) { |
|
112 | - return $i . htmlentities(var_export($v, true)) . '<br />'; |
|
113 | - } elseif (is_null($v)) { |
|
114 | - return $i . 'null<br />'; |
|
115 | - } elseif (is_resource($v)) { |
|
116 | - return $i . 'resource(' . get_resource_type($v) . ')<br />'; |
|
117 | - } else { |
|
118 | - return $i . htmlentities(var_export($v, true)) . '<br />'; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param $i |
|
124 | - * @param $obj |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function exportObj($i, $obj) |
|
129 | - { |
|
130 | - if (array_search($obj, $this->outputObjects, true) !== false) { |
|
131 | - return $i . ' [recursion, skipped]<br />'; |
|
132 | - } |
|
133 | - |
|
134 | - $this->outputObjects[] = $obj; |
|
135 | - |
|
136 | - $list = (array)$obj; |
|
137 | - |
|
138 | - $protectedLength = strlen(get_class($obj)) + 2; |
|
139 | - |
|
140 | - $out = array(); |
|
141 | - |
|
142 | - if ($this->outputMethods) { |
|
143 | - $ref = new ReflectionObject($obj); |
|
144 | - |
|
145 | - foreach ($ref->getMethods() as $method) { |
|
146 | - if (!$method->isPublic()) { |
|
147 | - continue; |
|
148 | - } |
|
149 | - |
|
150 | - if (empty($out['method'])) { |
|
151 | - $out['method'] = ''; |
|
152 | - } |
|
153 | - |
|
154 | - $params = array(); |
|
155 | - foreach ($method->getParameters() as $param) { |
|
156 | - $params[] = ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName() . ($param->isOptional() ? ' = ' . var_export($param->getDefaultValue(), true) : ''); |
|
157 | - } |
|
158 | - |
|
159 | - $out['method'] .= '(method) ' . $method->getName() . '(' . implode(', ', $params) . ')<br />'; |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - foreach ($list as $attributeName => $attributeValue) { |
|
164 | - if (property_exists($obj, $attributeName)) { |
|
165 | - $key = 'public'; |
|
166 | - } elseif (substr($attributeName, 0, 3) === "\0*\0") { |
|
167 | - $key = 'protected'; |
|
168 | - $attributeName = substr($attributeName, 3); |
|
169 | - } else { |
|
170 | - $key = 'private'; |
|
171 | - $attributeName = substr($attributeName, $protectedLength); |
|
172 | - } |
|
173 | - |
|
174 | - if (empty($out[$key])) { |
|
175 | - $out[$key] = ''; |
|
176 | - } |
|
177 | - |
|
178 | - $out[$key] .= '(' . $key . ') '; |
|
179 | - |
|
180 | - if (is_array($attributeValue)) { |
|
181 | - $out[$key] .= $attributeName . ' (array):<br /> |
|
34 | + protected $outputObjects; |
|
35 | + protected $outputMethods; |
|
36 | + |
|
37 | + /** |
|
38 | + * @param string $var |
|
39 | + * @param bool $show_methods |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function process($var = '$', $show_methods = false) |
|
44 | + { |
|
45 | + $this->outputMethods = $show_methods; |
|
46 | + if ($var === '$') { |
|
47 | + $var = $this->core->getData(); |
|
48 | + $out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">data'; |
|
49 | + } else { |
|
50 | + $out = '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">dump'; |
|
51 | + } |
|
52 | + |
|
53 | + $this->outputObjects = array(); |
|
54 | + |
|
55 | + if (!is_array($var)) { |
|
56 | + if (is_object($var)) { |
|
57 | + return $this->exportObj('', $var); |
|
58 | + } else { |
|
59 | + return $this->exportVar('', $var); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + $scope = $this->core->getScope(); |
|
64 | + |
|
65 | + if ($var === $scope) { |
|
66 | + $out .= ' (current scope): <div style="background:#ccc;">'; |
|
67 | + } else { |
|
68 | + $out .= ':<div style="padding-left:20px;">'; |
|
69 | + } |
|
70 | + |
|
71 | + $out .= $this->export($var, $scope); |
|
72 | + |
|
73 | + return $out . '</div></div>'; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param $var |
|
78 | + * @param $scope |
|
79 | + * |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + protected function export($var, $scope) |
|
83 | + { |
|
84 | + $out = ''; |
|
85 | + foreach ($var as $i => $v) { |
|
86 | + if (is_array($v) || (is_object($v) && $v instanceof Iterator)) { |
|
87 | + $out .= $i . ' (' . (is_array($v) ? 'array' : 'object: ' . get_class($v)) . ')'; |
|
88 | + if ($v === $scope) { |
|
89 | + $out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">' . $this->export($v, $scope) . '</div>'; |
|
90 | + } else { |
|
91 | + $out .= ':<div style="padding-left:20px;">' . $this->export($v, $scope) . '</div>'; |
|
92 | + } |
|
93 | + } elseif (is_object($v)) { |
|
94 | + $out .= $this->exportObj($i . ' (object: ' . get_class($v) . '):', $v); |
|
95 | + } else { |
|
96 | + $out .= $this->exportVar($i . ' = ', $v); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + return $out; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param $i |
|
105 | + * @param $v |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + protected function exportVar($i, $v) |
|
110 | + { |
|
111 | + if (is_string($v) || is_bool($v) || is_numeric($v)) { |
|
112 | + return $i . htmlentities(var_export($v, true)) . '<br />'; |
|
113 | + } elseif (is_null($v)) { |
|
114 | + return $i . 'null<br />'; |
|
115 | + } elseif (is_resource($v)) { |
|
116 | + return $i . 'resource(' . get_resource_type($v) . ')<br />'; |
|
117 | + } else { |
|
118 | + return $i . htmlentities(var_export($v, true)) . '<br />'; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param $i |
|
124 | + * @param $obj |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function exportObj($i, $obj) |
|
129 | + { |
|
130 | + if (array_search($obj, $this->outputObjects, true) !== false) { |
|
131 | + return $i . ' [recursion, skipped]<br />'; |
|
132 | + } |
|
133 | + |
|
134 | + $this->outputObjects[] = $obj; |
|
135 | + |
|
136 | + $list = (array)$obj; |
|
137 | + |
|
138 | + $protectedLength = strlen(get_class($obj)) + 2; |
|
139 | + |
|
140 | + $out = array(); |
|
141 | + |
|
142 | + if ($this->outputMethods) { |
|
143 | + $ref = new ReflectionObject($obj); |
|
144 | + |
|
145 | + foreach ($ref->getMethods() as $method) { |
|
146 | + if (!$method->isPublic()) { |
|
147 | + continue; |
|
148 | + } |
|
149 | + |
|
150 | + if (empty($out['method'])) { |
|
151 | + $out['method'] = ''; |
|
152 | + } |
|
153 | + |
|
154 | + $params = array(); |
|
155 | + foreach ($method->getParameters() as $param) { |
|
156 | + $params[] = ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName() . ($param->isOptional() ? ' = ' . var_export($param->getDefaultValue(), true) : ''); |
|
157 | + } |
|
158 | + |
|
159 | + $out['method'] .= '(method) ' . $method->getName() . '(' . implode(', ', $params) . ')<br />'; |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + foreach ($list as $attributeName => $attributeValue) { |
|
164 | + if (property_exists($obj, $attributeName)) { |
|
165 | + $key = 'public'; |
|
166 | + } elseif (substr($attributeName, 0, 3) === "\0*\0") { |
|
167 | + $key = 'protected'; |
|
168 | + $attributeName = substr($attributeName, 3); |
|
169 | + } else { |
|
170 | + $key = 'private'; |
|
171 | + $attributeName = substr($attributeName, $protectedLength); |
|
172 | + } |
|
173 | + |
|
174 | + if (empty($out[$key])) { |
|
175 | + $out[$key] = ''; |
|
176 | + } |
|
177 | + |
|
178 | + $out[$key] .= '(' . $key . ') '; |
|
179 | + |
|
180 | + if (is_array($attributeValue)) { |
|
181 | + $out[$key] .= $attributeName . ' (array):<br /> |
|
182 | 182 | <div style="padding-left:20px;">' . $this->export($attributeValue, false) . '</div>'; |
183 | - } elseif (is_object($attributeValue)) { |
|
184 | - $out[$key] .= $this->exportObj($attributeName . ' (object: ' . get_class($attributeValue) . '):', $attributeValue); |
|
185 | - } else { |
|
186 | - $out[$key] .= $this->exportVar($attributeName . ' = ', $attributeValue); |
|
187 | - } |
|
188 | - } |
|
183 | + } elseif (is_object($attributeValue)) { |
|
184 | + $out[$key] .= $this->exportObj($attributeName . ' (object: ' . get_class($attributeValue) . '):', $attributeValue); |
|
185 | + } else { |
|
186 | + $out[$key] .= $this->exportVar($attributeName . ' = ', $attributeValue); |
|
187 | + } |
|
188 | + } |
|
189 | 189 | |
190 | - $return = $i . '<br /><div style="padding-left:20px;">'; |
|
190 | + $return = $i . '<br /><div style="padding-left:20px;">'; |
|
191 | 191 | |
192 | - if (!empty($out['method'])) { |
|
193 | - $return .= $out['method']; |
|
194 | - } |
|
192 | + if (!empty($out['method'])) { |
|
193 | + $return .= $out['method']; |
|
194 | + } |
|
195 | 195 | |
196 | - if (!empty($out['public'])) { |
|
197 | - $return .= $out['public']; |
|
198 | - } |
|
196 | + if (!empty($out['public'])) { |
|
197 | + $return .= $out['public']; |
|
198 | + } |
|
199 | 199 | |
200 | - if (!empty($out['protected'])) { |
|
201 | - $return .= $out['protected']; |
|
202 | - } |
|
200 | + if (!empty($out['protected'])) { |
|
201 | + $return .= $out['protected']; |
|
202 | + } |
|
203 | 203 | |
204 | - if (!empty($out['private'])) { |
|
205 | - $return .= $out['private']; |
|
206 | - } |
|
204 | + if (!empty($out['private'])) { |
|
205 | + $return .= $out['private']; |
|
206 | + } |
|
207 | 207 | |
208 | - return $return . '</div>'; |
|
209 | - } |
|
208 | + return $return . '</div>'; |
|
209 | + } |
|
210 | 210 | } |
@@ -34,61 +34,61 @@ |
||
34 | 34 | */ |
35 | 35 | class PluginCounter extends Plugin |
36 | 36 | { |
37 | - protected $counters = array(); |
|
37 | + protected $counters = array(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @param null $start |
|
42 | - * @param null $skip |
|
43 | - * @param null $direction |
|
44 | - * @param null $print |
|
45 | - * @param null $assign |
|
46 | - * |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null) |
|
50 | - { |
|
51 | - // init counter |
|
52 | - if (!isset($this->counters[$name])) { |
|
53 | - $this->counters[$name] = array( |
|
54 | - 'count' => $start === null ? 1 : (int)$start, |
|
55 | - 'skip' => $skip === null ? 1 : (int)$skip, |
|
56 | - 'print' => $print === null ? true : (bool)$print, |
|
57 | - 'assign' => $assign === null ? null : (string)$assign, |
|
58 | - 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
59 | - ); |
|
60 | - } // increment |
|
61 | - else { |
|
62 | - // override setting if present |
|
63 | - if ($skip !== null) { |
|
64 | - $this->counters[$name]['skip'] = (int)$skip; |
|
65 | - } |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @param null $start |
|
42 | + * @param null $skip |
|
43 | + * @param null $direction |
|
44 | + * @param null $print |
|
45 | + * @param null $assign |
|
46 | + * |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null) |
|
50 | + { |
|
51 | + // init counter |
|
52 | + if (!isset($this->counters[$name])) { |
|
53 | + $this->counters[$name] = array( |
|
54 | + 'count' => $start === null ? 1 : (int)$start, |
|
55 | + 'skip' => $skip === null ? 1 : (int)$skip, |
|
56 | + 'print' => $print === null ? true : (bool)$print, |
|
57 | + 'assign' => $assign === null ? null : (string)$assign, |
|
58 | + 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
59 | + ); |
|
60 | + } // increment |
|
61 | + else { |
|
62 | + // override setting if present |
|
63 | + if ($skip !== null) { |
|
64 | + $this->counters[$name]['skip'] = (int)$skip; |
|
65 | + } |
|
66 | 66 | |
67 | - if ($direction !== null) { |
|
68 | - $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
69 | - } |
|
67 | + if ($direction !== null) { |
|
68 | + $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
69 | + } |
|
70 | 70 | |
71 | - if ($print !== null) { |
|
72 | - $this->counters[$name]['print'] = (bool)$print; |
|
73 | - } |
|
71 | + if ($print !== null) { |
|
72 | + $this->counters[$name]['print'] = (bool)$print; |
|
73 | + } |
|
74 | 74 | |
75 | - if ($assign !== null) { |
|
76 | - $this->counters[$name]['assign'] = (string)$assign; |
|
77 | - } |
|
75 | + if ($assign !== null) { |
|
76 | + $this->counters[$name]['assign'] = (string)$assign; |
|
77 | + } |
|
78 | 78 | |
79 | - if ($start !== null) { |
|
80 | - $this->counters[$name]['count'] = (int)$start; |
|
81 | - } else { |
|
82 | - $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
83 | - } |
|
84 | - } |
|
79 | + if ($start !== null) { |
|
80 | + $this->counters[$name]['count'] = (int)$start; |
|
81 | + } else { |
|
82 | + $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - $out = $this->counters[$name]['count']; |
|
86 | + $out = $this->counters[$name]['count']; |
|
87 | 87 | |
88 | - if ($this->counters[$name]['assign'] !== null) { |
|
89 | - $this->core->assignInScope($out, $this->counters[$name]['assign']); |
|
90 | - } elseif ($this->counters[$name]['print'] === true) { |
|
91 | - return $out; |
|
92 | - } |
|
93 | - } |
|
88 | + if ($this->counters[$name]['assign'] !== null) { |
|
89 | + $this->core->assignInScope($out, $this->counters[$name]['assign']); |
|
90 | + } elseif ($this->counters[$name]['print'] === true) { |
|
91 | + return $out; |
|
92 | + } |
|
93 | + } |
|
94 | 94 | } |
@@ -51,35 +51,35 @@ |
||
51 | 51 | // init counter |
52 | 52 | if (!isset($this->counters[$name])) { |
53 | 53 | $this->counters[$name] = array( |
54 | - 'count' => $start === null ? 1 : (int)$start, |
|
55 | - 'skip' => $skip === null ? 1 : (int)$skip, |
|
56 | - 'print' => $print === null ? true : (bool)$print, |
|
57 | - 'assign' => $assign === null ? null : (string)$assign, |
|
58 | - 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
54 | + 'count' => $start === null ? 1 : (int) $start, |
|
55 | + 'skip' => $skip === null ? 1 : (int) $skip, |
|
56 | + 'print' => $print === null ? true : (bool) $print, |
|
57 | + 'assign' => $assign === null ? null : (string) $assign, |
|
58 | + 'direction' => strtolower($direction) === 'down' ? -1 : 1, |
|
59 | 59 | ); |
60 | 60 | } // increment |
61 | 61 | else { |
62 | 62 | // override setting if present |
63 | 63 | if ($skip !== null) { |
64 | - $this->counters[$name]['skip'] = (int)$skip; |
|
64 | + $this->counters[$name]['skip'] = (int) $skip; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | if ($direction !== null) { |
68 | - $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
68 | + $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? -1 : 1; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | if ($print !== null) { |
72 | - $this->counters[$name]['print'] = (bool)$print; |
|
72 | + $this->counters[$name]['print'] = (bool) $print; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | if ($assign !== null) { |
76 | - $this->counters[$name]['assign'] = (string)$assign; |
|
76 | + $this->counters[$name]['assign'] = (string) $assign; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | if ($start !== null) { |
80 | - $this->counters[$name]['count'] = (int)$start; |
|
80 | + $this->counters[$name]['count'] = (int) $start; |
|
81 | 81 | } else { |
82 | - $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
82 | + $this->counters[$name]['count'] += ($this->counters[$name]['skip']*$this->counters[$name]['direction']); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 |
@@ -27,47 +27,47 @@ |
||
27 | 27 | */ |
28 | 28 | class PluginForeachelse extends BlockPlugin implements ICompilableBlock |
29 | 29 | { |
30 | - public function init() |
|
31 | - { |
|
32 | - } |
|
30 | + public function init() |
|
31 | + { |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param Compiler $compiler |
|
36 | - * @param array $params |
|
37 | - * @param string $prepend |
|
38 | - * @param string $append |
|
39 | - * @param string $type |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | - { |
|
45 | - $with = &$compiler->findBlock('foreach', true); |
|
34 | + /** |
|
35 | + * @param Compiler $compiler |
|
36 | + * @param array $params |
|
37 | + * @param string $prepend |
|
38 | + * @param string $append |
|
39 | + * @param string $type |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | + { |
|
45 | + $with = &$compiler->findBlock('foreach', true); |
|
46 | 46 | |
47 | - $params['initialized'] = true; |
|
48 | - $compiler->injectBlock($type, $params); |
|
47 | + $params['initialized'] = true; |
|
48 | + $compiler->injectBlock($type, $params); |
|
49 | 49 | |
50 | - return ''; |
|
51 | - } |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param Compiler $compiler |
|
55 | - * @param array $params |
|
56 | - * @param string $prepend |
|
57 | - * @param string $append |
|
58 | - * @param string $content |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | - { |
|
64 | - if (!isset($params['initialized'])) { |
|
65 | - return ''; |
|
66 | - } |
|
53 | + /** |
|
54 | + * @param Compiler $compiler |
|
55 | + * @param array $params |
|
56 | + * @param string $prepend |
|
57 | + * @param string $append |
|
58 | + * @param string $content |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | + { |
|
64 | + if (!isset($params['initialized'])) { |
|
65 | + return ''; |
|
66 | + } |
|
67 | 67 | |
68 | - $block = &$compiler->getCurrentBlock(); |
|
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
68 | + $block = &$compiler->getCurrentBlock(); |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | - return ''; |
|
72 | - } |
|
71 | + return ''; |
|
72 | + } |
|
73 | 73 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | $block = &$compiler->getCurrentBlock(); |
92 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
92 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
93 | 93 | |
94 | 94 | return ''; |
95 | 95 | } |
@@ -41,234 +41,234 @@ |
||
41 | 41 | */ |
42 | 42 | class PluginIf extends BlockPlugin implements ICompilableBlock, IElseable |
43 | 43 | { |
44 | - /** |
|
45 | - * @param array $rest |
|
46 | - */ |
|
47 | - public function init(array $rest) |
|
48 | - { |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param array $rest |
|
46 | + */ |
|
47 | + public function init(array $rest) |
|
48 | + { |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param array $params |
|
53 | - * @param array $tokens |
|
54 | - * @param Compiler $compiler |
|
55 | - * |
|
56 | - * @return array |
|
57 | - * @throws CompilationException |
|
58 | - */ |
|
59 | - public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
60 | - { |
|
61 | - $p = array(); |
|
51 | + /** |
|
52 | + * @param array $params |
|
53 | + * @param array $tokens |
|
54 | + * @param Compiler $compiler |
|
55 | + * |
|
56 | + * @return array |
|
57 | + * @throws CompilationException |
|
58 | + */ |
|
59 | + public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
60 | + { |
|
61 | + $p = array(); |
|
62 | 62 | |
63 | - reset($params); |
|
64 | - while (list($k, $v) = each($params)) { |
|
65 | - $v = (string)$v; |
|
66 | - if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
67 | - $vmod = strtolower(substr($v, 1, - 1)); |
|
68 | - } else { |
|
69 | - $vmod = strtolower($v); |
|
70 | - } |
|
71 | - switch ($vmod) { |
|
63 | + reset($params); |
|
64 | + while (list($k, $v) = each($params)) { |
|
65 | + $v = (string)$v; |
|
66 | + if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
67 | + $vmod = strtolower(substr($v, 1, - 1)); |
|
68 | + } else { |
|
69 | + $vmod = strtolower($v); |
|
70 | + } |
|
71 | + switch ($vmod) { |
|
72 | 72 | |
73 | - case 'and': |
|
74 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | - $p[] = '&&'; |
|
76 | - } else { |
|
77 | - $p[] = $v; |
|
78 | - } |
|
79 | - break; |
|
80 | - case 'or': |
|
81 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | - $p[] = '||'; |
|
83 | - } else { |
|
84 | - $p[] = $v; |
|
85 | - } |
|
86 | - break; |
|
87 | - case 'xor': |
|
88 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | - $p[] = '^'; |
|
90 | - } else { |
|
91 | - $p[] = $v; |
|
92 | - } |
|
93 | - break; |
|
94 | - case 'eq': |
|
95 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | - $p[] = '=='; |
|
97 | - } else { |
|
98 | - $p[] = $v; |
|
99 | - } |
|
100 | - break; |
|
101 | - case 'ne': |
|
102 | - case 'neq': |
|
103 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
104 | - $p[] = '!='; |
|
105 | - } else { |
|
106 | - $p[] = $v; |
|
107 | - } |
|
108 | - break; |
|
109 | - case 'gte': |
|
110 | - case 'ge': |
|
111 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | - $p[] = '>='; |
|
113 | - } else { |
|
114 | - $p[] = $v; |
|
115 | - } |
|
116 | - break; |
|
117 | - case 'lte': |
|
118 | - case 'le': |
|
119 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | - $p[] = '<='; |
|
121 | - } else { |
|
122 | - $p[] = $v; |
|
123 | - } |
|
124 | - break; |
|
125 | - case 'gt': |
|
126 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | - $p[] = '>'; |
|
128 | - } else { |
|
129 | - $p[] = $v; |
|
130 | - } |
|
131 | - break; |
|
132 | - case 'lt': |
|
133 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | - $p[] = '<'; |
|
135 | - } else { |
|
136 | - $p[] = $v; |
|
137 | - } |
|
138 | - break; |
|
139 | - case 'mod': |
|
140 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | - $p[] = '%'; |
|
142 | - } else { |
|
143 | - $p[] = $v; |
|
144 | - } |
|
145 | - break; |
|
146 | - case 'not': |
|
147 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | - $p[] = '!'; |
|
149 | - } else { |
|
150 | - $p[] = $v; |
|
151 | - } |
|
152 | - break; |
|
153 | - case '<>': |
|
154 | - $p[] = '!='; |
|
155 | - break; |
|
156 | - case '==': |
|
157 | - case '!=': |
|
158 | - case '>=': |
|
159 | - case '<=': |
|
160 | - case '>': |
|
161 | - case '<': |
|
162 | - case '===': |
|
163 | - case '!==': |
|
164 | - case '%': |
|
165 | - case '!': |
|
166 | - case '^': |
|
167 | - $p[] = $vmod; |
|
168 | - break; |
|
169 | - case 'is': |
|
170 | - if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | - $p[] = $v; |
|
172 | - break; |
|
173 | - } |
|
174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | - $negate = true; |
|
176 | - next($params); |
|
177 | - } else { |
|
178 | - $negate = false; |
|
179 | - } |
|
180 | - $ptr = 1 + (int)$negate; |
|
181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | - break; |
|
183 | - } |
|
184 | - if (!isset($params[$k + $ptr])) { |
|
185 | - $params[$k + $ptr] = ''; |
|
186 | - } else { |
|
187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | - } |
|
189 | - switch ($params[$k + $ptr]) { |
|
73 | + case 'and': |
|
74 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | + $p[] = '&&'; |
|
76 | + } else { |
|
77 | + $p[] = $v; |
|
78 | + } |
|
79 | + break; |
|
80 | + case 'or': |
|
81 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | + $p[] = '||'; |
|
83 | + } else { |
|
84 | + $p[] = $v; |
|
85 | + } |
|
86 | + break; |
|
87 | + case 'xor': |
|
88 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | + $p[] = '^'; |
|
90 | + } else { |
|
91 | + $p[] = $v; |
|
92 | + } |
|
93 | + break; |
|
94 | + case 'eq': |
|
95 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | + $p[] = '=='; |
|
97 | + } else { |
|
98 | + $p[] = $v; |
|
99 | + } |
|
100 | + break; |
|
101 | + case 'ne': |
|
102 | + case 'neq': |
|
103 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
104 | + $p[] = '!='; |
|
105 | + } else { |
|
106 | + $p[] = $v; |
|
107 | + } |
|
108 | + break; |
|
109 | + case 'gte': |
|
110 | + case 'ge': |
|
111 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | + $p[] = '>='; |
|
113 | + } else { |
|
114 | + $p[] = $v; |
|
115 | + } |
|
116 | + break; |
|
117 | + case 'lte': |
|
118 | + case 'le': |
|
119 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | + $p[] = '<='; |
|
121 | + } else { |
|
122 | + $p[] = $v; |
|
123 | + } |
|
124 | + break; |
|
125 | + case 'gt': |
|
126 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | + $p[] = '>'; |
|
128 | + } else { |
|
129 | + $p[] = $v; |
|
130 | + } |
|
131 | + break; |
|
132 | + case 'lt': |
|
133 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | + $p[] = '<'; |
|
135 | + } else { |
|
136 | + $p[] = $v; |
|
137 | + } |
|
138 | + break; |
|
139 | + case 'mod': |
|
140 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | + $p[] = '%'; |
|
142 | + } else { |
|
143 | + $p[] = $v; |
|
144 | + } |
|
145 | + break; |
|
146 | + case 'not': |
|
147 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | + $p[] = '!'; |
|
149 | + } else { |
|
150 | + $p[] = $v; |
|
151 | + } |
|
152 | + break; |
|
153 | + case '<>': |
|
154 | + $p[] = '!='; |
|
155 | + break; |
|
156 | + case '==': |
|
157 | + case '!=': |
|
158 | + case '>=': |
|
159 | + case '<=': |
|
160 | + case '>': |
|
161 | + case '<': |
|
162 | + case '===': |
|
163 | + case '!==': |
|
164 | + case '%': |
|
165 | + case '!': |
|
166 | + case '^': |
|
167 | + $p[] = $vmod; |
|
168 | + break; |
|
169 | + case 'is': |
|
170 | + if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | + $p[] = $v; |
|
172 | + break; |
|
173 | + } |
|
174 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | + $negate = true; |
|
176 | + next($params); |
|
177 | + } else { |
|
178 | + $negate = false; |
|
179 | + } |
|
180 | + $ptr = 1 + (int)$negate; |
|
181 | + if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | + break; |
|
183 | + } |
|
184 | + if (!isset($params[$k + $ptr])) { |
|
185 | + $params[$k + $ptr] = ''; |
|
186 | + } else { |
|
187 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | + } |
|
189 | + switch ($params[$k + $ptr]) { |
|
190 | 190 | |
191 | - case 'div': |
|
192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | - next($params); |
|
195 | - next($params); |
|
196 | - next($params); |
|
197 | - } else { |
|
198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | - } |
|
200 | - break; |
|
201 | - case 'even': |
|
202 | - $a = array_pop($p); |
|
203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | - $b = $params[$k + $ptr + 2]; |
|
205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | - next($params); |
|
207 | - next($params); |
|
208 | - } else { |
|
209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | - } |
|
211 | - next($params); |
|
212 | - break; |
|
213 | - case 'odd': |
|
214 | - $a = array_pop($p); |
|
215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | - $b = $params[$k + $ptr + 2]; |
|
217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | - next($params); |
|
219 | - next($params); |
|
220 | - } else { |
|
221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | - } |
|
223 | - next($params); |
|
224 | - break; |
|
225 | - default: |
|
226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | - } |
|
228 | - break; |
|
229 | - default: |
|
230 | - $p[] = $v; |
|
231 | - } |
|
232 | - } |
|
191 | + case 'div': |
|
192 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | + next($params); |
|
195 | + next($params); |
|
196 | + next($params); |
|
197 | + } else { |
|
198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | + } |
|
200 | + break; |
|
201 | + case 'even': |
|
202 | + $a = array_pop($p); |
|
203 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | + $b = $params[$k + $ptr + 2]; |
|
205 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | + next($params); |
|
207 | + next($params); |
|
208 | + } else { |
|
209 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | + } |
|
211 | + next($params); |
|
212 | + break; |
|
213 | + case 'odd': |
|
214 | + $a = array_pop($p); |
|
215 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | + $b = $params[$k + $ptr + 2]; |
|
217 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | + next($params); |
|
219 | + next($params); |
|
220 | + } else { |
|
221 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | + } |
|
223 | + next($params); |
|
224 | + break; |
|
225 | + default: |
|
226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | + } |
|
228 | + break; |
|
229 | + default: |
|
230 | + $p[] = $v; |
|
231 | + } |
|
232 | + } |
|
233 | 233 | |
234 | - return $p; |
|
235 | - } |
|
234 | + return $p; |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * @param Compiler $compiler |
|
239 | - * @param array $params |
|
240 | - * @param string $prepend |
|
241 | - * @param string $append |
|
242 | - * @param string $type |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
247 | - { |
|
248 | - return ''; |
|
249 | - } |
|
237 | + /** |
|
238 | + * @param Compiler $compiler |
|
239 | + * @param array $params |
|
240 | + * @param string $prepend |
|
241 | + * @param string $append |
|
242 | + * @param string $type |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
247 | + { |
|
248 | + return ''; |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @param Compiler $compiler |
|
253 | - * @param array $params |
|
254 | - * @param string $prepend |
|
255 | - * @param string $append |
|
256 | - * @param string $content |
|
257 | - * |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
261 | - { |
|
262 | - $tokens = $compiler->getParamTokens($params); |
|
263 | - $params = $compiler->getCompiledParams($params); |
|
264 | - $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
251 | + /** |
|
252 | + * @param Compiler $compiler |
|
253 | + * @param array $params |
|
254 | + * @param string $prepend |
|
255 | + * @param string $append |
|
256 | + * @param string $content |
|
257 | + * |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
261 | + { |
|
262 | + $tokens = $compiler->getParamTokens($params); |
|
263 | + $params = $compiler->getCompiledParams($params); |
|
264 | + $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
265 | 265 | |
266 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
266 | + $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
267 | 267 | |
268 | - if (isset($params['hasElse'])) { |
|
269 | - $post .= $params['hasElse']; |
|
270 | - } |
|
268 | + if (isset($params['hasElse'])) { |
|
269 | + $post .= $params['hasElse']; |
|
270 | + } |
|
271 | 271 | |
272 | - return $pre . $content . $post; |
|
273 | - } |
|
272 | + return $pre . $content . $post; |
|
273 | + } |
|
274 | 274 | } |
@@ -70,164 +70,164 @@ |
||
70 | 70 | } |
71 | 71 | switch ($vmod) { |
72 | 72 | |
73 | - case 'and': |
|
74 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | - $p[] = '&&'; |
|
76 | - } else { |
|
77 | - $p[] = $v; |
|
78 | - } |
|
79 | - break; |
|
80 | - case 'or': |
|
81 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | - $p[] = '||'; |
|
83 | - } else { |
|
84 | - $p[] = $v; |
|
85 | - } |
|
86 | - break; |
|
87 | - case 'xor': |
|
88 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | - $p[] = '^'; |
|
90 | - } else { |
|
91 | - $p[] = $v; |
|
92 | - } |
|
93 | - break; |
|
94 | - case 'eq': |
|
95 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | - $p[] = '=='; |
|
97 | - } else { |
|
98 | - $p[] = $v; |
|
99 | - } |
|
100 | - break; |
|
101 | - case 'ne': |
|
102 | - case 'neq': |
|
103 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
104 | - $p[] = '!='; |
|
105 | - } else { |
|
106 | - $p[] = $v; |
|
107 | - } |
|
108 | - break; |
|
109 | - case 'gte': |
|
110 | - case 'ge': |
|
111 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | - $p[] = '>='; |
|
113 | - } else { |
|
114 | - $p[] = $v; |
|
115 | - } |
|
116 | - break; |
|
117 | - case 'lte': |
|
118 | - case 'le': |
|
119 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | - $p[] = '<='; |
|
121 | - } else { |
|
122 | - $p[] = $v; |
|
123 | - } |
|
124 | - break; |
|
125 | - case 'gt': |
|
126 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | - $p[] = '>'; |
|
128 | - } else { |
|
129 | - $p[] = $v; |
|
130 | - } |
|
131 | - break; |
|
132 | - case 'lt': |
|
133 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | - $p[] = '<'; |
|
135 | - } else { |
|
136 | - $p[] = $v; |
|
137 | - } |
|
138 | - break; |
|
139 | - case 'mod': |
|
140 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | - $p[] = '%'; |
|
142 | - } else { |
|
143 | - $p[] = $v; |
|
144 | - } |
|
145 | - break; |
|
146 | - case 'not': |
|
147 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | - $p[] = '!'; |
|
149 | - } else { |
|
150 | - $p[] = $v; |
|
151 | - } |
|
152 | - break; |
|
153 | - case '<>': |
|
73 | + case 'and': |
|
74 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
75 | + $p[] = '&&'; |
|
76 | + } else { |
|
77 | + $p[] = $v; |
|
78 | + } |
|
79 | + break; |
|
80 | + case 'or': |
|
81 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
82 | + $p[] = '||'; |
|
83 | + } else { |
|
84 | + $p[] = $v; |
|
85 | + } |
|
86 | + break; |
|
87 | + case 'xor': |
|
88 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
89 | + $p[] = '^'; |
|
90 | + } else { |
|
91 | + $p[] = $v; |
|
92 | + } |
|
93 | + break; |
|
94 | + case 'eq': |
|
95 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
96 | + $p[] = '=='; |
|
97 | + } else { |
|
98 | + $p[] = $v; |
|
99 | + } |
|
100 | + break; |
|
101 | + case 'ne': |
|
102 | + case 'neq': |
|
103 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
154 | 104 | $p[] = '!='; |
105 | + } else { |
|
106 | + $p[] = $v; |
|
107 | + } |
|
108 | + break; |
|
109 | + case 'gte': |
|
110 | + case 'ge': |
|
111 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
112 | + $p[] = '>='; |
|
113 | + } else { |
|
114 | + $p[] = $v; |
|
115 | + } |
|
116 | + break; |
|
117 | + case 'lte': |
|
118 | + case 'le': |
|
119 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
120 | + $p[] = '<='; |
|
121 | + } else { |
|
122 | + $p[] = $v; |
|
123 | + } |
|
124 | + break; |
|
125 | + case 'gt': |
|
126 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
127 | + $p[] = '>'; |
|
128 | + } else { |
|
129 | + $p[] = $v; |
|
130 | + } |
|
131 | + break; |
|
132 | + case 'lt': |
|
133 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
134 | + $p[] = '<'; |
|
135 | + } else { |
|
136 | + $p[] = $v; |
|
137 | + } |
|
138 | + break; |
|
139 | + case 'mod': |
|
140 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
141 | + $p[] = '%'; |
|
142 | + } else { |
|
143 | + $p[] = $v; |
|
144 | + } |
|
145 | + break; |
|
146 | + case 'not': |
|
147 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
148 | + $p[] = '!'; |
|
149 | + } else { |
|
150 | + $p[] = $v; |
|
151 | + } |
|
152 | + break; |
|
153 | + case '<>': |
|
154 | + $p[] = '!='; |
|
155 | + break; |
|
156 | + case '==': |
|
157 | + case '!=': |
|
158 | + case '>=': |
|
159 | + case '<=': |
|
160 | + case '>': |
|
161 | + case '<': |
|
162 | + case '===': |
|
163 | + case '!==': |
|
164 | + case '%': |
|
165 | + case '!': |
|
166 | + case '^': |
|
167 | + $p[] = $vmod; |
|
168 | + break; |
|
169 | + case 'is': |
|
170 | + if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | + $p[] = $v; |
|
155 | 172 | break; |
156 | - case '==': |
|
157 | - case '!=': |
|
158 | - case '>=': |
|
159 | - case '<=': |
|
160 | - case '>': |
|
161 | - case '<': |
|
162 | - case '===': |
|
163 | - case '!==': |
|
164 | - case '%': |
|
165 | - case '!': |
|
166 | - case '^': |
|
167 | - $p[] = $vmod; |
|
173 | + } |
|
174 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | + $negate = true; |
|
176 | + next($params); |
|
177 | + } else { |
|
178 | + $negate = false; |
|
179 | + } |
|
180 | + $ptr = 1 + (int)$negate; |
|
181 | + if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
168 | 182 | break; |
169 | - case 'is': |
|
170 | - if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
171 | - $p[] = $v; |
|
172 | - break; |
|
173 | - } |
|
174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | - $negate = true; |
|
176 | - next($params); |
|
177 | - } else { |
|
178 | - $negate = false; |
|
179 | - } |
|
180 | - $ptr = 1 + (int)$negate; |
|
181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | - break; |
|
183 | - } |
|
184 | - if (!isset($params[$k + $ptr])) { |
|
185 | - $params[$k + $ptr] = ''; |
|
186 | - } else { |
|
187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | - } |
|
189 | - switch ($params[$k + $ptr]) { |
|
183 | + } |
|
184 | + if (!isset($params[$k + $ptr])) { |
|
185 | + $params[$k + $ptr] = ''; |
|
186 | + } else { |
|
187 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
188 | + } |
|
189 | + switch ($params[$k + $ptr]) { |
|
190 | 190 | |
191 | - case 'div': |
|
192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | - next($params); |
|
195 | - next($params); |
|
196 | - next($params); |
|
197 | - } else { |
|
198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | - } |
|
200 | - break; |
|
201 | - case 'even': |
|
202 | - $a = array_pop($p); |
|
203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | - $b = $params[$k + $ptr + 2]; |
|
205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | - next($params); |
|
207 | - next($params); |
|
208 | - } else { |
|
209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | - } |
|
211 | - next($params); |
|
212 | - break; |
|
213 | - case 'odd': |
|
214 | - $a = array_pop($p); |
|
215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | - $b = $params[$k + $ptr + 2]; |
|
217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | - next($params); |
|
219 | - next($params); |
|
220 | - } else { |
|
221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | - } |
|
223 | - next($params); |
|
224 | - break; |
|
225 | - default: |
|
226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | - } |
|
228 | - break; |
|
191 | + case 'div': |
|
192 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
194 | + next($params); |
|
195 | + next($params); |
|
196 | + next($params); |
|
197 | + } else { |
|
198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
199 | + } |
|
200 | + break; |
|
201 | + case 'even': |
|
202 | + $a = array_pop($p); |
|
203 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | + $b = $params[$k + $ptr + 2]; |
|
205 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
206 | + next($params); |
|
207 | + next($params); |
|
208 | + } else { |
|
209 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
210 | + } |
|
211 | + next($params); |
|
212 | + break; |
|
213 | + case 'odd': |
|
214 | + $a = array_pop($p); |
|
215 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | + $b = $params[$k + $ptr + 2]; |
|
217 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
218 | + next($params); |
|
219 | + next($params); |
|
220 | + } else { |
|
221 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
222 | + } |
|
223 | + next($params); |
|
224 | + break; |
|
229 | 225 | default: |
230 | - $p[] = $v; |
|
226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
227 | + } |
|
228 | + break; |
|
229 | + default: |
|
230 | + $p[] = $v; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | reset($params); |
64 | 64 | while (list($k, $v) = each($params)) { |
65 | - $v = (string)$v; |
|
65 | + $v = (string) $v; |
|
66 | 66 | if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
67 | 67 | $vmod = strtolower(substr($v, 1, - 1)); |
68 | 68 | } else { |
@@ -171,59 +171,59 @@ discard block |
||
171 | 171 | $p[] = $v; |
172 | 172 | break; |
173 | 173 | } |
174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
174 | + if (isset($params[$k+1]) && strtolower(trim($params[$k+1], '"\'')) === 'not' && $tokens[$k+1] === Compiler::T_UNQUOTED_STRING) { |
|
175 | 175 | $negate = true; |
176 | 176 | next($params); |
177 | 177 | } else { |
178 | 178 | $negate = false; |
179 | 179 | } |
180 | - $ptr = 1 + (int)$negate; |
|
181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
180 | + $ptr = 1+(int) $negate; |
|
181 | + if ($tokens[$k+$ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
182 | 182 | break; |
183 | 183 | } |
184 | - if (!isset($params[$k + $ptr])) { |
|
185 | - $params[$k + $ptr] = ''; |
|
184 | + if (!isset($params[$k+$ptr])) { |
|
185 | + $params[$k+$ptr] = ''; |
|
186 | 186 | } else { |
187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
187 | + $params[$k+$ptr] = trim($params[$k+$ptr], '"\''); |
|
188 | 188 | } |
189 | - switch ($params[$k + $ptr]) { |
|
189 | + switch ($params[$k+$ptr]) { |
|
190 | 190 | |
191 | 191 | case 'div': |
192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
192 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
193 | + $p[] = ' % '.$params[$k+$ptr+2].' '.($negate ? '!' : '=').'== 0'; |
|
194 | 194 | next($params); |
195 | 195 | next($params); |
196 | 196 | next($params); |
197 | 197 | } else { |
198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate ? 'not ' : '').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2]); |
|
199 | 199 | } |
200 | 200 | break; |
201 | 201 | case 'even': |
202 | 202 | $a = array_pop($p); |
203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
204 | - $b = $params[$k + $ptr + 2]; |
|
205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
203 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
204 | + $b = $params[$k+$ptr+2]; |
|
205 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '!' : '=').'== 0'; |
|
206 | 206 | next($params); |
207 | 207 | next($params); |
208 | 208 | } else { |
209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
209 | + $p[] = $a.' % 2 '.($negate ? '!' : '=').'== 0'; |
|
210 | 210 | } |
211 | 211 | next($params); |
212 | 212 | break; |
213 | 213 | case 'odd': |
214 | 214 | $a = array_pop($p); |
215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
216 | - $b = $params[$k + $ptr + 2]; |
|
217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
215 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
216 | + $b = $params[$k+$ptr+2]; |
|
217 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '=' : '!').'== 0'; |
|
218 | 218 | next($params); |
219 | 219 | next($params); |
220 | 220 | } else { |
221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
221 | + $p[] = $a.' % 2 '.($negate ? '=' : '!').'== 0'; |
|
222 | 222 | } |
223 | 223 | next($params); |
224 | 224 | break; |
225 | 225 | default: |
226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1]); |
|
227 | 227 | } |
228 | 228 | break; |
229 | 229 | default: |
@@ -261,14 +261,14 @@ discard block |
||
261 | 261 | { |
262 | 262 | $tokens = $compiler->getParamTokens($params); |
263 | 263 | $params = $compiler->getCompiledParams($params); |
264 | - $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
264 | + $pre = Compiler::PHP_OPEN.'if ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Compiler::PHP_CLOSE; |
|
265 | 265 | |
266 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
266 | + $post = Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
267 | 267 | |
268 | 268 | if (isset($params['hasElse'])) { |
269 | 269 | $post .= $params['hasElse']; |
270 | 270 | } |
271 | 271 | |
272 | - return $pre . $content . $post; |
|
272 | + return $pre.$content.$post; |
|
273 | 273 | } |
274 | 274 | } |
@@ -29,38 +29,38 @@ |
||
29 | 29 | */ |
30 | 30 | class PluginBlock extends BlockPlugin implements ICompilableBlock |
31 | 31 | { |
32 | - /** |
|
33 | - * @param string $name |
|
34 | - */ |
|
35 | - public function init($name = '') |
|
36 | - { |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param string $name |
|
34 | + */ |
|
35 | + public function init($name = '') |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Compiler $compiler |
|
41 | - * @param array $params |
|
42 | - * @param string $prepend |
|
43 | - * @param string $append |
|
44 | - * @param string $type |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
49 | - { |
|
50 | - return ''; |
|
51 | - } |
|
39 | + /** |
|
40 | + * @param Compiler $compiler |
|
41 | + * @param array $params |
|
42 | + * @param string $prepend |
|
43 | + * @param string $append |
|
44 | + * @param string $type |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
49 | + { |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param Compiler $compiler |
|
55 | - * @param array $params |
|
56 | - * @param string $prepend |
|
57 | - * @param string $append |
|
58 | - * @param string $content |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | - { |
|
64 | - return $content; |
|
65 | - } |
|
53 | + /** |
|
54 | + * @param Compiler $compiler |
|
55 | + * @param array $params |
|
56 | + * @param string $prepend |
|
57 | + * @param string $append |
|
58 | + * @param string $content |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | + { |
|
64 | + return $content; |
|
65 | + } |
|
66 | 66 | } |
@@ -28,69 +28,69 @@ |
||
28 | 28 | */ |
29 | 29 | class PluginSmartyinterface extends BlockPlugin implements ICompilableBlock |
30 | 30 | { |
31 | - /** |
|
32 | - * @param $__funcname |
|
33 | - * @param $__functype |
|
34 | - * @param array $rest |
|
35 | - */ |
|
36 | - public function init($__funcname, $__functype, array $rest = array()) |
|
37 | - { |
|
38 | - } |
|
31 | + /** |
|
32 | + * @param $__funcname |
|
33 | + * @param $__functype |
|
34 | + * @param array $rest |
|
35 | + */ |
|
36 | + public function init($__funcname, $__functype, array $rest = array()) |
|
37 | + { |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param Compiler $compiler |
|
42 | - * @param array $params |
|
43 | - * @param string $prepend |
|
44 | - * @param string $append |
|
45 | - * @param string $type |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
50 | - { |
|
51 | - $params = $compiler->getCompiledParams($params); |
|
52 | - $func = $params['__funcname']; |
|
53 | - $pluginType = $params['__functype']; |
|
54 | - $params = $params['*']; |
|
40 | + /** |
|
41 | + * @param Compiler $compiler |
|
42 | + * @param array $params |
|
43 | + * @param string $prepend |
|
44 | + * @param string $append |
|
45 | + * @param string $type |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
50 | + { |
|
51 | + $params = $compiler->getCompiledParams($params); |
|
52 | + $func = $params['__funcname']; |
|
53 | + $pluginType = $params['__functype']; |
|
54 | + $params = $params['*']; |
|
55 | 55 | |
56 | - if ($pluginType & Core::CUSTOM_PLUGIN) { |
|
57 | - $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
58 | - $callback = $customPlugins[$func]['callback']; |
|
59 | - if (is_array($callback)) { |
|
60 | - if (is_object($callback[0])) { |
|
61 | - $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
62 | - } else { |
|
63 | - $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
64 | - } |
|
65 | - } else { |
|
66 | - $callback = $callback . '('; |
|
67 | - } |
|
68 | - } else { |
|
69 | - $callback = 'smarty_block_' . $func . '('; |
|
70 | - } |
|
56 | + if ($pluginType & Core::CUSTOM_PLUGIN) { |
|
57 | + $customPlugins = $compiler->getDwoo()->getCustomPlugins(); |
|
58 | + $callback = $customPlugins[$func]['callback']; |
|
59 | + if (is_array($callback)) { |
|
60 | + if (is_object($callback[0])) { |
|
61 | + $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
62 | + } else { |
|
63 | + $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
64 | + } |
|
65 | + } else { |
|
66 | + $callback = $callback . '('; |
|
67 | + } |
|
68 | + } else { |
|
69 | + $callback = 'smarty_block_' . $func . '('; |
|
70 | + } |
|
71 | 71 | |
72 | - $paramsOut = ''; |
|
73 | - foreach ($params as $i => $p) { |
|
74 | - $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
75 | - } |
|
72 | + $paramsOut = ''; |
|
73 | + foreach ($params as $i => $p) { |
|
74 | + $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
75 | + } |
|
76 | 76 | |
77 | - $curBlock = &$compiler->getCurrentBlock(); |
|
78 | - $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
77 | + $curBlock = &$compiler->getCurrentBlock(); |
|
78 | + $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
79 | 79 | |
80 | - return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
81 | - } |
|
80 | + return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param Compiler $compiler |
|
85 | - * @param array $params |
|
86 | - * @param string $prepend |
|
87 | - * @param string $append |
|
88 | - * @param string $content |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
93 | - { |
|
94 | - return $content . $params['postOut']; |
|
95 | - } |
|
83 | + /** |
|
84 | + * @param Compiler $compiler |
|
85 | + * @param array $params |
|
86 | + * @param string $prepend |
|
87 | + * @param string $append |
|
88 | + * @param string $content |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
93 | + { |
|
94 | + return $content . $params['postOut']; |
|
95 | + } |
|
96 | 96 | } |
@@ -58,26 +58,26 @@ discard block |
||
58 | 58 | $callback = $customPlugins[$func]['callback']; |
59 | 59 | if (is_array($callback)) { |
60 | 60 | if (is_object($callback[0])) { |
61 | - $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; |
|
61 | + $callback = '$this->customPlugins[\''.$func.'\'][0]->'.$callback[1].'('; |
|
62 | 62 | } else { |
63 | - $callback = '' . $callback[0] . '::' . $callback[1] . '('; |
|
63 | + $callback = ''.$callback[0].'::'.$callback[1].'('; |
|
64 | 64 | } |
65 | 65 | } else { |
66 | - $callback = $callback . '('; |
|
66 | + $callback = $callback.'('; |
|
67 | 67 | } |
68 | 68 | } else { |
69 | - $callback = 'smarty_block_' . $func . '('; |
|
69 | + $callback = 'smarty_block_'.$func.'('; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $paramsOut = ''; |
73 | 73 | foreach ($params as $i => $p) { |
74 | - $paramsOut .= var_export($i, true) . ' => ' . $p . ','; |
|
74 | + $paramsOut .= var_export($i, true).' => '.$p.','; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $curBlock = &$compiler->getCurrentBlock(); |
78 | - $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; |
|
78 | + $curBlock['params']['postOut'] = Compiler::PHP_OPEN.' $_block_content = ob_get_clean(); $_block_repeat=false; echo '.$callback.'$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);'.Compiler::PHP_CLOSE; |
|
79 | 79 | |
80 | - return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; |
|
80 | + return Compiler::PHP_OPEN.$prepend.' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array('.$paramsOut.'); $_block_repeat=true; '.$callback.'$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();'.Compiler::PHP_CLOSE; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -91,6 +91,6 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
93 | 93 | { |
94 | - return $content . $params['postOut']; |
|
94 | + return $content.$params['postOut']; |
|
95 | 95 | } |
96 | 96 | } |
@@ -27,47 +27,47 @@ |
||
27 | 27 | */ |
28 | 28 | class PluginWithelse extends BlockPlugin implements ICompilableBlock |
29 | 29 | { |
30 | - public function init() |
|
31 | - { |
|
32 | - } |
|
30 | + public function init() |
|
31 | + { |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param Compiler $compiler |
|
36 | - * @param array $params |
|
37 | - * @param string $prepend |
|
38 | - * @param string $append |
|
39 | - * @param string $type |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | - { |
|
45 | - $with = &$compiler->findBlock('with', true); |
|
34 | + /** |
|
35 | + * @param Compiler $compiler |
|
36 | + * @param array $params |
|
37 | + * @param string $prepend |
|
38 | + * @param string $append |
|
39 | + * @param string $type |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
44 | + { |
|
45 | + $with = &$compiler->findBlock('with', true); |
|
46 | 46 | |
47 | - $params['initialized'] = true; |
|
48 | - $compiler->injectBlock($type, $params); |
|
47 | + $params['initialized'] = true; |
|
48 | + $compiler->injectBlock($type, $params); |
|
49 | 49 | |
50 | - return ''; |
|
51 | - } |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param Compiler $compiler |
|
55 | - * @param array $params |
|
56 | - * @param string $prepend |
|
57 | - * @param string $append |
|
58 | - * @param string $content |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | - { |
|
64 | - if (!isset($params['initialized'])) { |
|
65 | - return ''; |
|
66 | - } |
|
53 | + /** |
|
54 | + * @param Compiler $compiler |
|
55 | + * @param array $params |
|
56 | + * @param string $prepend |
|
57 | + * @param string $append |
|
58 | + * @param string $content |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
63 | + { |
|
64 | + if (!isset($params['initialized'])) { |
|
65 | + return ''; |
|
66 | + } |
|
67 | 67 | |
68 | - $block = &$compiler->getCurrentBlock(); |
|
69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
68 | + $block = &$compiler->getCurrentBlock(); |
|
69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
70 | 70 | |
71 | - return ''; |
|
72 | - } |
|
71 | + return ''; |
|
72 | + } |
|
73 | 73 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | $block = &$compiler->getCurrentBlock(); |
92 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
92 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
93 | 93 | |
94 | 94 | return ''; |
95 | 95 | } |