🔧
This commit is contained in:
52
vendor/inertiajs/inertia-laravel/src/Directive.php
vendored
Normal file
52
vendor/inertiajs/inertia-laravel/src/Directive.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Inertia;
|
||||
|
||||
class Directive
|
||||
{
|
||||
/**
|
||||
* Compiles the "@inertia" directive.
|
||||
*
|
||||
* @param string $expression
|
||||
*/
|
||||
public static function compile($expression = ''): string
|
||||
{
|
||||
$id = trim(trim($expression), "\'\"") ?: 'app';
|
||||
|
||||
$template = '<?php
|
||||
if (!isset($__inertiaSsrDispatched)) {
|
||||
$__inertiaSsrDispatched = true;
|
||||
$__inertiaSsrResponse = app(\Inertia\Ssr\Gateway::class)->dispatch($page);
|
||||
}
|
||||
|
||||
if ($__inertiaSsrResponse) {
|
||||
echo $__inertiaSsrResponse->body;
|
||||
} else {
|
||||
?><div id="'.$id.'" data-page="{{ json_encode($page) }}"></div><?php
|
||||
}
|
||||
?>';
|
||||
|
||||
return implode(' ', array_map('trim', explode("\n", $template)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the "@inertiaHead" directive.
|
||||
*
|
||||
* @param string $expression
|
||||
*/
|
||||
public static function compileHead($expression = ''): string
|
||||
{
|
||||
$template = '<?php
|
||||
if (!isset($__inertiaSsrDispatched)) {
|
||||
$__inertiaSsrDispatched = true;
|
||||
$__inertiaSsrResponse = app(\Inertia\Ssr\Gateway::class)->dispatch($page);
|
||||
}
|
||||
|
||||
if ($__inertiaSsrResponse) {
|
||||
echo $__inertiaSsrResponse->head;
|
||||
}
|
||||
?>';
|
||||
|
||||
return implode(' ', array_map('trim', explode("\n", $template)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user