CompilesLayouts.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Illuminate\View\Compilers\Concerns;
  3. use Illuminate\View\Factory as ViewFactory;
  4. trait CompilesLayouts
  5. {
  6. /**
  7. * The name of the last section that was started.
  8. *
  9. * @var string
  10. */
  11. protected $lastSection;
  12. /**
  13. * Compile the extends statements into valid PHP.
  14. *
  15. * @param string $expression
  16. * @return string
  17. */
  18. protected function compileExtends($expression)
  19. {
  20. $expression = $this->stripParentheses($expression);
  21. $echo = "<?php echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
  22. $this->footer[] = $echo;
  23. return '';
  24. }
  25. /**
  26. * Compile the section statements into valid PHP.
  27. *
  28. * @param string $expression
  29. * @return string
  30. */
  31. protected function compileSection($expression)
  32. {
  33. $this->lastSection = trim($expression, "()'\" ");
  34. return "<?php \$__env->startSection{$expression}; ?>";
  35. }
  36. /**
  37. * Replace the @parent directive to a placeholder.
  38. *
  39. * @return string
  40. */
  41. protected function compileParent()
  42. {
  43. return ViewFactory::parentPlaceholder($this->lastSection ?: '');
  44. }
  45. /**
  46. * Compile the yield statements into valid PHP.
  47. *
  48. * @param string $expression
  49. * @return string
  50. */
  51. protected function compileYield($expression)
  52. {
  53. return "<?php echo \$__env->yieldContent{$expression}; ?>";
  54. }
  55. /**
  56. * Compile the show statements into valid PHP.
  57. *
  58. * @return string
  59. */
  60. protected function compileShow()
  61. {
  62. return '<?php echo $__env->yieldSection(); ?>';
  63. }
  64. /**
  65. * Compile the append statements into valid PHP.
  66. *
  67. * @return string
  68. */
  69. protected function compileAppend()
  70. {
  71. return '<?php $__env->appendSection(); ?>';
  72. }
  73. /**
  74. * Compile the overwrite statements into valid PHP.
  75. *
  76. * @return string
  77. */
  78. protected function compileOverwrite()
  79. {
  80. return '<?php $__env->stopSection(true); ?>';
  81. }
  82. /**
  83. * Compile the stop statements into valid PHP.
  84. *
  85. * @return string
  86. */
  87. protected function compileStop()
  88. {
  89. return '<?php $__env->stopSection(); ?>';
  90. }
  91. /**
  92. * Compile the end-section statements into valid PHP.
  93. *
  94. * @return string
  95. */
  96. protected function compileEndsection()
  97. {
  98. return '<?php $__env->stopSection(); ?>';
  99. }
  100. }