File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed
src/Illuminate/View/Compilers/Concerns Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -35,12 +35,17 @@ protected function compileForelse($expression)
3535 }
3636
3737 /**
38- * Compile the for-else-empty statements into valid PHP.
38+ * Compile the for-else-empty and empty statements into valid PHP.
3939 *
40+ * @param string $expression
4041 * @return string
4142 */
42- protected function compileEmpty ()
43+ protected function compileEmpty ($ expression )
4344 {
45+ if ($ expression ) {
46+ return "<?php if(empty {$ expression }): ?> " ;
47+ }
48+
4449 $ empty = '$__empty_ ' .$ this ->forElseCounter --;
4550
4651 return "<?php endforeach; \$__env->popLoop(); \$loop = \$__env->getLastLoop(); if ( {$ empty }): ?> " ;
@@ -56,6 +61,16 @@ protected function compileEndforelse()
5661 return '<?php endif; ?> ' ;
5762 }
5863
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+
5974 /**
6075 * Compile the for statements into valid PHP.
6176 *
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Illuminate \Tests \Blade ;
4+
5+ use Mockery as m ;
6+ use PHPUnit \Framework \TestCase ;
7+ use Illuminate \View \Compilers \BladeCompiler ;
8+
9+ class BladeIfEmptyStatementsTest extends TestCase
10+ {
11+ public function tearDown ()
12+ {
13+ m::close ();
14+ }
15+
16+ public function testIfStatementsAreCompiled ()
17+ {
18+ $ compiler = new BladeCompiler ($ this ->getFiles (), __DIR__ );
19+ $ string = '@empty ($test)
20+ breeze
21+ @endempty ' ;
22+ $ expected = '<?php if(empty($test)): ?>
23+ breeze
24+ <?php endif; ?> ' ;
25+ $ this ->assertEquals ($ expected , $ compiler ->compileString ($ string ));
26+ }
27+
28+ protected function getFiles ()
29+ {
30+ return m::mock ('Illuminate\Filesystem\Filesystem ' );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments