定制 nowise/uup-web-component 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nowise/uup-web-component

Composer 安装命令:

composer require nowise/uup-web-component

包简介

Web component library.

README 文档

README

This library provides web component classes for rendering HTML.

A component is a class that has both behavior and interface. The main classes are widget (standard components), element (simple HTML elements) and finally container (using template file). You can use these direct, but recommended is to use one of their sub-classes.

The easiest way to get started is to examine the code in the examples directory while watching the outcome in a web browser. It's recommended to open the project in i.e. NetBeans IDE to get autocomplete of property names. Start explore the container and widget classes.

The library is organized as:

UUP\Web\Component
    +-- Component           // Interface class
    +-- Transform           // Rendition transformer (callable)
    +-- Element             // Generic element component class
    +-- Container           // Generic container component class
    +-- Style               // Enum classes for inline CSS
    |     +-- Alignment
    |     +-- Border
    |     +-- Color
    |     +-- Font
    |    ...
    +-- Collection          // Collection support (i.e. attributes and events).
    |     +-- Attributes
    |     +-- Classes
    |     +-- Events
    |     +-- Stylesheet
    |     +-- Properties    // Generic properties
    |     +-- Collection    // Base class
    +-- Element             // Components with direct rendering (HTML elements)
    |     +-- Button
    |     +-- Span
    |     +-- List
    |     +-- Table
    |    ...
    +-- Widget              // Components with direct rendering (specialized objects)
    |     +-- Button
    |     +-- Combobox
    |     +-- Panel
    |    ...
    +-- Container           // Components using rendering template
          +-- Grid
          +-- Card
          +-- Download
          +-- Sitemap

All classes derived from element has access to the special properties class, event, props, style and attr that provides collection support. Settings in the props collection are transformed during rendering. Some of the collection has virtual sub collections that groups properties together:

$element = new Element(array(), "p", "...");
$element->id = 12;
$element->data->order = 4885;
$element->render();     // <p id="12" data-order="4885">...</p>

Components contains properties and optional sub components. It's the job of the render transformer to generate HTML from component objects and rendition can be altered by passing the transformer to render() method or set a default transformer globally:

$transformer = new CustomTransformer();
Transformer::setInstance($transfomer);

The reason for using a custom transformer could be to support themes, creating high-contrast styles or translation of text. It's up to you as the library user to decide how to use it, at the extreme you can bypass the builtin rendition and use the library classes as plain objects.

The default render transformer is paragon that produces HTML targetting the W3.CSS library from properties defined in component objects:

$button = new Button("Download");
$button->color = "red";
$button->render();          // <button class="w3-btn w3-red">Download</button>

You can override this by passing an transform class instance to the render() method and modify classes:

$transform = new MaterialDesignTransform();
$button->render($transform);

Another option is to not using the component properties, but to use the collection properties instead:

$button = new Button("Download");
$button->attr->color = "red";
$button->render();          // <button color="red">Download</button>

For setting attributes that can't be used as property names (syntax violation on i.e. background-color), use the add() method instead:

$button->attr->add("background-color", "red");

You are not limited to setting individual properties. The class, event, attr and style properties all accepts an array:

$button->attr->set(array(
    "color" => "red",
    "background-color" => "blue"
));

For setting all at once, use the second argument during construction:

$button = new Button("Download", array(
    "style" => array(           // Define inline CSS
            ...     
    ),
    "event" => array(           // Define event handlers
            ...     
    ),
));

All components (element and containers) can contain other child components:

$div = new Div();
$p1 = $div->add(new Paragraph("Some text here"));
$p2 = $div->add(new Paragraph("More text here"));
$div->render();     // <div><p>Some text here</p><p>More text here</p></div>

Calling render() on parent component automatic renders all child components. The rendition will take care of outputting them inside itself using their added order but after its own text (think inner HTML).

The scope of this library is not to provide a complete set of HTML element components. Neither does it care if nesting input elements inside an option element.

More

Visit the project page for more examples.

nowise/uup-web-component 适用场景与选型建议

nowise/uup-web-component 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「template」 「web」 「component」 「render」 「bmc」 「uup」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nowise/uup-web-component 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nowise/uup-web-component 我们能提供哪些服务?
定制开发 / 二次开发

基于 nowise/uup-web-component 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-01-24