From 27c247c15b65ec566317fa886020b62233b7a05a Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Mon, 7 May 2018 23:34:29 +0800 Subject: [PATCH] Add @canany and @elsecanany blade directive --- .../Concerns/CompilesAuthorizations.php | 32 +++++++++++++++++++ .../View/Blade/BladeCananyStatementsTest.php | 21 ++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/View/Blade/BladeCananyStatementsTest.php diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesAuthorizations.php b/src/Illuminate/View/Compilers/Concerns/CompilesAuthorizations.php index 39119ec68f49..4f969982c17b 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesAuthorizations.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesAuthorizations.php @@ -26,6 +26,17 @@ protected function compileCannot($expression) return "denies{$expression}): ?>"; } + /** + * Compile the canany statements into valid PHP. + * + * @param string $expression + * @return string + */ + protected function compileCanany($expression) + { + return "any{$expression}): ?>"; + } + /** * Compile the else-can statements into valid PHP. * @@ -48,6 +59,17 @@ protected function compileElsecannot($expression) return "denies{$expression}): ?>"; } + /** + * Compile the else-canany statements into valid PHP. + * + * @param string $expression + * @return string + */ + protected function compileElsecanany($expression) + { + return "any{$expression}): ?>"; + } + /** * Compile the end-can statements into valid PHP. * @@ -67,4 +89,14 @@ protected function compileEndcannot() { return ''; } + + /** + * Compile the end-canany statements into valid PHP. + * + * @return string + */ + protected function compileEndcanany() + { + return ''; + } } diff --git a/tests/View/Blade/BladeCananyStatementsTest.php b/tests/View/Blade/BladeCananyStatementsTest.php new file mode 100644 index 000000000000..59a67b3b62b3 --- /dev/null +++ b/tests/View/Blade/BladeCananyStatementsTest.php @@ -0,0 +1,21 @@ +any([\'create\', \'update\'], [$post])): ?> +breeze +any([\'delete\', \'approve\'], [$post])): ?> +sneeze +'; + $this->assertEquals($expected, $this->compiler->compileString($string)); + } +}