CompilesAuthorizations.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Illuminate\View\Compilers\Concerns;
  3. trait CompilesAuthorizations
  4. {
  5. /**
  6. * Compile the can statements into valid PHP.
  7. *
  8. * @param string $expression
  9. * @return string
  10. */
  11. protected function compileCan($expression)
  12. {
  13. return "<?php if (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->check{$expression}): ?>";
  14. }
  15. /**
  16. * Compile the cannot statements into valid PHP.
  17. *
  18. * @param string $expression
  19. * @return string
  20. */
  21. protected function compileCannot($expression)
  22. {
  23. return "<?php if (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->denies{$expression}): ?>";
  24. }
  25. /**
  26. * Compile the canany statements into valid PHP.
  27. *
  28. * @param string $expression
  29. * @return string
  30. */
  31. protected function compileCanany($expression)
  32. {
  33. return "<?php if (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->any{$expression}): ?>";
  34. }
  35. /**
  36. * Compile the else-can statements into valid PHP.
  37. *
  38. * @param string $expression
  39. * @return string
  40. */
  41. protected function compileElsecan($expression)
  42. {
  43. return "<?php elseif (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->check{$expression}): ?>";
  44. }
  45. /**
  46. * Compile the else-cannot statements into valid PHP.
  47. *
  48. * @param string $expression
  49. * @return string
  50. */
  51. protected function compileElsecannot($expression)
  52. {
  53. return "<?php elseif (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->denies{$expression}): ?>";
  54. }
  55. /**
  56. * Compile the else-canany statements into valid PHP.
  57. *
  58. * @param string $expression
  59. * @return string
  60. */
  61. protected function compileElsecanany($expression)
  62. {
  63. return "<?php elseif (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->any{$expression}): ?>";
  64. }
  65. /**
  66. * Compile the end-can statements into valid PHP.
  67. *
  68. * @return string
  69. */
  70. protected function compileEndcan()
  71. {
  72. return '<?php endif; ?>';
  73. }
  74. /**
  75. * Compile the end-cannot statements into valid PHP.
  76. *
  77. * @return string
  78. */
  79. protected function compileEndcannot()
  80. {
  81. return '<?php endif; ?>';
  82. }
  83. /**
  84. * Compile the end-canany statements into valid PHP.
  85. *
  86. * @return string
  87. */
  88. protected function compileEndcanany()
  89. {
  90. return '<?php endif; ?>';
  91. }
  92. }