lagdo/ui-builder
Composer 安装命令:
composer require lagdo/ui-builder
包简介
A customizable and extensible HTML UI builder.
README 文档
README
A customizable and extensible HTML UI builder
This package provides a unified API in PHP to create UI for CSS frameworks like Bootstrap.
It takes its inspiration from the PHP HTML builder, with functions to create UI components like menus, forms, tabs and so on.
Motivation
This UI builder was first created for Jaxon DbAdmin, a database admin dashboard that can be inserted in a page of an existing PHP application. Its user interface then needs to adapt to various CSS frameworks, with as little effort as possible. So rewriting all the views for each supported CSS framework was not a satisfying option.
Using this UI buider, the UI of the app is written once, and the HTML code for CSS frameworks is generated automatically. Adding support of a given CSS framework is then easier and less error-prone.
Getting Started
The BuilderInterface in the src/ directory defines the functions that can be used to build user interfaces.
What it actually creates is not only HTML elements, but also UI components as defined by popular CSS frameworks like Bootstrap or Bulma.
The classes that generate the final HTML code is provided by a separate package, which must be installed in addition to this one.
Prerequisites
This package requires PHP version 8.0 or greater.
Installation
Install the packages using Composer. In the examples below, we will build simple UI components for the Bootstrap 5 framework.
composer require ui-builder ui-builder-bootstrap5
Usage
The BuilderInterface defines the functions that are use to build the UI components.
In this example, it is passed as parameter to the View class constructor.
use Lagdo\UiBuilder\BuilderInterface; class View { /** * @var BuilderInterface */ protected $html; /** * @param BuilderInterface */ public function __construct(BuilderInterface $html) { $this->html = $html; } /** * Get the HTML code of a simple form * * @param array $formData * @return string */ public function getSimpleForm(array $formData) { return $this->html->build( $this->html->form( $this->html->row( $this->html->col( $this->html->label($this->html->text('Name')) ->setFor('name') ) ->width(4), $this->html->col( $this->html->input() ->setType('text') ->setName('name') ->setPlaceholder('Name') ->setValue($formData['name']) ) ->width(8) ), $this->html->row( $this->html->col( $this->html->label($this->html->text('Description')) ->setFor('description') ) ->width(4), $this->html->col( $this->html->textarea($this->html->text($formData['description'])) ->setRows('10') ->setName('description') ->setWrap('on') ->setSpellcheck('false') ) ->width(8) ) ) ->responsive()->setId('form-id') ); } }
Depending on which class instance is passed to the View constructor, a different HTML code will be generated.
With the following PHP code,
use Lagdo\UiBuilder\Bootstrap3\Builder; $view = new View(new Builder());
the getSimpleForm() function will generate code for Bootstrap 3.
<form class="form-horizontal" id="form-id"> <div class="form-group"> <div class="col-md-4"> <label class="control-label" for="name">Name</label> </div> <div class="col-md-8"> <input class="form-control" type="text" name="name" placeholder="Name" value="" /> </div> </div> <div class="form-group"> <div class="col-md-4"> <label class="control-label" for="description">Description</label> </div> <div class="col-md-8"> <textarea class="form-control" rows="10" name="description" wrap="on" spellcheck="false"></textarea> </div> </div> </form>
And with the following PHP code,
use Lagdo\UiBuilder\Bootstrap4\Builder; $view = new View(new Builder());
the same getSimpleForm() function will generate code for Bootstrap 4.
<form id="form-id"> <div class="form-group row"> <div class="col-md-4"> <label class="col-form-label" for="name">Name</label> </div> <div class="col-md-8"> <input class="form-control" type="text" name="name" placeholder="Name" value="" /> </div> </div> <div class="form-group row"> <div class="col-md-4"> <label class="col-form-label" for="description">Description</label> </div> <div class="col-md-8"> <textarea class="form-control" rows="10" name="description" wrap="on" spellcheck="false"></textarea> </div> </div> </form>
Documentation
Coming soon...
Roadmap
- Add more components in the interface
- Add support of more UI frameworks
- Add tests
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE.txt for more information.
lagdo/ui-builder 适用场景与选型建议
lagdo/ui-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 523 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ui」 「html」 「builder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lagdo/ui-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lagdo/ui-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lagdo/ui-builder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A Sphinx Query Builder extension for the Laravel Database package
Anax Database Active Record module for model classes.
HTML and form generation
A simple package to create tables in Discord messages.
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 523
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 14
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-20