construct-blue / snappy-renderer
A component oriented server side rendering engine for PHP
dev-main
2023-08-26 16:26 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpstan/phpstan: ^1.10.21
- phpunit/phpunit: ^10.2
This package is auto-updated.
Last update: 2025-03-26 19:38:01 UTC
README
A component oriented server side rendering engine for PHP
Example usage
<?php // A class component class App implements \Blue\Snappy\Renderer\Renderable { public function render(object $model) : iterable { return [ '<html lang="en">', '<head>' '<title>Example App</title>' '</head>' '<body>' include 'greeting.php' '</body>' '</html>' ]; } }
<?php // A functional component greeting.php return fn($model) => yield <<<HTML <h1>The Example Greeting</h1> <p>Hello $model->name</p> HTML;
$renderer = new \Blue\Snappy\Renderer\Renderer(); echo $renderer->execute(new App(), (object)['name' => 'world'])