CompilesFragments.php
TLDR
The file CompilesFragments.php
contains a trait CompilesFragments
that is used for compiling fragment statements in a PHP template.
Methods
compileFragment($expression)
This method is used to compile the fragment statements into valid PHP code. It takes an $expression
argument and trims it before assigning it to the $lastFragment
property. It then returns the compiled PHP code.
compileEndfragment()
This method is used to compile the end-fragment statements into valid PHP code. It simply returns the PHP code to stop the current fragment.
<?php
namespace Illuminate\View\Compilers\Concerns;
trait CompilesFragments
{
/**
* The last compiled fragment.
*
* @var string
*/
protected $lastFragment;
/**
* Compile the fragment statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileFragment($expression)
{
$this->lastFragment = trim($expression, "()'\" ");
return "<?php \$__env->startFragment{$expression}; ?>";
}
/**
* Compile the end-fragment statements into valid PHP.
*
* @return string
*/
protected function compileEndfragment()
{
return '<?php echo $__env->stopFragment(); ?>';
}
}