123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
-
- namespace Illuminate\View\Compilers\Concerns;
-
- trait CompilesConditionals
- {
- /**
- * Identifier for the first case in switch statement.
- *
- * @var bool
- */
- protected $firstCaseInSwitch = true;
-
- /**
- * Compile the if-auth statements into valid PHP.
- *
- * @param string|null $guard
- * @return string
- */
- protected function compileAuth($guard = null)
- {
- $guard = is_null($guard) ? '()' : $guard;
-
- return "<?php if(auth()->guard{$guard}->check()): ?>";
- }
-
- /**
- * Compile the else-auth statements into valid PHP.
- *
- * @param string|null $guard
- * @return string
- */
- protected function compileElseAuth($guard = null)
- {
- $guard = is_null($guard) ? '()' : $guard;
-
- return "<?php elseif(auth()->guard{$guard}->check()): ?>";
- }
-
- /**
- * Compile the end-auth statements into valid PHP.
- *
- * @return string
- */
- protected function compileEndAuth()
- {
- return '<?php endif; ?>';
- }
-
- /**
- * Compile the if-guest statements into valid PHP.
- *
- * @param string|null $guard
- * @return string
- */
- protected function compileGuest($guard = null)
- {
- $guard = is_null($guard) ? '()' : $guard;
-
- return "<?php if(auth()->guard{$guard}->guest()): ?>";
- }
-
- /**
- * Compile the else-guest statements into valid PHP.
- *
- * @param string|null $guard
- * @return string
- */
- protected function compileElseGuest($guard = null)
- {
- $guard = is_null($guard) ? '()' : $guard;
-
- return "<?php elseif(auth()->guard{$guard}->guest()): ?>";
- }
-
- /**
- * Compile the end-guest statements into valid PHP.
- *
- * @return string
- */
- protected function compileEndGuest()
- {
- return '<?php endif; ?>';
- }
-
- /**
- * Compile the has-section statements into valid PHP.
- *
- * @param string $expression
- * @return string
- */
- protected function compileHasSection($expression)
- {
- return "<?php if (! empty(trim(\$__env->yieldContent{$expression}))): ?>";
- }
-
- /**
- * Compile the if statements into valid PHP.
- *
- * @param string $expression
- * @return string
- */
- protected function compileIf($expression)
- {
- return "<?php if{$expression}: ?>";
- }
-
- /**
- * Compile the unless statements into valid PHP.
- *
- * @param string $expression
- * @return string
- */
- protected function compileUnless($expression)
- {
- return "<?php if (! {$expression}): ?>";
- }
-
- /**
- * Compile the else-if statements into valid PHP.
- *
- * @param string $expression
- * @return string
- */
- protected function compileElseif($expression)
- {
- return "<?php elseif{$expression}: ?>";
- }
-
- /**
- * Compile the else statements into valid PHP.
- *
- * @return string
- */
- protected function compileElse()
- {
- return '<?php else: ?>';
- }
-
- /**
- * Compile the end-if statements into valid PHP.
- *
- * @return string
- */
- protected function compileEndif()
- {
- return '<?php endif; ?>';
- }
-
- /**
- * Compile the end-unless statements into valid PHP.
- *
- * @return string
- */
- protected function compileEndunless()
- {
- return '<?php endif; ?>';
- }
-
- /**
- * Compile the if-isset statements into valid PHP.
- *
- * @param string $expression
- * @return string
- */
- protected function compileIsset($expression)
- {
- return "<?php if(isset{$expression}): ?>";
- }
-
- /**
- * Compile the end-isset statements into valid PHP.
- *
- * @return string
- */
- protected function compileEndIsset()
- {
- return '<?php endif; ?>';
- }
-
- /**
- * Compile the switch statements into valid PHP.
- *
- * @param string $expression
- * @return string
- */
- protected function compileSwitch($expression)
- {
- $this->firstCaseInSwitch = true;
-
- return "<?php switch{$expression}:";
- }
-
- /**
- * Compile the case statements into valid PHP.
- *
- * @param string $expression
- * @return string
- */
- protected function compileCase($expression)
- {
- if ($this->firstCaseInSwitch) {
- $this->firstCaseInSwitch = false;
-
- return "case {$expression}: ?>";
- }
-
- return "<?php case {$expression}: ?>";
- }
-
- /**
- * Compile the default statements in switch case into valid PHP.
- *
- * @return string
- */
- protected function compileDefault()
- {
- return '<?php default: ?>';
- }
-
- /**
- * Compile the end switch statements into valid PHP.
- *
- * @return string
- */
- protected function compileEndSwitch()
- {
- return '<?php endswitch; ?>';
- }
- }
|