switon / view
HTML views with request-scoped state, controller template resolution, and an HTTP response bridge for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
- switon/event: ^1.0
- switon/http: ^1.0
- switon/renderer: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
Switon's view layer for router-mapped HTML actions, request-local state, widgets, and layout/block rendering.
Highlights
- View routing:
#[ViewMapping]and related attributes route page actions into the HTML view flow. - Flexible template resolution:
ViewInterface::render()accepts direct template paths andController::Actiontargets. - Shared layout shell:
setLayout(),@section, and@yieldlet page templates reuse one wrapper. - Request-local view state:
ViewContextkeeps layout, variables, and rendered content together. - Widget support: reusable page parts can be built with widget contracts.
- HTTP bridge:
ViewRendererturns action return values into rendered HTML responses.
Installation
composer require switon/view
Quick Start
use Switon\Routing\Attribute\RequestMapping; use Switon\Routing\Attribute\ViewMapping; use Switon\Viewing\ViewInterface; use Switon\Core\Attribute\Autowired; #[RequestMapping('/user')] class UserController { #[Autowired] protected ViewInterface $view; #[ViewMapping('profile')] public function profileAction(): array { return [ 'title' => 'Profile', 'user' => ['name' => 'Mark'], ]; } }
Docs: https://docs.switon.dev/latest/view
License
MIT.