keruyphp/keruy-html
Composer 安装命令:
composer require keruyphp/keruy-html
包简介
Flexible fluent PHP DSL for HTML.
README 文档
README
Simple fluent PHP DSL for building HTML.
Installation
composer require keruyphp/keruy-html
Quick start
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use KeruyPHP\KeruyHtml\Html; echo Html::div(['class' => 'box'], 'Hello world');
Passing content
You can build children in a few different ways.
1. As an array
The first array argument is treated as attributes. Pass an empty attribute array if you want to send children as an array.
echo Html::ul([], [ Html::li('One'), Html::li('Two'), Html::li('Three'), ]);
2. With a closure
echo Html::ul(function () { Html::li('One'); Html::li('Two'); Html::li('Three'); });
3. As trailing arguments
echo Html::ul( Html::li('One'), Html::li('Two'), Html::li('Three'), );
Output styles
You can render the same structure using an array or a closure.
Array-based output
echo Html::div(['class' => 'card'], [ Html::h2('Title'), Html::p('Text from array children.'), ]);
Closure-based output
echo Html::div(function () { Html::h2('Title'); Html::p('Text from closure children.'); });
Core methods
append()
append() is the universal child API. It accepts strings, nodes, arrays, generators and closures.
String values are treated as text and escaped automatically.
echo Html::div(function (\KeruyPHP\KeruyHtml\Tags\Tag $div) { $div->append( 'Hello ', Html::strong('world'), '!', ); });
text()
text() is the explicit text helper. It is a semantic alias for appending escaped string content.
echo Html::p(function (\KeruyPHP\KeruyHtml\Tags\Tag $p) { $p->text('Price: ', '100 UAH'); });
raw()
raw() appends trusted HTML fragments without escaping.
echo Html::div(function (\KeruyPHP\KeruyHtml\Tags\Tag $div) { $div->raw('<strong>Trusted HTML</strong>'); });
Use raw() only for HTML you already trust.
Setting attributes and classes
You can add attributes and classes in three common ways.
1. In the attribute array
echo Html::div([ 'class' => 'box', 'id' => 'main', ], 'Hello');
2. Inside a closure
echo Html::div(function (\KeruyPHP\KeruyHtml\Tags\Tag $div) { $div->class('box'); $div->prop('id', 'main'); Html::span('Hello'); });
3. At the end of the chain
echo Html::div('Hello') ->class('box') ->prop('id', 'main');
class()
The class() method is the main shortcut for CSS classes.
echo Html::div('Hello') ->class('box') ->class('has-background-light');
prop()
Use prop() for any attribute.
echo Html::a('Profile') ->prop('href', '/profile') ->prop('target', '_blank');
You can also combine it with regular attribute arrays:
echo Html::input(['type' => 'text']) ->prop('name', 'email') ->prop('placeholder', 'Email');
Pretty output
Call pretty() if you want formatted HTML instead of minified output.
echo Html::div(['class' => 'card'], function () { Html::h2('Title'); Html::p('Formatted output example.'); })->pretty();
Notes
- Strings are escaped automatically.
- Use
HtmlElement::raw()orHtmlUtil::raw()if you need raw HTML. - Use
HtmlElement::text()orHtmlUtil::text()if you want explicit escaped text.
keruyphp/keruy-html 适用场景与选型建议
keruyphp/keruy-html 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「DSL」 「fluent」 「html」 「Flexible」 「fluent-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 keruyphp/keruy-html 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 keruyphp/keruy-html 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 keruyphp/keruy-html 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Feature complete, object oriented, composable, extendable Elasticsearch query DSL builder for PHP.
Presentation and Formatting helper with nice fluent interface.
Elasticsearch DSL library
Traits gathering fluent syntax common methods
Expression executor, which allow to implement domain-specific language
A modern, fluent HTTP client. Forked from Mashape, reimagined by Nidux, and open-sourced for the PHP community.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2026-05-08