devgroup/bh
Composer 安装命令:
composer require devgroup/bh
包简介
Template engine. BEMJSON -> HTML processor. PHP port of https://github.com/bem/bh
README 文档
README

BH is a processor that converts BEMJSON to HTML. Or in other words a template engine.
Works with PHP 5.4+ (doesn't work with HHVM 'cause it lacks a lot of required functionality)
Table of Contents
Friendly Packages
- Project Stub with BH.PHP tech
- BEM Core Library with BH.PHP templates - tmp branch
- BEM Components Library with BH.PHP templates - tmp branch
Installation
Via composer
Execute in your shell:
php composer.phar require bem/bh
or (if you have composer in your path)
composer require bem/bh
And use in your code:
require "vendor/autoload.php"; $bh = new \BEM\BH(); // ...
Manual installation
Download using git (execute this in your shell):
# via git
git clone https://github.com/bem/bh-php.git ./vendor/bem/bh
Using wget and tar:
# via wget + tar
wget https://github.com/bem/bh-php/archive/master.tar.gz # download archive
tar -xzvf master.tar.gz --exclude=tests # extract
[ ! -d ./vendor/bem ] && mkdir ./vendor/bem -p # create vendor director
mv ./bh-php-master ./vendor/bem/bh # move library to vendor
rm master.tar.gz # cleanup
Or just download the latest version and unpack to ./vendor/bem/bh path (or any path you want).
And use in your code:
// manual installation require "vendor/bem/bh/index.php"; $bh = new \BEM\BH(); // ...
Usage
BH files within a project have .bh.php suffix (for example, page.bh.php). The file is formed in CommonJS-like format:
return function ($bh) { $bh->match(/*...*/); // ... };
To load this file format use include and run technique:
// Instantiate BH object $bh = new \BEM\BH(); // Load and apply matchers to BH object in $bh $fn = include('file.bh.php'); $fn($bh); // done. and nothing in global // ...
This allows you to have several instances at the moment:
$bh1 = new \BEM\BH(); $bh2 = new \BEM\BH(); // load matchers $indexMatchers = include('bundles/index/index.bh.php'); $mergedMatchers = include('bundles/merged/merged.bh.php'); // apply them $indexMatchers($bh1); // bh1 now contains matchers for index page only $mergedMatchers($bh2); // bh2 now contains all matchers // use it with the same bemjson data $bh1->apply($bemjson); $bh2->apply($bemjson);
Use apply method to convert source tree of BEMJSON into an output HTML. Use processBemJson method to get an interim result in detailed BEMJSON tree form.
Common use case:
require "vendor/autoload.php"; $bh = new \BEM\BH(); $bh->match('button', function ($ctx) { $ctx->tag('button'); }); $bh->processBemJson([ 'block' => 'block' ]); // [ 'block' => 'button', 'mods' => new Mods(), 'tag' => 'button' ] $bh->apply([ 'block' => 'button' ]); // '<button class="button"></button>'
Conversion
Working functions for BEMJSON are templates. Use match method to declare templates. Logic of BEMJSON conversion is declared in a function body.
There are two arguments provided to a template function:
$ctx– instance of\BEM\Contextclass;$json– instance of\BEM\Jsonclass (current BEMJSON tree node).
NB: Do not make changes directly in $json object. Use methods of $ctx object instead. We recommend you to use $json object for reading only (see also $ctx->json() method).
Syntax:
/** * Register matchers * @param string|array $expression bem css expression * @param closure [$matcher] * @return \BEM\BH */ $bh->match(/*string*/ $expression, function (\BEM\Context $ctx, \BEM\Json $json) { // ... actions }); // or... $bh->match([/*string*/ $expression], function (\BEM\Context $ctx, \BEM\Json $json) { // ... actions }); // or... $bh->match(/*array*/ $matchers = [ "$expression" => function(\BEM\Context $ctx, \BEM\Json $json) { // ... actions }, // ... more matchers ]);
Look at more examples in README.md or README.ru.md.
License
devgroup/bh 适用场景与选型建议
devgroup/bh 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 542 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「BEM」 「bh」 「bemjson」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 devgroup/bh 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 devgroup/bh 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 devgroup/bh 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library that provides easy-to-use way of interaction with web-page elements in functional tests using PageObject pattern.
This bundle provides you with an easy way to include assets on demand, but still include them in your header or footer. This can be used for your BEM blocks or facilitates HTTP2.
BEM view components in Laravel
Template engine. BEMJSON -> HTML processor. PHP port of https://github.com/bem/bh
A DOM class name generation library (BEM syntax class name builder etc.)
Blade shortcodes to generate BEM class
统计信息
- 总下载量: 542
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-25