承接 apfelfrisch/edifact 相关项目开发

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

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

apfelfrisch/edifact

Composer 安装命令:

composer require apfelfrisch/edifact

包简介

Parse, build, serialize and validate UN/EDIFACT messages

README 文档

README

Unit test Static Analysis Mutation tests

Parse, build, serialize and validate UN/EDIFACT Messages in a memory efficient way.

You will likely have to generate your own Segments, see php-edifact/edifact-mapping for XML Mappings. I have done a protype for autogeneration, it should give you a good starting point.

If you don't need validation or Segment getter you can also parse to the generic Segment.

Usage

Parse EDIFACT Messages

Load Segment Classes

You can add your Segments to the Factory like so:

use Apfelfrisch\Edifact\Segment\SegmentFactory;

$segmentFactory = new SegmentFactory;
$segmentFactory->addSegment('SEQ', \My\Namespace\Segments\Seq::class);

After that you can either mark the Factory as default:

$segmentFactory->markAsDefault();

or you inject the Factory in the Message:

use Apfelfrisch\Edifact\Segment\SegmentFactory;

$message = Message::fromString("UNA:+.? 'SEQ+1", $segmentFactory);

If you don't need validation or Segment getter you can also parse to the generic Segement

use Apfelfrisch\Edifact\Segments\Generic;
use Apfelfrisch\Edifact\Segment\SegmentFactory;

$segmentFactory = new SegmentFactory;
$segmentFactory->addFallback(Generic::class);
$segmentFactory->markAsDefault();

Parse from String

use Apfelfrisch\Edifact\Message;

$message = Message::fromString("UNA:+.? 'NAD+DP++++Musterstr.::10+City++12345+DE");

Parse from File

use Apfelfrisch\Edifact\Message;

$message = Message::fromFilepath('path/to/file.txt');

Iterate over Segments

use Apfelfrisch\Edifact\Segments\SegmentInterface;

foreach ($message->getSegments() as $segment) {
    if ($segment instanceof SegmentInterface) {
        echo $segment->name();
    }
}

Filter Segments

use My\Namespace\Segments\MyNad;

foreach ($message->filterSegments(MyNad::class) as $segment) {
    echo $segment->name(); // NAD
}

$message->filterSegments(MyNad::class, fn(Nad $seg): bool 
    => $seg->street() === 'Musterstr.'
);

echo $message->findFirstSegment(MyNad::class)->name(); // NAD

Unwrap Messages

foreach ($message->unwrap() as $partialMessage) {
    echo $segment instanceof \Apfelfrisch\Edifact\Message;
}

Add Readfilter

$message->addStreamFilter('iso-to-utf8', 'convert.iconv.ISO-8859-1.UTF-8');

Build a Message:

Build with default Una

use Apfelfrisch\Edifact\Builder;
use Apfelfrisch\Edifact\Message;
use My\Namespace\Segments\MyUnb;
use My\Namespace\Segments\MyUnh;

$builder = new Builder;

$builder->writeSegments(
    MyUnb::fromAttributes('1', '2', 'sender', '500', 'receiver', '400', new DateTime('2021-01-01 12:01:01'), 'unb-ref'),
    MyUnh::fromAttributes('unh-ref', 'type', 'v-no', 'r-no', 'o-no', 'o-co')
);

$message = new Message($builder->get());

UNA and the trailing Segments (UNT and UNZ) will be added automatically. If no UNA Segment is provided, it uses the default values [UNA:+.? '].

Build with custom Una

use Apfelfrisch\Edifact\Builder;
use Apfelfrisch\Edifact\Segment\UnaSegment;

$builder = new Builder(new UnaSegment('|', '#', ',', '!', '_', '"'));

If you replace the decimal seperator, be sure that the blueprint marks the value as numeric.

Write directly into File

use Apfelfrisch\Edifact\Builder;
use Apfelfrisch\Edifact\Segment\UnaSegment;

$builder = new Builder(new UnaSegment, 'path/to/file.txt');

Add Writefilter to the Builder

use Apfelfrisch\Edifact\Builder;

$builder = new Builder;
$builder->addStreamFilter('utf8-to-iso', 'convert.iconv.UTF-8.ISO-8859-1');

Validate Message Segments

use Apfelfrisch\Edifact\Message;
use Apfelfrisch\Edifact\Validation\Failure;
use Apfelfrisch\Edifact\Validation\Validator;

$message = Message::fromString("UNA:+.? 'SEQ+9999", $segmentFactory);

$validator = new Validator;

if(! $validator->isValid($message)) {
    foreach ($validator->getFailures() as $failure) {
        echo $failure instanceof Failure;
    }
}

apfelfrisch/edifact 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-25