34 lines
1015 B
PHP
34 lines
1015 B
PHP
<?php
|
|
|
|
// Router de compatibilidad del paquete htmx: monta un componente propio sobre
|
|
// el motor HTMLComponent/HTMX con el arranque real del core.
|
|
|
|
use Libs\HTMLComponent;
|
|
use Libs\HTMX;
|
|
use Libs\Router;
|
|
|
|
$views = ROOT_CORE . '/Views';
|
|
if (!is_dir($views)) {
|
|
mkdir($views, 0777, true);
|
|
}
|
|
|
|
file_put_contents($views . '/CompatGreet.php', <<<'VIEW'
|
|
<h1 id="compat-greet"><?php echo $this->escapedProperty('name'); ?></h1>
|
|
VIEW);
|
|
|
|
file_put_contents($views . '/CompatButton.php', <<<'VIEW'
|
|
<button hx-post="/compat/htmx/echo" hx-target="#compat-greet" class="btn">ir</button>
|
|
VIEW);
|
|
|
|
Router::get('/compat/htmx/render', function () {
|
|
echo 'GREET:';
|
|
HTMLComponent::render('CompatGreet', ['name' => 'A<b>']);
|
|
});
|
|
|
|
Router::get('/compat/htmx/static', function () {
|
|
$instance = new HTMX([], '<i hx-get="/x">ok</i>');
|
|
header('X-Marker: ' . (HTMX::isHtmx() ? 'yes' : 'no'));
|
|
echo 'HTMX:' . var_export(HTMX::isPartialRequest(), true)
|
|
. ':' . var_export($instance->getContent() !== '', true);
|
|
});
|