diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php index 2b1c0e8e41d4..b26494e822b5 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php @@ -373,6 +373,30 @@ protected function compilePushIf($expression) return "startPush({$parts[1]}); ?>"; } + /** + * Compile the else-if push statements into valid PHP. + * + * @param string $expression + * @return string + */ + protected function compileElsePushIf($expression) + { + $parts = explode(',', $this->stripParentheses($expression), 2); + + return "stopPush(); elseif({$parts[0]}): \$__env->startPush({$parts[1]}); ?>"; + } + + /** + * Compile the else push statements into valid PHP. + * + * @param string $expression + * @return string + */ + protected function compileElsePush($expression) + { + return "stopPush(); else: \$__env->startPush{$expression}; ?>"; + } + /** * Compile the end-push statements into valid PHP. * diff --git a/tests/View/Blade/BladePushTest.php b/tests/View/Blade/BladePushTest.php index 103c5c13b692..84f3d3f33bfd 100644 --- a/tests/View/Blade/BladePushTest.php +++ b/tests/View/Blade/BladePushTest.php @@ -65,6 +65,26 @@ public function testPushIfIsCompiled() @endPushIf'; $expected = 'startPush( \'foo\'); ?> test +stopPush(); endif; ?>'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testPushIfElseIsCompiled() + { + $string = '@pushIf(true, \'stack\') +if +@elsePushIf(false, \'stack\') +elseif +@elsePush(\'stack\') +else +@endPushIf'; + $expected = 'startPush( \'stack\'); ?> +if +stopPush(); elseif(false): $__env->startPush( \'stack\'); ?> +elseif +stopPush(); else: $__env->startPush(\'stack\'); ?> +else stopPush(); endif; ?>'; $this->assertEquals($expected, $this->compiler->compileString($string));