CompilesHelpers.php
TLDR
This file, CompilesHelpers.php
, is part of the Illuminate\View\Compilers\Concerns
namespace and contains a trait called CompilesHelpers
. The trait provides methods for compiling various statements into valid PHP code. The statements include CSRF, dd
, dump
, method, vite
, and viteReactRefresh
statements.
Methods
compileCsrf
This method compiles the CSRF statements into valid PHP code. It returns a string that echoes the csrf_field()
function.
compileDd
This method compiles the "dd" statements into valid PHP code. It takes a string argument and returns a string that executes the dd
function with the provided arguments.
compileDump
This method compiles the "dump" statements into valid PHP code. It takes a string argument and returns a string that executes the dump
function with the provided arguments.
compileMethod
This method compiles the method statements into valid PHP code. It takes a string argument representing the method and returns a string that echoes the method_field()
function with the provided method.
compileVite
This method compiles the "vite" statements into valid PHP code. It takes an optional string argument and returns a string that echoes the app('Illuminate\Foundation\Vite')
function with the provided arguments. If no arguments are provided, it defaults to an empty argument list ()
.
compileViteReactRefresh
This method compiles the "viteReactRefresh" statements into valid PHP code. It returns a string that echoes the app('Illuminate\Foundation\Vite')->reactRefresh()
function.
Classes
None
<?php
namespace Illuminate\View\Compilers\Concerns;
use Illuminate\Foundation\Vite;
trait CompilesHelpers
{
/**
* Compile the CSRF statements into valid PHP.
*
* @return string
*/
protected function compileCsrf()
{
return '<?php echo csrf_field(); ?>';
}
/**
* Compile the "dd" statements into valid PHP.
*
* @param string $arguments
* @return string
*/
protected function compileDd($arguments)
{
return "<?php dd{$arguments}; ?>";
}
/**
* Compile the "dump" statements into valid PHP.
*
* @param string $arguments
* @return string
*/
protected function compileDump($arguments)
{
return "<?php dump{$arguments}; ?>";
}
/**
* Compile the method statements into valid PHP.
*
* @param string $method
* @return string
*/
protected function compileMethod($method)
{
return "<?php echo method_field{$method}; ?>";
}
/**
* Compile the "vite" statements into valid PHP.
*
* @param string|null $arguments
* @return string
*/
protected function compileVite($arguments)
{
$arguments ??= '()';
$class = Vite::class;
return "<?php echo app('$class'){$arguments}; ?>";
}
/**
* Compile the "viteReactRefresh" statements into valid PHP.
*
* @return string
*/
protected function compileViteReactRefresh()
{
$class = Vite::class;
return "<?php echo app('$class')->reactRefresh(); ?>";
}
}