A simple view library inspired by React.
Install this package as a dependency using Composer.
composer require stefanfisk/vy
Below is a minimal example. Check out the examples for more.
namespace StefanFisk\Vy\Example;
use StefanFisk\Vy\Serialization\Html\UnsafeHtml;
use StefanFisk\Vy\Vy;
use function StefanFisk\Vy\el;
class MyPage
{
public static function el(string $title): Element
{
return Element::create(self::render(...), [
'title' => $title,
]);
}
private static function render(string $title, mixed $children = null): mixed
{
return [
UnsafeHtml::from('<!DOCTYPE html>'),
html::el(lang: 'en')(
head::el()(
meta::el(charset: 'UTF-8'),
title::el()($title),
),
body::el()(
$children,
),
),
];
}
}
$el = MyPage::el(
title: 'Hello, world!',
)(
h1::el()(
'Hello, world!',
),
p::el()(
'This is a test page. There are many like it, but this one is mine.',
),
);
$vy = new Vy();
echo $vy->render($el);
Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.
Keeping user information safe and secure is a top priority, and we welcome the contribution of external security researchers. If you believe you've found a security issue in software that is maintained in this repository, please read SECURITY.md for instructions on submitting a vulnerability report.
stefanfisk/vy is copyright © Stefan Fisk and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.