aleksip/plugin-data-transform 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

aleksip/plugin-data-transform

Composer 安装命令:

composer require aleksip/plugin-data-transform

包简介

Data Transform Plugin for Pattern Lab PHP

README 文档

README

Installation

To install and use the plugin run the following command in the Pattern Lab root directory:

composer require aleksip/plugin-data-transform

Configuration options

For Attribute object support to work properly, your Pattern Lab config.yml file needs to have the following setting:

twigAutoescape: false

The default values for Data Transform Plugin specific options in config.yml are:

plugins:
    dataTransform:
        enabled: true
        verbose: false

Enabling and disabling the plugin

Once installed, it is possible to enable and disable Data Transform Plugin using the enabled setting.

Verbose mode

Occasionally it might happen that there is a problem with a data file, and PHP notices and/or warnings with long stack traces are displayed when Pattern Lab is generated. In a large project it can be difficult to find the problematic data file, but turning on Data Transform Plugin's verbose mode using the verbose setting can help.

In verbose mode Data Transform plugin reports each pattern it processes and all data transform functions performed. It also suppresses regular PHP error messages and reports about errors in an easier to read way.

Important note: due to the way verbose mode is implemented, it might not work if other plugins that interact with the Twig Environment object are used.

Features

Pattern-specific data file support for included patterns

Pattern Lab core only supports global data files and a pattern-specific data file for the main pattern. This plugin adds pattern-specific data file support for included patterns. This feature works with the include function provided by this plugin with all PatternEngines and also with regular includes in template files with Twig PatternEngine.

Please note that global data from the _data directory is considered to be pattern-specific data and will overwrite data inherited from a parent pattern. If you want to override data of an included pattern you can use the with keyword.

Data transform functions

Currently the plugin provides four transform functions for the data read by Pattern Lab. The examples provided are in JSON but Pattern Lab supports YAML too.

Include pattern files

If a value contains the name of a pattern in shorthand partials syntax, the plugin will replace the value with the rendered pattern:

{
    "key": "atoms-form-element-label-html"
}

Advanced syntax with support for passing variables (with) and disabling access to the default data (only):

{
    "key": {
        "include()": {
            "pattern": "atoms-form-element-label-html",
            "with": {
                "title": "Textfield label"
            },
            "only": true
        }
    }
}

In both examples the value of key will replaced with the rendered pattern.

For more information about with and only please refer to the Twig include documentation.

Include pseudo-pattern files

It is also possible to include pseudo-patterns using the shorthand partials syntax, by replacing the tilde (~) with a dash (-). So for example the pseudo-pattern shila-card.html~variant.json can be included like so:

{
    "key": "molecules-shila-card-html-variant"
}

Join text values

{
    "key": {
        "join()": [
            "molecules-comment-html",
            "<div class=\"indented\">",
            "molecules-comment-html",
            "</div>",
            "molecules-comment-html"
        ]
    }
}

The value of key will be replaced with the joined strings. Note that in the example molecules-comment-html is the name of a pattern in shorthand partials syntax. These will be replaced with the rendered pattern before the join.

Create Drupal Attribute objects

{
    "key": {
        "Attribute()": {
            "id": ["edit-submit"],
            "type": ["submit"],
            "value": ["Submit"],
            "class": ["button", "button-primary"]
        }
    }
}

The value of key will be replaced with an Attribute object.

Create Drupal Url objects

{
    "key": {
        "Url()": {
            "url": "http://example.com",
            "options": {
                "attributes": {
                    "Attribute()": {
                        "class": ["link"]
                    }
                }
            }
        }
    }
}

The value of key will be replaced with an Url object. Note that in the example the value of attributes will be replaced with an Attribute object before the Url object is created.

aleksip/plugin-data-transform 适用场景与选型建议

aleksip/plugin-data-transform 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 904.3k 次下载、GitHub Stars 达 34, 最近一次更新时间为 2016 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 aleksip/plugin-data-transform 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 904.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 34
  • 点击次数: 30
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 34
  • Watchers: 3
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2016-01-12