PHPackages                             bottledcode/swytch-framework - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. bottledcode/swytch-framework

ActiveLibrary[Framework](/categories/framework)

bottledcode/swytch-framework
============================

A PHP framework for building web applications

v0.6.1(2y ago)21600[1 PRs](https://github.com/bottledcode/swytch-framework/pulls)MITPHPPHP &gt;=8.2

Since Feb 20Pushed 2y ago2 watchersCompare

[ Source](https://github.com/bottledcode/swytch-framework)[ Packagist](https://packagist.org/packages/bottledcode/swytch-framework)[ RSS](/packages/bottledcode-swytch-framework/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (20)Versions (22)Used By (0)

Swytch Framework
================

[](#swytch-framework)

The Swytch Framework is a new, fledgling, but powerful framework allowing you to write HTML inline with your application logic, including API endpoints. It is built on top of [htmx](https://htmx.org/) for the browser-side heavy-lifting, and a custom, streaming HTML5 parser, to handle the HTML and escaping.

Features:

- Write HTML inline with your PHP code, relying on context-aware escaping.
- Keep you API logic near the HTML that uses it.
- Application routing via HTML (similar to ReactRouter).
- Automatic CSRF protection.
- Context-Aware escaping.
- Automatic HTML5 validation.
- Authorization and authentication aware routing and rendering.
- Browser cache control.
- Builtin support for translations.

> NOTE: This is currently pre-production software and is not recommended for production use.

Example Apps
------------

[](#example-apps)

The following are some example apps using the Swytch Framework:

### [Once](https://github.com/bottledcode/once)

[](#once)

Check it out live on [once.getswytch.com](https://once.getswytch.com/). This is a secret message app.

### [Authentication](https://github.com/bottledcode/swytch-auth)

[](#authentication)

This app provides a simple authentication system by emailing passwords. It provides Kubernetes ingress authentication.

Example Component
-----------------

[](#example-component)

```
#[\Bottledcode\SwytchFramework\Template\Attributes\Component('example')]
class ExampleComponent {
    use \Bottledcode\SwytchFramework\Template\Traits\RegularPHP;
    use \Bottledcode\SwytchFramework\Template\Traits\Htmx;

    #[\Bottledcode\SwytchFramework\Router\Attributes\Route(\Bottledcode\SwytchFramework\Router\Method::POST, '/api/number')]
    public function getNumber(string $name, string $number): int {
        return $this->render($name, random_int(0, 100));
    }

    public function render(string $name, int $number = null): string {
        $this->begin();
        ?>

            Hello, {}

                } />
                Here is a random number: {}
                Generate a new random number
