This commit is contained in:
TiclemFR
2023-12-29 17:47:40 +01:00
parent 936d5f15d9
commit 076ec32c3b
565 changed files with 339154 additions and 110 deletions

View 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)));
}
}