定制 drez/hjson-to-propel-xml 二次开发

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

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

drez/hjson-to-propel-xml

Composer 安装命令:

composer require drez/hjson-to-propel-xml

包简介

Convert JSON for Humans (HJSON) to Propel XML Schema.

README 文档

README

This is a library to convert HJSON file to Propel XML schema. I always found Propel(http://propelorm.org/) schema tedious to write. This should help make it more approchable.

Install with composer

composer require drez/hjson-to-propel-xml

Live converter

https://hjson2xml.apigoat.com

Example

Now you can write that:

{
    // database name
    goatcheese:
    {
        // custom behavior, not parameter
        add_validator:true,
        
        // timestamp behavior
        table_stamp_behavior:true,

        /* parameters for the APIgoat behavior from here, configurable custom behaviors shortcuts */
        set_debug_level:3,
        is_builder:true,
        add_hooks:{},
        with_api:true,
        /* to here */

        // table name='authy' decription='User'
        "authy('User')":{ 
            
            // parameters from the APIgoat behavior
            set_parent_menu:"Settings",
            
            // Primary column name=id_authy primaryKey=true autoincrement=true
            id_authy:["primary"],
            
            // default string column type=VARCHAR size=50
            validation_key:"string(32)",
            
            // A single-column unique index is added per column flagged "unique";
            // for a composite (multi-column) unique index use the table-level key
            // unique: [["col_a", "col_b"]] (one inner array per composite index)
            "username(Username)":["string(32)", "not-required", "unique"],
            
            // set the defaultValue=No
            is_root(Root):["enum(Yes, No)", "default:No"],

            // Add a default colunm, type=integer and add the foreign-key markup
            id_authy_group:["foreign(authy_group)", "required"],
            expire(Expiration): ["date()"]
        },
        authy_group_x:
        {
            // cross reference table, will add isCrossRef=true to the table
            is_cross_ref:true,

            // change the default settings on the foreign key
            id_authy:["foreign(authy)", "primary", "onDelete:cascade"],

            id_authy_group:["foreign(authy_group)", "primary"],
        }
    }
}

will translate to:

<database name="goatcheese" defaultIdMethod="native" namespace="App" >
        <behavior name="add_validator" />
        <behavior name="table_stamp_behavior" />
        <behavior name="GoatCheese" >
            <parameter name="set_debug_level" value="3" />
            <parameter name="is_builder" value="1" />
            <parameter name="add_hooks" value="[]" />
            <parameter name="with_api" value="1" />
        </behavior>
    <table name="authy" description="User" >
        <behavior name="GoatCheese" >
            <parameter name="set_parent_menu" value="Settings" />
        </behavior>
        <column name="id_authy" type="INTEGER" size="11" required="true" primaryKey="true" autoIncrement="true" />
        <column name="validation_key" type="VARCHAR" size="32" required="false" />
        <column name="username" description="Username" type="VARCHAR" size="32" required="false" />
        <column name="is_root" description="Root" type="ENUM" valueSet="Yes, No" required="false" defaultValue="No" />
        <column name="id_authy_group" type="INTEGER" size="11" required="true" />
        <foreign-key foreignTable="authy_group" onDelete="restrict" onUpdate="restrict" >
            <reference local="id_authy_group" foreign="id_authy_group" />
        </foreign-key>
        <column name="expire" description="Expiration" type="DATE" required="false" />
        <unique >
            <unique-column name="username" />
        </unique>
    </table>
    <table name="authy_group_x" isCrossRef="true" >
        <column name="id_authy" type="INTEGER" size="11" required="true" primaryKey="true" />
        <foreign-key foreignTable="authy" onDelete="cascade" onUpdate="restrict" >
            <reference local="id_authy" foreign="id_authy" />
        </foreign-key>
        <column name="id_authy_group" type="INTEGER" size="11" required="true" primaryKey="true" />
        <foreign-key foreignTable="authy_group" onDelete="restrict" onUpdate="restrict" >
            <reference local="id_authy_group" foreign="id_authy_group" />
        </foreign-key>
    </table>
</database>

USE

$text = file_get_contents($this->rootDir . DIRECTORY_SEPARATOR . $hjson_file);

// make sure we have unix style text regardless of the input
$std = mb_ereg_replace('/\r/', "", $text);
$hjson = $cr ? mb_ereg_replace("\n", "\r\n", $std) : $std;

// use of laktak/hjson(https://github.com/hjson/hjson-php) to convert the HJSON to array
$parser = new \HJSON\HJSONParser();
$obj = $parser->parse($hjson, ['assoc' => true]);

// convert Hjson to Propel schema
$HjsonToXml = new \HjsonToPropelXml\HjsonToPropelXml();
$HjsonToXml->convert($obj);

Schema

  • You can use all Propel column type
  • You can specify any Propel column attributes as attribut:value
  • You are encouraged to add your own shortcuts for the most used type!

TODO

  • Make more keyword shortcut (String(32)), and find the best defaults!
  • Propel validations
  • Add table validations, warn on potential problems
  • Add custom behavior validations
  • Tests

License

MIT

drez/hjson-to-propel-xml 适用场景与选型建议

drez/hjson-to-propel-xml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 drez/hjson-to-propel-xml 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-15