承接 xayan/dataflow 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

xayan/dataflow

Composer 安装命令:

composer require xayan/dataflow

包简介

A data manipulation library

README 文档

README

A multi-purpose data manipulation library

A data manipulation library is meant to, well, manipulate data. This library introduces two main classes: Entity and EntityCollection. The first one accumulates data, the second one allows batch operations on entities. But that's not all, another feature of this library is data import/export. As for now, only CSV files are supported, but more are to come. That way you can easily make scripts that will import some data, process it and then output it in desired form (a string or a file).

Installation

Package is available through composer:

composer require xayan/dataflow

Usage

Let's assume the following CSV file:

λ cat your_file.csv

id,firstName,lastName,age
1,John,Doe,10
2,Mickey,Mouse,50
3,Philip J.,Fry,25

Now, let's say we want to filter this data to contain only adults. Also, I don't like the fact that first name and last name are separated. So let's change that:

<?php
require_once 'vendor/autoload.php';

use DataFlow\Data\Entity;
use DataFlow\IO\CSV\Export;
use DataFlow\IO\CSV\ExportPolicy;
use DataFlow\IO\CSV\Import;
use DataFlow\IO\CSV\ImportPolicy;

$file = 'your_file.csv';

$header = fgetcsv(fopen($file, 'r'));

// This will create ImportPolicy that will import all available columns, using file header as a reference:
$importPolicy = ImportPolicy::fromHeader($header);

$collection = Import::fromFile($file, $importPolicy);

$newCollection = $collection->filter(function(Entity $entity) {
    // Select only entities that contain the 'age' property and its value is >= 18
    return $entity->has('age') && $entity->get('age') >= 18;
})->map(function(Entity $entity) {
    // Set a new property
    $entity->set('name', $entity->get('firstName') . ' ' . $entity->get('lastName'));

    // Remove properties
    $entity->remove('firstName');
    $entity->remove('lastName');

    // Remember to return it
    return $entity;
});

// Create ExportPolicy automatically from an entity, so all data will be exported
$exportPolicy = ExportPolicy::fromEntity($newCollection->get(0));

// Create a new file and write export contents to it
$outputFile = fopen('another_file.csv', 'w');
Export::toStream($outputFile, $newCollection, $exportPolicy);

If you execute this script, the output should look like this:

λ cat another_file.csv

id,age,name
2,50,"Mickey Mouse"
3,25,"Philip J. Fry"

Features

Current version of the library is v1.0. Only the basic features are implemented, but they still have some potential.

What it can do now

  • Each Entity can have any number of properties of any primitive type
  • EntityCollection implements basic functions for data manipulation, that is: each, map, count and filter
  • Import from and export to CSV - you can specify from which columns/properties data should be imported to/exported from, and whether to throw exceptions or not when data is missing
  • Full unit tests are implemented to make sure future changes won't mess up current functionality

Plans for the future

  • JSON support
  • PDO support
  • Child entities
  • Type definitions
  • Data validation

Footnotes

This library is a private project and I can't guarantee it will work 100% of the time.

xayan/dataflow 适用场景与选型建议

xayan/dataflow 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 xayan/dataflow 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-10