php-etl/fast-map-config
Composer 安装命令:
composer require php-etl/fast-map-config
包简介
This library implements the Extract-Transform-Load pattern asynchronously in PHP with the help of iterators and generators
README 文档
README
Example 1: configure mapping for an array
<?php use Kiboko\Component\FastMapConfig\ArrayBuilder; use Kiboko\Component\FastMap\Compiler; use Kiboko\Component\FastMap\PropertyAccess\EmptyPropertyPath; use Symfony\Component\ExpressionLanguage\ExpressionFunction; $input = [ 'customer' => [ 'firstName' => 'John', 'lastName' => 'Doe', 'email' => 'joh@example.com', ], 'items' => [ [ 'sku' => '123456', 'price' => [ 'value' => 123.45, 'currency' => 'EUR', ], 'weight' => [ 'value' => 123.45, 'KILOGRAM', ], ], [ 'sku' => '234567', 'price' => [ 'value' => 23.45, 'currency' => 'EUR', ], 'weight' => [ 'value' => 13.45, 'KILOGRAM', ], ], ], 'shippings' => [ [ 'sku' => '123456', 'price' => [ 'value' => 123.45, 'currency' => 'EUR', ], ], [ 'sku' => '234567', 'price' => [ 'value' => 23.45, 'currency' => 'EUR', ], ], ], ]; $compiler = new Compiler\Compiler(new Compiler\Strategy\Spaghetti()); $interpreter = new Symfony\Component\ExpressionLanguage\ExpressionLanguage(); $interpreter->addFunction(ExpressionFunction::fromPhp('array_merge', 'merge')); $interpreter->addFunction(new ExpressionFunction( 'price', function (array $context, float $value, string $currency) { return sprintf('\sprintf("%%s %%s", \number_format(%s, 2), "%s")', $value, addslashes($currency)); }, function (array $context, float $value, string $currency) { return sprintf('%s %s', number_format($value, 2), $currency); } )); $mapper = (new ArrayBuilder(null, $interpreter)) ->children() ->constant('[type]', 'ORDER') ->copy('[customer][first_name]', '[customer][firstName]') ->copy('[customer][last_name]', '[customer][lastName]') ->list('[products]', 'merge( input["items"], input["shippings"] )') ->children() ->copy('[sku]', '[sku]') ->expression('[price]', 'price( input["price"]["value"], input["price"]["currency"] )') ->end() ->end() ->end() ->getMapper(); $compiler = new Compiler\Compiler(new Compiler\Strategy\Spaghetti()); $mapper = $compiler->compile( Compiler\StandardCompilationContext::build( new EmptyPropertyPath(), __DIR__, 'Foo\\ArraySpaghettiMapper' ), $mapper ); var_dump($mapper($input, [], new EmptyPropertyPath()));
Example 2: configure mapping for an object
<?php use Kiboko\Component\FastMapConfig\CompositeBuilder; use Kiboko\Component\FastMapConfig\ObjectBuilder; use Kiboko\Component\FastMap\Compiler; use Kiboko\Component\FastMap\PropertyAccess\EmptyPropertyPath; class Order { public ?Customer $customer = null; public iterable $products; public function __construct() { $this->products = []; } } class Customer { public string $firstName; public string $lastName; } class Product { public string $sku; public ?Price $price = null; } class Price { public float $amount; public string $currency; } $mapper = (new ObjectBuilder(Order::class, null, $interpreter)) ->children() ->object('customer', 'input["customer"]', Customer::class) ->children() ->merge( (new CompositeBuilder(null, $interpreter)) ->copy('firstName', '[firstName]') ->copy('lastName', '[lastName]') ) ->end() ->end() ->collection('products', 'merge( input["items"], input["shippings"] )', Product::class) ->children() ->copy('sku', '[sku]') ->object('price', 'input["price"]', Price::class) ->children() ->expression('amount', 'input["value"]') ->expression('currency', 'input["currency"]') ->end() ->end() ->end() ->end() ->end() ->getMapper(); var_dump($mapper($input, [], new EmptyPropertyPath())); $compiler->compile( Compiler\StandardCompilationContext::build(new EmptyPropertyPath(), __DIR__, 'Foo\\ObjectSpaghettiMapper'), $mapper );
<?php use Kiboko\Component\FastMapConfig\ArrayBuilder; $builder = new ArrayBuilder(); $builder ->children() ->expression('[additionalUnits.0.code]', 'coalesce(input["units"][0], null)') ->expression('[additionalUnits.1.code]', 'coalesce(input["units"][1], null)') ->expression('[additionalUnits.2.code]', 'coalesce(input["units"][2], null)') ->end();
php-etl/fast-map-config 适用场景与选型建议
php-etl/fast-map-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.9k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 php-etl/fast-map-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 php-etl/fast-map-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-07