Skip to content
Newer
Older
100644 364 lines (318 sloc) 7.99 KB
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
1 <?php
2
df2dac1 @arshaw makefile and renamed some files
authored Mar 27, 2010
3 /*
4
5 PHP Template Inheritance
6 ------------------------
7 Version: @VERSION
8 Released: @DATE
9 Website: http://phpti.com/
10 Author: Adam Shaw (http://arshaw.com/)
486b0fa @arshaw better filter method behavior, handling mismatching endblocks, improv…
authored Mar 28, 2010
11 Released under the MIT License (license.txt)
df2dac1 @arshaw makefile and renamed some files
authored Mar 28, 2010
12
13 */
486b0fa @arshaw better filter method behavior, handling mismatching endblocks, improv…
authored Mar 28, 2010
14 require_once dirname(__FILE__) . '/debug.php'; // line will be removed by Makefile
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
15
a90622b @arshaw refactored things, added error reporting for mismatched tags
authored Dec 7, 2009
16
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 27, 2010
17 $GLOBALS['_ti_base'] = null;
18 $GLOBALS['_ti_stack'] = null;
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
19
20
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 23, 2010
21 function emptyblock($name) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
22 $trace = _ti_callingTrace();
23 _ti_init($trace);
24 _ti_insertBlock(
25 _ti_newBlock($name, null, $trace)
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
26 );
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
27 }
28
29
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
30 function startblock($name, $filters=null) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
31 $trace = _ti_callingTrace();
32 _ti_init($trace);
33 $stack =& $GLOBALS['_ti_stack'];
34 $stack[] = _ti_newBlock($name, $filters, $trace);
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
35 }
36
37
38 function endblock($name=null) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
39 $trace = _ti_callingTrace();
40 _ti_init($trace);
41 $stack =& $GLOBALS['_ti_stack'];
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
42 if ($stack) {
43 $block = array_pop($stack);
44 if ($name && $name != $block['name']) {
486b0fa @arshaw better filter method behavior, handling mismatching endblocks, improv…
authored Mar 28, 2010
45 _ti_warning("startblock('{$block['name']}') does not match endblock('$name')", $trace);
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
46 }
486b0fa @arshaw better filter method behavior, handling mismatching endblocks, improv…
authored Mar 28, 2010
47 _ti_insertBlock($block);
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 15, 2009
48 }else{
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
49 _ti_warning(
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 25, 2010
50 $name ? "orphan endblock('$name')" : "orphan endblock()",
51 $trace
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
52 );
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
53 }
54 }
55
56
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
57 function superblock() {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
58 if ($GLOBALS['_ti_stack']) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
59 echo getsuperblock();
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
60 }else{
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
61 _ti_warning(
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
62 "superblock() call must be within a block",
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
63 _ti_callingTrace()
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
64 );
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
65 }
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
66 }
67
68
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
69 function getsuperblock() {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
70 $stack =& $GLOBALS['_ti_stack'];
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
71 if ($stack) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
72 $hash =& $GLOBALS['_ti_hash'];
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
73 $block = end($stack);
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
74 if (isset($hash[$block['name']])) {
75 return implode(
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
76 _ti_compile(
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
77 $hash[$block['name']]['block'],
78 ob_get_contents()
79 )
80 );
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
81 }
82 }else{
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
83 _ti_warning(
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
84 "getsuperblock() call must be within a block",
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
85 _ti_callingTrace()
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
86 );
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
87 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
88 return '';
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
89 }
90
91
92 function flushblocks() {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
93 $base =& $GLOBALS['_ti_base'];
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
94 if ($base) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
95 $stack =& $GLOBALS['_ti_stack'];
96 $level =& $GLOBALS['_ti_level'];
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
97 while ($block = array_pop($stack)) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
98 _ti_warning(
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
99 "missing endblock() for startblock('{$block['name']}')",
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
100 _ti_callingTrace(),
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
101 $block['trace']
102 );
103 }
104 while (ob_get_level() > $level) {
105 ob_end_flush(); // will eventually trigger bufferCallback
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
106 }
107 $base = null;
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
108 $stack = null;
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
109 }
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
110 }
111
112
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
113 function blockbase() {
486b0fa @arshaw better filter method behavior, handling mismatching endblocks, improv…
authored Mar 28, 2010
114 _ti_init(_ti_callingTrace());
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
115 }
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
116
117
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
118 function _ti_init($trace) {
119 $base =& $GLOBALS['_ti_base'];
120 if ($base && !_ti_inBaseOrChild($trace)) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
121 flushblocks(); // will set $base to null
122 }
123 if (!$base) {
124 $base = array(
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
125 'trace' => $trace,
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
126 'filters' => null, // purely for compile
127 'children' => array(),
128 'start' => 0, // purely for compile
129 'end' => null
130 );
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
131 $GLOBALS['_ti_level'] = ob_get_level();
132 $GLOBALS['_ti_stack'] = array();
133 $GLOBALS['_ti_hash'] = array();
134 $GLOBALS['_ti_end'] = null;
135 $GLOBALS['_ti_after'] = '';
136 ob_start('_ti_bufferCallback');
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
137 }
138 }
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
139
a90622b @arshaw refactored things, added error reporting for mismatched tags
authored Dec 8, 2009
140
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
141 function _ti_newBlock($name, $filters, $trace) {
142 $base =& $GLOBALS['_ti_base'];
143 $stack =& $GLOBALS['_ti_stack'];
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
144 while ($block = end($stack)) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
145 if (_ti_isSameFile($block['trace'], $trace)) {
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
146 break;
147 }else{
148 array_pop($stack);
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
149 _ti_insertBlock($block);
150 _ti_warning(
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
151 "missing endblock() for startblock('{$block['name']}')",
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
152 _ti_callingTrace(),
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
153 $block['trace']
154 );
155 }
156 }
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
157 if ($base['end'] === null && !_ti_inBase($trace)) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
158 $base['end'] = ob_get_length();
159 }
160 if ($filters) {
161 if (is_string($filters)) {
162 $filters = preg_split('/\s*[,|]\s*/', trim($filters));
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
163 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
164 else if (!is_array($filters)) {
165 $filters = array($filters);
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
166 }
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
167 foreach ($filters as $i => $f) {
486b0fa @arshaw better filter method behavior, handling mismatching endblocks, improv…
authored Mar 28, 2010
168 if ($f && !is_callable($f)) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
169 _ti_warning(
486b0fa @arshaw better filter method behavior, handling mismatching endblocks, improv…
authored Mar 28, 2010
170 is_array($f) ?
171 "filter " . implode('::', $f) . " is not defined":
172 "filter '$f' is not defined", // TODO: better messaging for methods
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
173 $trace
174 );
175 $filters[$i] = null;
176 }
177 }
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
178 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
179 return array(
180 'name' => $name,
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
181 'trace' => $trace,
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
182 'filters' => $filters,
183 'children' => array(),
184 'start' => ob_get_length()
185 );
186 }
187
188
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
189 function _ti_insertBlock($block) { // at this point, $block is done being modified
190 $base =& $GLOBALS['_ti_base'];
191 $stack =& $GLOBALS['_ti_stack'];
192 $hash =& $GLOBALS['_ti_hash'];
193 $end =& $GLOBALS['_ti_end'];
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
194 $block['end'] = $end = ob_get_length();
195 $name = $block['name'];
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
196 if ($stack || _ti_inBase($block['trace'])) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
197 $block_anchor = array(
198 'start' => $block['start'],
199 'end' => $end,
200 'block' => $block
201 );
202 if ($stack) {
203 // nested block
204 $stack[count($stack)-1]['children'][] =& $block_anchor;
3d30634 @arshaw total refactoring for PHP4 support, removed funcblock()
authored Dec 16, 2009
205 }else{
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
206 // top-level block in base
207 $base['children'][] =& $block_anchor;
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
208 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
209 $hash[$name] =& $block_anchor; // same reference as children array
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
210 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
211 else if (isset($hash[$name])) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
212 if (_ti_isSameFile($hash[$name]['block']['trace'], $block['trace'])) {
213 _ti_warning(
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
214 "cannot define another block called '$name'",
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
215 _ti_callingTrace(),
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
216 $block['trace']
217 );
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
218 }else{
219 // top-level block in a child template; override the base's block
220 $hash[$name]['block'] = $block;
a90622b @arshaw refactored things, added error reporting for mismatched tags
authored Dec 8, 2009
221 }
222 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
223 }
224
225
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
226 function _ti_bufferCallback($buffer) {
227 $base =& $GLOBALS['_ti_base'];
228 $stack =& $GLOBALS['_ti_stack'];
229 $end =& $GLOBALS['_ti_end'];
230 $after =& $GLOBALS['_ti_after'];
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
231 if ($base) {
232 while ($block = array_pop($stack)) {
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
233 _ti_insertBlock($block);
234 _ti_warning(
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
235 "missing endblock() for startblock('{$block['name']}')",
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
236 _ti_callingTrace(),
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
237 $block['trace']
238 );
ee2bad2 @arshaw solved trailing whitespace situation, allowed ob functions in funcblo…
authored Dec 5, 2009
239 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
240 if ($base['end'] === null) {
241 $base['end'] = strlen($buffer);
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
242 $end = null; // todo: more explanation
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
243 // means there were no blocks other than the base's
244 }
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
245 $parts = _ti_compile($base, $buffer);
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
246 // remove trailing whitespace from end
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
247 $i = count($parts) - 1;
248 $parts[$i] = rtrim($parts[$i]);
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
249 // if there are child template blocks, preserve output after last one
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
250 if ($end !== null) {
251 $parts[] = substr($buffer, $end);
252 }
253 // for error messages
254 $parts[] = $after;
255 return implode($parts);
256 }else{
ee2bad2 @arshaw solved trailing whitespace situation, allowed ob functions in funcblo…
authored Dec 5, 2009
257 return '';
258 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
259 }
260
261
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
262 function _ti_compile($block, $buffer) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
263 $parts = array();
264 $previ = $block['start'];
265 foreach ($block['children'] as $child_anchor) {
266 $parts[] = substr($buffer, $previ, $child_anchor['start'] - $previ);
267 $parts = array_merge(
268 $parts,
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
269 _ti_compile($child_anchor['block'], $buffer)
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
270 );
271 $previ = $child_anchor['end'];
272 }
273 if ($previ != $block['end']) {
274 // could be a big buffer, so only do substr if necessary
275 $parts[] = substr($buffer, $previ, $block['end'] - $previ);
276 }
277 if ($block['filters']) {
278 $s = implode($parts);
279 foreach ($block['filters'] as $filter) {
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
280 if ($filter) {
281 $s = call_user_func($filter, $s);
282 }
ee2bad2 @arshaw solved trailing whitespace situation, allowed ob functions in funcblo…
authored Dec 5, 2009
283 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
284 return array($s);
ee2bad2 @arshaw solved trailing whitespace situation, allowed ob functions in funcblo…
authored Dec 5, 2009
285 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
286 return $parts;
287 }
288
289
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
290 function _ti_warning($message, $trace, $warning_trace=null) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
291 if (error_reporting() & E_USER_WARNING) {
292 if (defined('STDIN')) {
293 // from command line
294 $format = "\nWarning: %s in %s on line %d\n";
295 }else{
296 // from browser
297 $format = "<br />\n<b>Warning</b>: %s in <b>%s</b> on line <b>%d</b><br />\n";
298 }
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
299 if (!$warning_trace) {
300 $warning_trace = $trace;
301 }
302 $s = sprintf($format, $message, $warning_trace[0]['file'], $warning_trace[0]['line']);
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
303 if (!$GLOBALS['_ti_base'] || _ti_inBase($trace)) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
304 echo $s;
305 }else{
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
306 $GLOBALS['_ti_after'] .= $s;
a90622b @arshaw refactored things, added error reporting for mismatched tags
authored Dec 8, 2009
307 }
308 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
309 }
310
311
312 /* backtrace utilities
313 ------------------------------------------------------------------------*/
314
315
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
316 function _ti_callingTrace() {
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
317 $trace = debug_backtrace();
318 foreach ($trace as $i => $location) {
319 if ($location['file'] !== __FILE__) {
320 return array_slice($trace, $i);
321 }
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
322 }
0e012f8 @arshaw optimized calls to debug_backtrace, important bugfixes with buffering…
authored Mar 26, 2010
323 }
324
325
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
326 function _ti_inBase($trace) {
327 return _ti_isSameFile($trace, $GLOBALS['_ti_base']['trace']);
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
328 }
329
330
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
331 function _ti_inBaseOrChild($trace) {
332 $base_trace = $GLOBALS['_ti_base']['trace'];
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
333 return
334 $trace && $base_trace &&
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
335 _ti_isSubtrace(array_slice($trace, 1), $base_trace) &&
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
336 $trace[0]['file'] === $base_trace[count($base_trace)-count($trace)]['file'];
337 }
338
339
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
340 function _ti_isSameFile($trace1, $trace2) {
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
341 return
342 $trace1 && $trace2 &&
343 $trace1[0]['file'] === $trace2[0]['file'] &&
344 array_slice($trace1, 1) === array_slice($trace2, 1);
345 }
346
347
2bacee3 @arshaw PHP Template Inheritance > PHPTI
authored Mar 28, 2010
348 function _ti_isSubtrace($trace1, $trace2) { // is trace1 a subtrace of trace2
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
349 $len1 = count($trace1);
350 $len2 = count($trace2);
351 if ($len1 > $len2) {
352 return false;
a90622b @arshaw refactored things, added error reporting for mismatched tags
authored Dec 8, 2009
353 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
354 for ($i=0; $i<$len1; $i++) {
355 if ($trace1[$len1-1-$i] !== $trace2[$len2-1-$i]) {
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
356 return false;
357 }
358 }
f756a41 @arshaw total refactor. many new improvements and optimizations
authored Mar 24, 2010
359 return true;
8d5ce16 @arshaw initial commit
authored Dec 5, 2009
360 }
361
362
363 ?>
Something went wrong with that request. Please try again.