CompilesIncludes.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Illuminate\View\Compilers\Concerns;
  3. trait CompilesIncludes
  4. {
  5. /**
  6. * Compile the each statements into valid PHP.
  7. *
  8. * @param string $expression
  9. * @return string
  10. */
  11. protected function compileEach($expression)
  12. {
  13. return "<?php echo \$__env->renderEach{$expression}; ?>";
  14. }
  15. /**
  16. * Compile the include statements into valid PHP.
  17. *
  18. * @param string $expression
  19. * @return string
  20. */
  21. protected function compileInclude($expression)
  22. {
  23. $expression = $this->stripParentheses($expression);
  24. return "<?php echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
  25. }
  26. /**
  27. * Compile the include-if statements into valid PHP.
  28. *
  29. * @param string $expression
  30. * @return string
  31. */
  32. protected function compileIncludeIf($expression)
  33. {
  34. $expression = $this->stripParentheses($expression);
  35. return "<?php if (\$__env->exists({$expression})) echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
  36. }
  37. /**
  38. * Compile the include-when statements into valid PHP.
  39. *
  40. * @param string $expression
  41. * @return string
  42. */
  43. protected function compileIncludeWhen($expression)
  44. {
  45. $expression = $this->stripParentheses($expression);
  46. return "<?php echo \$__env->renderWhen($expression, array_except(get_defined_vars(), array('__data', '__path'))); ?>";
  47. }
  48. /**
  49. * Compile the include-first statements into valid PHP.
  50. *
  51. * @param string $expression
  52. * @return string
  53. */
  54. protected function compileIncludeFirst($expression)
  55. {
  56. $expression = $this->stripParentheses($expression);
  57. return "<?php echo \$__env->first({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
  58. }
  59. }