File tree 2 files changed +49
-2
lines changed
src/Illuminate/View/Compilers/Concerns
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)
35
35
}
36
36
37
37
/**
38
- * Compile the for-else-empty statements into valid PHP.
38
+ * Compile the for-else-empty and empty statements into valid PHP.
39
39
*
40
+ * @param string $expression
40
41
* @return string
41
42
*/
42
- protected function compileEmpty ()
43
+ protected function compileEmpty ($ expression )
43
44
{
45
+ if ($ expression ) {
46
+ return "<?php if(empty {$ expression }): ?> " ;
47
+ }
48
+
44
49
$ empty = '$__empty_ ' .$ this ->forElseCounter --;
45
50
46
51
return "<?php endforeach; \$__env->popLoop(); \$loop = \$__env->getLastLoop(); if ( {$ empty }): ?> " ;
@@ -56,6 +61,16 @@ protected function compileEndforelse()
56
61
return '<?php endif; ?> ' ;
57
62
}
58
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
+
59
74
/**
60
75
* Compile the for statements into valid PHP.
61
76
*
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