transitive / web
Web Front controller and view for transitive.
2.5.5
2026-05-19 21:43 UTC
Requires
- php: >8.1
- transitive/core: ^2.5.4
- transitive/routing: ^2.4.4
- transitive/simple: ^2.5.4
Requires (Dev)
- phpunit/phpunit: ^9.0.0
- vimeo/psalm: ^6.12
Suggests
- nikic/fast-route: Fast request router for PHP
- transitive/utils: sometimes usefull methods and function
README
HTTP front controller and HTML-oriented view layer for Transitive.
This package builds on transitive/core and transitive/routing to provide browser-facing rendering, content negotiation, default HTML layout handling, and helpers for scripts, styles, and metadata.
Installation
composer require transitive/web
PHP 8.1+ is required.
What is included
Transitive\Web\Front: an HTTP front controller withAcceptheader negotiation and response header management.Transitive\Web\View: a richer (than Transitive\Simple) view implementation with title, meta tag, stylesheet, and script helpers.
Basic Usage
<?php use Transitive\Web; use Transitive\Routing; require __DIR__.'/../vendor/autoload.php'; $front = new Web\WebFront(); $front->addRouter(new Routing\PathRouter(dirname(dirname(__FILE__)).'/presenters', dirname(dirname(__FILE__)).'/views')); $front->execute(@$_GET['request'] ?? 'index'); echo $front;
Response formats
Transitive\Web\Front can emit different representations depending on the resolved content type, including:
- HTML and XHTML
- JSON
- XML
- YAML
- raw stylesheet content
- raw script content
- serialised document/head/content payloads
By default it inspects $_SERVER['HTTP_ACCEPT'] and chooses the best supported MIME type.
View helpers
Transitive\Web\View extends the simple core view with helpers such as:
addMetaTag()/addRawMetaTag()addStyle()/linkStyleSheet()/importStyleSheet()addScript()/linkScript()/importScript()getHead(),getMetas(),getStyles(), andgetScripts()
Example:
<?php use Transitive\Web\View; $view = new View(); $view->setTitle('Home'); $view->addMetaTag('description', 'Example page'); $view->linkStyleSheet('/assets/site.css'); $view->linkScript('/assets/site.js', defer: true); $view->addContent(function($data) { echo '<h1>Hello '.$data['name'].'</h1>'; }, 'text/html');