@barefootjs/php

中文文档
0.40.2发布于 2026/11/02MITES Module零依赖构建来源已验证近 30 天下载 1726

BarefootJS engine-agnostic PHP runtime -- pluggable rendering backend; the shared basis for Twig, Blade and other PHP engine integrations

原始使用文档
文档目录4 节
  1. Backend contract
  2. Reference implementation
  3. Composer
  4. Tests

@barefootjs/php

The engine-agnostic PHP runtime for BarefootJS — the BarefootJS class (BarefootJS.php) that compiled marked templates call as the bf object (bf.json(...), bf.spread_attrs(...), the array/string method helpers, hydration markers, child-component rendering).

This package has no dependencies beyond core PHP (>=8.2). Everything that depends on how a template is rendered — JSON marshalling, raw-string marking, JSX-children materialisation, named-template rendering, and template-variable-name mangling — is delegated to a pluggable backend, so the same runtime can drive any PHP template engine (Twig, Blade, ...).

JSX → IR → (compile-time adapter) → marked template ─┐
                                                      ├─► rendered by the host's
  BarefootJS runtime ── backend ── template engine ───┘    template engine

Backend contract

A backend implements five methods:

MethodPurpose
encode_json($data)JSON-encode a value (injectable; defaults to Barefoot\Json::canonicalEncode)
mark_raw($str)Mark a string so the engine emits it without re-escaping
materialize($value)Resolve a captured-children value to a string
render_named($name, $bf, $vars)Render a named template with $bf bound
ident($name)Mangle a template-variable name for this engine's reserved-word set

Inject a backend with new BarefootJS($c, ['backend' => $backend]).

Reference implementation

@barefootjs/twig provides Barefoot\TwigBackend (targeting twig/twig) plus the compile-time adapter that emits Twig templates (.twig).

Composer

The Packagist distribution name is barefootjs/php. The npm package ships the same src/ so the monorepo integrations can consume it without a separate install.

This package is maintained in the BarefootJS monorepo and is mirrored to a Packagist-facing repository only for Composer distribution.

Do not send implementation pull requests to the Packagist mirror. Send changes to the monorepo path above; the release workflow splits this directory and pushes the mirror automatically.

Tests

php tests/run.php

Zero-dependency, PHPUnit-free TAP-ish harness (tests/_harness.php). Every test_*.php file is also independently runnable via php tests/test_foo.php. Includes the golden helper-vector (test_helper_vectors.php) and ParsedExpr-evaluator (test_eval_vectors.php) conformance suites — see spec/template-helpers.md.

版本与发布记录

@barefootjs/php 共发布 78 个版本,首次发布于 2026/07/07;过去 12 个月发布了 78 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.40.2latest2026/11/027 天前
0.40.12026/10/2911 天前
0.40.02026/10/2614 天前
0.39.92026/10/2515 天前
0.39.82026/10/2119 天前
0.39.72026/10/1822 天前

关于 @barefootjs/php 的常见问题

@barefootjs/php 是什么?

BarefootJS engine-agnostic PHP runtime -- pluggable rendering backend; the shared basis for Twig, Blade and other PHP engine integrations

如何安装 @barefootjs/php?

在项目目录运行 npm install @barefootjs/php,或使用 pnpm add / yarn add / bun add。

@barefootjs/php 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/barefootjs__php 是否存在。

@barefootjs/php 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@barefootjs/php 可以商用吗?

@barefootjs/php 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@barefootjs/php 的下载量有多少?

根据 npm 官方下载统计,@barefootjs/php 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,726 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@barefootjs/php 还在维护吗?

最新版本 0.40.2 发布于 2026/11/02(7 天前);至今共发布 78 个版本,其中过去 12 个月发布了 78 个;首次发布于 2026/07/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。