bottledcode / swytch-framework
A PHP framework for building web applications
v0.6.1
2023-12-31 19:51 UTC
Requires
- php: >=8.2
- ext-dom: *
- ext-intl: *
- ext-mbstring: *
- ext-sodium: *
- gettext/gettext: ^5.6
- gettext/translator: ^1.1
- laminas/laminas-escaper: ^2.12
- laminas/laminas-httphandlerrunner: ^2.5
- masterminds/html5: ^2.7
- nyholm/psr7: ^1.5
- nyholm/psr7-server: ^1.0
- olvlvl/composer-attribute-collector: ^2.0
- php-di/php-di: ^7.0
- psr/container: 2.0.2
- psr/http-message: ^1.1 || ^2.0
- symfony/property-access: ^7.0
- symfony/serializer: ^7.0
- withinboredom/response-code: ^1.0
Requires (Dev)
- infection/infection: ^0.27
- monolog/monolog: ^3.3
- pestphp/pest: ^2.5
- phpstan/phpstan: ^1.10
- roave/security-advisories: dev-latest
- spatie/pest-plugin-snapshots: ^2.0
Suggests
- monolog/monolog: For logging
- php-di/php-di: For dependency injection
- symfony/serializer: For state validation
README
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 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
The following are some example apps using the Swytch Framework:
Once
Check it out live on once.getswytch.com. This is a secret message app.
Authentication
This app provides a simple authentication system by emailing passwords. It provides Kubernetes ingress authentication.
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(); ?> <div> <h1>Hello, {<?= $name ?>}</h1> <form hx-post="/api/number"> <!-- CSRF protection is automatically added to forms --> <input type='hidden' name='name' value={<?= $name ?>} /> <p>Here is a random number: {<?= $number ?>}</p> <button type="submit">Generate a new random number</button> </form> </div> <?php return $this->end(); } }