|
1 | 1 | <?php namespace Illuminate\View\Compilers; |
2 | 2 |
|
3 | 3 | use Closure; |
| 4 | +use Illuminate\Support\Str; |
4 | 5 |
|
5 | 6 | class BladeCompiler extends Compiler implements CompilerInterface { |
6 | 7 |
|
@@ -620,6 +621,126 @@ protected function compileEndpush($expression) |
620 | 621 | return "<?php \$__env->appendSection(); ?>"; |
621 | 622 | } |
622 | 623 |
|
| 624 | + /** |
| 625 | + * @param string $expression |
| 626 | + * @return string |
| 627 | + */ |
| 628 | + protected function compileSelected($expression) |
| 629 | + { |
| 630 | + return "<?php if{$expression}: echo 'selected'; endif; ?>"; |
| 631 | + } |
| 632 | + |
| 633 | + /** |
| 634 | + * @param string $expression |
| 635 | + * @return string |
| 636 | + */ |
| 637 | + protected function compileChecked($expression) |
| 638 | + { |
| 639 | + return "<?php if{$expression}: echo 'checked'; endif; ?>"; |
| 640 | + } |
| 641 | + |
| 642 | + /** |
| 643 | + * @param string $expression |
| 644 | + * @return string |
| 645 | + */ |
| 646 | + protected function compileDisabled($expression) |
| 647 | + { |
| 648 | + return "<?php if{$expression}: echo 'disabled'; endif; ?>"; |
| 649 | + } |
| 650 | + |
| 651 | + /** |
| 652 | + * @param string $expression |
| 653 | + * @return string |
| 654 | + */ |
| 655 | + protected function compileClass($expression) |
| 656 | + { |
| 657 | + return "class=\"<?php echo e(\Illuminate\Support\Arr::toCssClasses{$expression}); ?>\""; |
| 658 | + } |
| 659 | + |
| 660 | + /** |
| 661 | + * @param string $expression |
| 662 | + * @return string |
| 663 | + */ |
| 664 | + protected function compileJson($expression) |
| 665 | + { |
| 666 | + $safeEncodingOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT; |
| 667 | + $data = $this->stripParentheses($expression); |
| 668 | + |
| 669 | + return "<?php echo json_encode({$data}, {$safeEncodingOptions}, 512) ?>"; |
| 670 | + } |
| 671 | + |
| 672 | + /** |
| 673 | + * @param string $expression |
| 674 | + * @return string |
| 675 | + */ |
| 676 | + protected function compileEnv($expression) |
| 677 | + { |
| 678 | + return "<?php if (app()->environment{$expression}): ?>"; |
| 679 | + } |
| 680 | + |
| 681 | + /** |
| 682 | + * @param string $expression |
| 683 | + * @return string |
| 684 | + */ |
| 685 | + protected function compileEndenv($expression) |
| 686 | + { |
| 687 | + return '<?php endif; ?>'; |
| 688 | + } |
| 689 | + |
| 690 | + /** |
| 691 | + * @param string $expression |
| 692 | + * @return string |
| 693 | + */ |
| 694 | + protected function compileProduction($expression) |
| 695 | + { |
| 696 | + return "<?php if (app()->environment('production')): ?>"; |
| 697 | + } |
| 698 | + |
| 699 | + /** |
| 700 | + * @param string $expression |
| 701 | + * @return string |
| 702 | + */ |
| 703 | + protected function compileEndproduction($expression) |
| 704 | + { |
| 705 | + return '<?php endif; ?>'; |
| 706 | + } |
| 707 | + |
| 708 | + /** |
| 709 | + * @param string $expression |
| 710 | + * @return string |
| 711 | + */ |
| 712 | + protected function compileAuth($expression) |
| 713 | + { |
| 714 | + return "<?php if (\Auth::check()): ?>"; |
| 715 | + } |
| 716 | + |
| 717 | + /** |
| 718 | + * @param string $expression |
| 719 | + * @return string |
| 720 | + */ |
| 721 | + protected function compileEndauth($expression) |
| 722 | + { |
| 723 | + return '<?php endif; ?>'; |
| 724 | + } |
| 725 | + |
| 726 | + /** |
| 727 | + * @param string $expression |
| 728 | + * @return string |
| 729 | + */ |
| 730 | + protected function compileGuest($expression) |
| 731 | + { |
| 732 | + return "<?php if (\Auth::guest()): ?>"; |
| 733 | + } |
| 734 | + |
| 735 | + /** |
| 736 | + * @param string $expression |
| 737 | + * @return string |
| 738 | + */ |
| 739 | + protected function compileEndguest($expression) |
| 740 | + { |
| 741 | + return '<?php endif; ?>'; |
| 742 | + } |
| 743 | + |
623 | 744 | /** |
624 | 745 | * Register a custom Blade compiler. |
625 | 746 | * |
@@ -724,4 +845,18 @@ protected function getTags($escaped = false) |
724 | 845 | return array_map('stripcslashes', $tags); |
725 | 846 | } |
726 | 847 |
|
| 848 | + /** |
| 849 | + * Strip the parentheses from the given expression. |
| 850 | + * |
| 851 | + * @param string $expression |
| 852 | + * @return string |
| 853 | + */ |
| 854 | + public function stripParentheses($expression) |
| 855 | + { |
| 856 | + if (Str::startsWith($expression, '(')) { |
| 857 | + $expression = substr($expression, 1, -1); |
| 858 | + } |
| 859 | + |
| 860 | + return $expression; |
| 861 | + } |
727 | 862 | } |
0 commit comments