bitforge/thorm
Composer 安装命令:
composer require bitforge/thorm
包简介
PHP-first UI framework that compiles a declarative DSL to a small browser runtime via a shared IR.
README 文档
README
PHP-first DSL for describing reactive UIs that compile to a small JavaScript runtime. Build views with simple PHP functions, emit an intermediate representation (IR), and let the runtime handle reactivity, events, routing, and effects in the browser.
Status
Thorm is currently in pre-alpha / developer preview.
- APIs may change without backward compatibility
- package structure and build flows may change
- suitable for evaluation, experimentation, and early integration work
Project docs
- ROADMAP.md: Current project direction, priorities, and release phases.
- CONTRIBUTING.md: Current contribution policy for the public repo.
- SECURITY.md: How to report security issues privately.
Installation
Install the framework with Composer:
composer require bitforge/thorm:^0.1@alpha
Because Thorm is currently in pre-alpha / developer preview, Composer installation requires an explicit alpha version constraint.
If you want to explore the framework itself, study the examples, or work directly from the source repository, clone the repo and install its local dependencies:
git clone https://github.com/scarpelius/thorm.git
cd thorm
composer install
If you want to consume a local checkout from another PHP project, use a Composer path repository:
{
"repositories": [
{
"type": "path",
"url": "../Thorm"
}
],
"require": {
"bitforge/thorm": "*"
}
}
Project layout
src/php/functions.php: Public DSL surface (state, el, attrs, on, repeat, route, component, effects, http, etc.).src/php/Render.php: Builds the shared IR and can render server-side HTML from that IR.src/php/BuildExample.php: Writes generated example output topublic/examples/<example>/.src/php/IR/*: IR node definitions for atoms, expressions, actions, effects, and DOM nodes.assets/index.tpl.html: HTML template used during example generation ({$title},{$containerId},{$iruri}placeholders).public/runtime/**: Browser runtime (core, primitives, utils, devtools).examples/*.php: End-to-end samples that generate pages underpublic/examples/.cli/watch.sh: Dev helper that watches the tree, reruns touched example PHP files, and syncs runtime assets.
Requirements
- PHP 8.1+
- Composer for autoloading via
vendor/autoload.php - A static file server to view the generated pages (e.g.,
php -S localhost:8000 -t public)
Quick start
- Install the package in your PHP project:
composer require bitforge/thorm:^0.1@alpha
- To explore the bundled examples from this repository instead, clone the repo and install local dependencies:
git clone https://github.com/scarpelius/thorm.git
cd thorm
composer install
- Run an example to generate IR + HTML in
public/examples/<example>/:
php examples/counter.php
- Serve the
public/folder and openhttp://localhost/examples/counter/.
To regenerate on changes, use the watcher (auto-runs example scripts and syncs runtime):
bash cli/watch.sh
(Use WATCH_MODE=poll on filesystems without inotify.)
Explore the repository
If you are learning Thorm for the first time, the repository is the best place to study the framework surface, examples, runtime, and generated output together.
examples/*.phpcontains end-to-end sample appssrc/php/**contains the DSL, renderer, and IR classessrc/runtime/**contains the browser runtimeassets/index.tpl.htmlshows the HTML template used during example generation
Authoring UIs in PHP
Build views with the DSL from Thorm\ (autoloaded via composer files):
<?php use Thorm\BuildExample; use Thorm\Render; use function Thorm\{state, el, text, attrs, cls, on, inc, read, client}; $cnt = state(0); $app = el('div', [cls('p-3')], [ el('h1', [], [text('Counter')]), el('p', [], [text(read($cnt))]), el('button', [attrs(['class' => 'btn btn-primary']), on('click', inc($cnt, 1))], [text('Increment')]), ]); $app = client($app); $render = new Render(); $res = $render->render($app); BuildExample::build([ 'name' => 'counter', 'path' => __DIR__ . '/public/examples/', 'renderer' => $res, 'template' => __DIR__ . '/assets/index.tpl.html', 'opts' => [ 'title' => 'Counter', 'containerId' => 'app', ], ]);
Render::render() returns the IR plus server-rendered HTML. BuildExample::build() writes the IR JSON and index.html for the example. Serve the output and the runtime under public/runtime.
DSL highlights (see src/php/functions.php)
- State & expressions:
state,read,val/num/str/not/concat/cond,iteminsiderepeat(item('')returns the full item). - DOM nodes:
el,text,fragment,show,repeat(lists),attrs,cls,style,on(events). - Routing & links:
routewith path table + fallback,link,navigate,redirect,param,query. - Components & slots:
component,slot,propfor props + named or default slots. - Effects & actions:
effect,onMount,watch,every,after,onVisible,onWindow,onDocument,onSelf,selectorTarget,windowTarget,documentTarget. - HTTP helper:
http(url, method, toAtom, statusAtom, headers, body, parse)usable as listener or action (asAction=true). - Utilities:
bindfor two-way form binding;inc,set,add,delayfor state updates.
Examples worth reading (examples)
counter.php,2counters.php: Atoms, math expressions, conditional rendering.attrs.php,text-reactive.php,toggle.php: Props, class/style helpers, simple state.repeat.php: Lists with keyed templates anditem()accessors.components.php,component-prop.php,components-style-classes.php,components-live*.php: Components with props + slots.effects-*,events.php: Effects (mount, interval, timeout, visible, watch), HTTP actions, window/document events, navigation.router.php,fragments.php,search-box-live.php,bid.php: Routing, fragments, form bindings, more realistic flows.
Runtime & templates
- Runtime entry:
public/runtime/index.js. - Templates:
assets/index.tpl.html. Tokens are replaced during example generation.
Serving and packaging
- For quick demos, serve
public/with PHP's built-in server:php -S localhost:8000 -t public. - When deploying, copy
public/plus the generated*.ir.jsonfiles. Ensure runtime assets underpublic/runtime/stay reachable at the path used in the generated page.
Notes
- IR is JSON-friendly; you can persist it alongside rendered HTML or feed it to another build step.
bitforge/thorm 适用场景与选型建议
bitforge/thorm 是一款 基于 HTML 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 15, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「ui」 「javascript」 「DSL」 「frontend」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bitforge/thorm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bitforge/thorm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bitforge/thorm 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 34
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-04-08