Skip to content

stefanfisk/vy

Repository files navigation

stefanfisk/vy

A simple view library inspired by React.

Source Code Download Package PHP Programming Language Read License Build Status Codecov Code Coverage Psalm Type Coverage

About

Installation

Install this package as a dependency using Composer.

composer require stefanfisk/vy

Usage

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

Contributing

Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.

Coordinated Disclosure

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.

Copyright and License

stefanfisk/vy is copyright © Stefan Fisk and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.

About

No description or website provided.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •