From d679a3d789d1d1e535bdce189893b5a9bb6a001b Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Mon, 25 Apr 2016 04:26:30 +0300 Subject: [PATCH] [5.2] Add @elsecan and @elsecannot blade directives (#13256) * add elsecan and elsecannot blade directives * use container resolving of the Gate class --- .../View/Compilers/BladeCompiler.php | 22 +++++++++++++++++++ tests/View/ViewBladeCompilerTest.php | 8 +++++++ 2 files changed, 30 insertions(+) diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index 6edcbb63a017..98417bf211e6 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -628,6 +628,17 @@ protected function compileCan($expression) return "check{$expression}): ?>"; } + /** + * Compile the else-can statements into valid PHP. + * + * @param string $expression + * @return string + */ + protected function compileElsecan($expression) + { + return "check{$expression}): ?>"; + } + /** * Compile the cannot statements into valid PHP. * @@ -639,6 +650,17 @@ protected function compileCannot($expression) return "denies{$expression}): ?>"; } + /** + * Compile the else-can statements into valid PHP. + * + * @param string $expression + * @return string + */ + protected function compileElsecannot($expression) + { + return "denies{$expression}): ?>"; + } + /** * Compile the if statements into valid PHP. * diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index f276fa31af66..e92f12dd6093 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -257,9 +257,13 @@ public function testCanStatementsAreCompiled() $compiler = new BladeCompiler($this->getFiles(), __DIR__); $string = '@can (\'update\', [$post]) breeze +@elsecan(\'delete\', [$post]) +sneeze @endcan'; $expected = 'check(\'update\', [$post])): ?> breeze +check(\'delete\', [$post])): ?> +sneeze '; $this->assertEquals($expected, $compiler->compileString($string)); } @@ -269,9 +273,13 @@ public function testCannotStatementsAreCompiled() $compiler = new BladeCompiler($this->getFiles(), __DIR__); $string = '@cannot (\'update\', [$post]) breeze +@elsecannot(\'delete\', [$post]) +sneeze @endcannot'; $expected = 'denies(\'update\', [$post])): ?> breeze +denies(\'delete\', [$post])): ?> +sneeze '; $this->assertEquals($expected, $compiler->compileString($string)); }