1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,180 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-namespace Illuminate\View\Compilers\Concerns; |
|
4 |
- |
|
5 |
-trait CompilesLoops |
|
6 |
-{ |
|
7 |
- /** |
|
8 |
- * Counter to keep track of nested forelse statements. |
|
9 |
- * |
|
10 |
- * @var int |
|
11 |
- */ |
|
12 |
- protected $forElseCounter = 0; |
|
13 |
- |
|
14 |
- /** |
|
15 |
- * Compile the for-else statements into valid PHP. |
|
16 |
- * |
|
17 |
- * @param string $expression |
|
18 |
- * @return string |
|
19 |
- */ |
|
20 |
- protected function compileForelse($expression) |
|
21 |
- { |
|
22 |
- $empty = '$__empty_'.++$this->forElseCounter; |
|
23 |
- |
|
24 |
- preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches); |
|
25 |
- |
|
26 |
- $iteratee = trim($matches[1]); |
|
27 |
- |
|
28 |
- $iteration = trim($matches[2]); |
|
29 |
- |
|
30 |
- $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);"; |
|
31 |
- |
|
32 |
- $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();'; |
|
33 |
- |
|
34 |
- return "<?php {$empty} = true; {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} {$empty} = false; ?>"; |
|
35 |
- } |
|
36 |
- |
|
37 |
- /** |
|
38 |
- * Compile the for-else-empty and empty statements into valid PHP. |
|
39 |
- * |
|
40 |
- * @param string $expression |
|
41 |
- * @return string |
|
42 |
- */ |
|
43 |
- protected function compileEmpty($expression) |
|
44 |
- { |
|
45 |
- if ($expression) { |
|
46 |
- return "<?php if(empty{$expression}): ?>"; |
|
47 |
- } |
|
48 |
- |
|
49 |
- $empty = '$__empty_'.$this->forElseCounter--; |
|
50 |
- |
|
51 |
- return "<?php endforeach; \$__env->popLoop(); \$loop = \$__env->getLastLoop(); if ({$empty}): ?>"; |
|
52 |
- } |
|
53 |
- |
|
54 |
- /** |
|
55 |
- * Compile the end-for-else statements into valid PHP. |
|
56 |
- * |
|
57 |
- * @return string |
|
58 |
- */ |
|
59 |
- protected function compileEndforelse() |
|
60 |
- { |
|
61 |
- return '<?php endif; ?>'; |
|
62 |
- } |
|
63 |
- |
|
64 |
- /** |
|
65 |
- * Compile the end-empty statements into valid PHP. |
|
66 |
- * |
|
67 |
- * @return string |
|
68 |
- */ |
|
69 |
- protected function compileEndEmpty() |
|
70 |
- { |
|
71 |
- return '<?php endif; ?>'; |
|
72 |
- } |
|
73 |
- |
|
74 |
- /** |
|
75 |
- * Compile the for statements into valid PHP. |
|
76 |
- * |
|
77 |
- * @param string $expression |
|
78 |
- * @return string |
|
79 |
- */ |
|
80 |
- protected function compileFor($expression) |
|
81 |
- { |
|
82 |
- return "<?php for{$expression}: ?>"; |
|
83 |
- } |
|
84 |
- |
|
85 |
- /** |
|
86 |
- * Compile the for-each statements into valid PHP. |
|
87 |
- * |
|
88 |
- * @param string $expression |
|
89 |
- * @return string |
|
90 |
- */ |
|
91 |
- protected function compileForeach($expression) |
|
92 |
- { |
|
93 |
- preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches); |
|
94 |
- |
|
95 |
- $iteratee = trim($matches[1]); |
|
96 |
- |
|
97 |
- $iteration = trim($matches[2]); |
|
98 |
- |
|
99 |
- $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);"; |
|
100 |
- |
|
101 |
- $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();'; |
|
102 |
- |
|
103 |
- return "<?php {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} ?>"; |
|
104 |
- } |
|
105 |
- |
|
106 |
- /** |
|
107 |
- * Compile the break statements into valid PHP. |
|
108 |
- * |
|
109 |
- * @param string $expression |
|
110 |
- * @return string |
|
111 |
- */ |
|
112 |
- protected function compileBreak($expression) |
|
113 |
- { |
|
114 |
- if ($expression) { |
|
115 |
- preg_match('/\(\s*(-?\d+)\s*\)$/', $expression, $matches); |
|
116 |
- |
|
117 |
- return $matches ? '<?php break '.max(1, $matches[1]).'; ?>' : "<?php if{$expression} break; ?>"; |
|
118 |
- } |
|
119 |
- |
|
120 |
- return '<?php break; ?>'; |
|
121 |
- } |
|
122 |
- |
|
123 |
- /** |
|
124 |
- * Compile the continue statements into valid PHP. |
|
125 |
- * |
|
126 |
- * @param string $expression |
|
127 |
- * @return string |
|
128 |
- */ |
|
129 |
- protected function compileContinue($expression) |
|
130 |
- { |
|
131 |
- if ($expression) { |
|
132 |
- preg_match('/\(\s*(-?\d+)\s*\)$/', $expression, $matches); |
|
133 |
- |
|
134 |
- return $matches ? '<?php continue '.max(1, $matches[1]).'; ?>' : "<?php if{$expression} continue; ?>"; |
|
135 |
- } |
|
136 |
- |
|
137 |
- return '<?php continue; ?>'; |
|
138 |
- } |
|
139 |
- |
|
140 |
- /** |
|
141 |
- * Compile the end-for statements into valid PHP. |
|
142 |
- * |
|
143 |
- * @return string |
|
144 |
- */ |
|
145 |
- protected function compileEndfor() |
|
146 |
- { |
|
147 |
- return '<?php endfor; ?>'; |
|
148 |
- } |
|
149 |
- |
|
150 |
- /** |
|
151 |
- * Compile the end-for-each statements into valid PHP. |
|
152 |
- * |
|
153 |
- * @return string |
|
154 |
- */ |
|
155 |
- protected function compileEndforeach() |
|
156 |
- { |
|
157 |
- return '<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>'; |
|
158 |
- } |
|
159 |
- |
|
160 |
- /** |
|
161 |
- * Compile the while statements into valid PHP. |
|
162 |
- * |
|
163 |
- * @param string $expression |
|
164 |
- * @return string |
|
165 |
- */ |
|
166 |
- protected function compileWhile($expression) |
|
167 |
- { |
|
168 |
- return "<?php while{$expression}: ?>"; |
|
169 |
- } |
|
170 |
- |
|
171 |
- /** |
|
172 |
- * Compile the end-while statements into valid PHP. |
|
173 |
- * |
|
174 |
- * @return string |
|
175 |
- */ |
|
176 |
- protected function compileEndwhile() |
|
177 |
- { |
|
178 |
- return '<?php endwhile; ?>'; |
|
179 |
- } |
|
180 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,180 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+namespace Illuminate\View\Compilers\Concerns; |
|
4 |
+ |
|
5 |
+trait CompilesLoops |
|
6 |
+{ |
|
7 |
+ /** |
|
8 |
+ * Counter to keep track of nested forelse statements. |
|
9 |
+ * |
|
10 |
+ * @var int |
|
11 |
+ */ |
|
12 |
+ protected $forElseCounter = 0; |
|
13 |
+ |
|
14 |
+ /** |
|
15 |
+ * Compile the for-else statements into valid PHP. |
|
16 |
+ * |
|
17 |
+ * @param string $expression |
|
18 |
+ * @return string |
|
19 |
+ */ |
|
20 |
+ protected function compileForelse($expression) |
|
21 |
+ { |
|
22 |
+ $empty = '$__empty_'.++$this->forElseCounter; |
|
23 |
+ |
|
24 |
+ preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches); |
|
25 |
+ |
|
26 |
+ $iteratee = trim($matches[1]); |
|
27 |
+ |
|
28 |
+ $iteration = trim($matches[2]); |
|
29 |
+ |
|
30 |
+ $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);"; |
|
31 |
+ |
|
32 |
+ $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();'; |
|
33 |
+ |
|
34 |
+ return "<?php {$empty} = true; {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} {$empty} = false; ?>"; |
|
35 |
+ } |
|
36 |
+ |
|
37 |
+ /** |
|
38 |
+ * Compile the for-else-empty and empty statements into valid PHP. |
|
39 |
+ * |
|
40 |
+ * @param string $expression |
|
41 |
+ * @return string |
|
42 |
+ */ |
|
43 |
+ protected function compileEmpty($expression) |
|
44 |
+ { |
|
45 |
+ if ($expression) { |
|
46 |
+ return "<?php if(empty{$expression}): ?>"; |
|
47 |
+ } |
|
48 |
+ |
|
49 |
+ $empty = '$__empty_'.$this->forElseCounter--; |
|
50 |
+ |
|
51 |
+ return "<?php endforeach; \$__env->popLoop(); \$loop = \$__env->getLastLoop(); if ({$empty}): ?>"; |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ /** |
|
55 |
+ * Compile the end-for-else statements into valid PHP. |
|
56 |
+ * |
|
57 |
+ * @return string |
|
58 |
+ */ |
|
59 |
+ protected function compileEndforelse() |
|
60 |
+ { |
|
61 |
+ return '<?php endif; ?>'; |
|
62 |
+ } |
|
63 |
+ |
|
64 |
+ /** |
|
65 |
+ * Compile the end-empty statements into valid PHP. |
|
66 |
+ * |
|
67 |
+ * @return string |
|
68 |
+ */ |
|
69 |
+ protected function compileEndEmpty() |
|
70 |
+ { |
|
71 |
+ return '<?php endif; ?>'; |
|
72 |
+ } |
|
73 |
+ |
|
74 |
+ /** |
|
75 |
+ * Compile the for statements into valid PHP. |
|
76 |
+ * |
|
77 |
+ * @param string $expression |
|
78 |
+ * @return string |
|
79 |
+ */ |
|
80 |
+ protected function compileFor($expression) |
|
81 |
+ { |
|
82 |
+ return "<?php for{$expression}: ?>"; |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ /** |
|
86 |
+ * Compile the for-each statements into valid PHP. |
|
87 |
+ * |
|
88 |
+ * @param string $expression |
|
89 |
+ * @return string |
|
90 |
+ */ |
|
91 |
+ protected function compileForeach($expression) |
|
92 |
+ { |
|
93 |
+ preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches); |
|
94 |
+ |
|
95 |
+ $iteratee = trim($matches[1]); |
|
96 |
+ |
|
97 |
+ $iteration = trim($matches[2]); |
|
98 |
+ |
|
99 |
+ $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);"; |
|
100 |
+ |
|
101 |
+ $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();'; |
|
102 |
+ |
|
103 |
+ return "<?php {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} ?>"; |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ /** |
|
107 |
+ * Compile the break statements into valid PHP. |
|
108 |
+ * |
|
109 |
+ * @param string $expression |
|
110 |
+ * @return string |
|
111 |
+ */ |
|
112 |
+ protected function compileBreak($expression) |
|
113 |
+ { |
|
114 |
+ if ($expression) { |
|
115 |
+ preg_match('/\(\s*(-?\d+)\s*\)$/', $expression, $matches); |
|
116 |
+ |
|
117 |
+ return $matches ? '<?php break '.max(1, $matches[1]).'; ?>' : "<?php if{$expression} break; ?>"; |
|
118 |
+ } |
|
119 |
+ |
|
120 |
+ return '<?php break; ?>'; |
|
121 |
+ } |
|
122 |
+ |
|
123 |
+ /** |
|
124 |
+ * Compile the continue statements into valid PHP. |
|
125 |
+ * |
|
126 |
+ * @param string $expression |
|
127 |
+ * @return string |
|
128 |
+ */ |
|
129 |
+ protected function compileContinue($expression) |
|
130 |
+ { |
|
131 |
+ if ($expression) { |
|
132 |
+ preg_match('/\(\s*(-?\d+)\s*\)$/', $expression, $matches); |
|
133 |
+ |
|
134 |
+ return $matches ? '<?php continue '.max(1, $matches[1]).'; ?>' : "<?php if{$expression} continue; ?>"; |
|
135 |
+ } |
|
136 |
+ |
|
137 |
+ return '<?php continue; ?>'; |
|
138 |
+ } |
|
139 |
+ |
|
140 |
+ /** |
|
141 |
+ * Compile the end-for statements into valid PHP. |
|
142 |
+ * |
|
143 |
+ * @return string |
|
144 |
+ */ |
|
145 |
+ protected function compileEndfor() |
|
146 |
+ { |
|
147 |
+ return '<?php endfor; ?>'; |
|
148 |
+ } |
|
149 |
+ |
|
150 |
+ /** |
|
151 |
+ * Compile the end-for-each statements into valid PHP. |
|
152 |
+ * |
|
153 |
+ * @return string |
|
154 |
+ */ |
|
155 |
+ protected function compileEndforeach() |
|
156 |
+ { |
|
157 |
+ return '<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>'; |
|
158 |
+ } |
|
159 |
+ |
|
160 |
+ /** |
|
161 |
+ * Compile the while statements into valid PHP. |
|
162 |
+ * |
|
163 |
+ * @param string $expression |
|
164 |
+ * @return string |
|
165 |
+ */ |
|
166 |
+ protected function compileWhile($expression) |
|
167 |
+ { |
|
168 |
+ return "<?php while{$expression}: ?>"; |
|
169 |
+ } |
|
170 |
+ |
|
171 |
+ /** |
|
172 |
+ * Compile the end-while statements into valid PHP. |
|
173 |
+ * |
|
174 |
+ * @return string |
|
175 |
+ */ |
|
176 |
+ protected function compileEndwhile() |
|
177 |
+ { |
|
178 |
+ return '<?php endwhile; ?>'; |
|
179 |
+ } |
|
180 |
+} |