pjmazenot / metamorphose

Metamorphose

安装: 3

依赖: 0

建议: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:项目

dev-master 2020-02-01 14:44 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:19 UTC


README

Software License

Metamorphose 库的设计类似于 ETL。它允许您从一个或多个数据源获取数据,在将其发送到一个或多个目标之前进行转换和验证。

这使其成为构建导入器、导出器、代理等数据转换应用的理想工具。

功能包括:

  • 使用合同系统定义整个过程
  • 合同检查器和验证器确保合同和结果的一致性
  • 从一个或多个源提取数据(字符串、文件、数据库、自定义)
  • 数据解析(数组、json、csv、xml、yaml、自定义)
  • 数据转换(许多默认处理器,自定义)
  • 数据验证(许多默认验证器,自定义)
  • 数据格式化(json、csv、xml、yaml、自定义)
  • 将数据加载到一个或多个目的地(字符串、文件、数据库、自定义)
  • 所有上述组件均可自定义

安装

composer require pjmazenot/metamorphose

入门

这是一个简单的合同示例

{
  "sources": [
    {
      "name": "source",
      "type": "string",
      "parser": "json",
      "structure": "object",
      "options": {},
      "fields": []
    }
  ],
  "destinations": [
    {
      "name": "dest",
      "type": "string",
      "formatter": "json",
      "structure": "object",
      "fields": [
        {
          "name": "firstname",
          "apply": [
            {
              "type": "value",
              "value": "$ref:source.param1"
            }
          ]
        },
        {
          "name": "lastname",
          "apply": [
            {
              "type": "value",
              "value": "$ref:source.param2"
            }
          ]
        }
      ]
    }
  ]
}

应用此转换时,您的代码将如下所示

<?php
$metamorphose = new \Metamorphose\Metamorphose('contract.json');
$metamorphose->extract([
    'source' => [
        'string' => '{"param1": "John","param2": "Smith"}'
    ],
]);
$metamorphose->transform();
$output = $metamorphose->load();

echo $output['dest'];

以下示例将显示:

{"firstname": "John","lastname": "Smith"}

文档

文档正在编写中。在此期间,您可以在功能测试套件(tests/codeception/functional/[...])中找到许多示例。