承接 neam/php-sie 相关项目开发

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

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

neam/php-sie

Composer 安装命令:

composer require neam/php-sie

包简介

PHP port of https://github.com/barsoom/sie

关键字:

README 文档

README

Parser and generator for SIE files (http://sie.se/).

PHP port of https://github.com/barsoom/sie

Current implementation requires PHP 5.6.5 or greater.

Installation

Via composer:

composer require neam/php-sie

Generating a SIE file

To generate a SIE document you first need to define a class that implements \sie\document\IDataSource or extends abstract class \sie\document\DataSource.

$mySieFileDataSource = new MySieFileDataSource($this);
$sieFileDocument = $mySieFileDataSource->generateSieDocument();
$sieFileContents = $sieFileDocument->render();
file_put_contents('sie_file.se', $sieFileContents);

Check the files in tests/unit/*Test.php for more examples.

Parsing a SIE file

You can parse sie data from anything that responds to each_line like a file or a string.

$file_contents = file_get_contents('sie_file.se');
$parser = new \sie\Parser();
$sie_file = $parser->parseSieFileContents($file_contents);
return $this->parse($data);

// The company name
puts sie_file.entries_with_label("fnamn").first.attributes["foretagsnamn"]

// The first account number
puts sie_file.entries_with_label("konto").first.attributes["kontonr"]

The parser expects file contents in CP437 encoding (the official encoding of the SIE file format). If you want to parse UTF8 strings, use the "parse" method:

$sie_file = $parser->parse($utf8_string);

By default the parser will raise an error if it encounters unknown entry types. Use the lenient option to avoid this:

$parser = new \sie\Parser(["lenient" => true]);

Check the files in tests/integration/*Test.php for more examples.

Developing

First time setup:

composer install

Running tests:

vendor/bin/codecept build
vendor/bin/codecept run

Tests sample output:

# vendor/bin/codecept run --debug
Codeception PHP Testing Framework v2.2.4
Powered by PHPUnit 5.4.8 by Sebastian Bergmann and contributors.

Integration Tests (8) ----------------------------------------------------------------------------------------------
Modules: \Helper\Integration
--------------------------------------------------------------------------------------------------------------------
✔ FileParserTest: Parses a file (0.07s)
✔ FileParserTest: Parses a file with unknown entries using a lenient parser (0.01s)
✔ FileParserTest: Parses a file with unknown entries using a strict parser (0.05s)
✔ Fortnox21FileParserTest: Parses sie1 se file (0.09s)
✔ Fortnox21FileParserTest: Parses sie2 se file (0.25s)
✔ Fortnox21FileParserTest: Parses sie3 se file (0.27s)
✔ Fortnox21FileParserTest: Parses sie4 se file (0.51s)
✔ Fortnox21FileParserTest: Parses sie4 si file (0.29s)
--------------------------------------------------------------------------------------------------------------------

Unit Tests (39) ----------------------------------------------------------------------------------------------------
Modules: \Helper\Unit
--------------------------------------------------------------------------------------------------------------------
✔ BuildEntryTest: Call (0.05s)
✔ BuildEntryTest: Call with an unquoted zero string (0.00s)
✔ BuildEntryTest: Call with short dimensions array (0.00s)
✔ BuildEntryTest: Call with long dimensions array (0.00s)
✔ BuildEntryTest: Call with simple attribute (0.00s)
✔ BuildEntryTest: Call with an unexpected token at start of array (0.00s)
✔ DocumentTest: Adds a header (0.02s)
✔ DocumentTest: Has accounting years (0.01s)
✔ DocumentTest: Has accounts (0.01s)
✔ DocumentTest: Has dimensions (0.01s)
✔ DocumentTest: Has objects (0.01s)
✔ DocumentTest: Has balances brought forward (0.01s)
✔ DocumentTest: Has balances carried forward (0.01s)
✔ DocumentTest: Has closing account balances (0.01s)
✔ DocumentTest: Has vouchers (0.01s)
✔ DocumentTest: Truncates really long descriptions (0.01s)
✔ DocumentTest: Ensures there are at least two lines with a zeroed single voucher line (0.01s)
✔ DocumentTest: Reads the series from the voucher with a series defined (0.01s)
✔ ParserTest: Parses sie data that includes arrays (0.00s)
✔ ParserTest: Handles leading whitespace (0.00s)
✔ RendererTest: Replaces input of the wrong encoding with questionmark (0.00s)
✔ VoucherSeriesTest: Self for | #0 (0.00s)
✔ VoucherSeriesTest: Self for | #1 (0.00s)
✔ VoucherSeriesTest: Self for | #2 (0.00s)
✔ VoucherSeriesTest: Self for | #3 (0.00s)
✔ VoucherSeriesTest: Self for | #4 (0.00s)
✔ LineParserTest: It parses lines from a sie file (0.00s)
✔ LineParserTest: Using a lenient parser it raises no error when encountering unknown entries (0.00s)
✔ LineParserTest: Using a strict parser it raises error when encountering unknown entries (0.00s)
✔ TokenizerTest: Tokenizes the given line (0.00s)
✔ TokenizerTest: Can parse metadata arrays (0.00s)
✔ TokenizerTest: Handles escaped quotes in quoted strings (0.00s)
✔ TokenizerTest: Handles escaped quotes in non quoted strings (0.00s)
✔ TokenizerTest: Handles escaped backslash in strings (0.00s)
✔ TokenizerTest: Has reasonable behavior for consecutive escape characters (0.00s)
✔ TokenizerTest: Handles tab character as field separator (0.00s)
✔ TokenizerTest: Handles unquoted zeros (0.01s)
✔ TokenizerTest: Handles transaction with dimension array (0.00s)
✔ TokenizerTest: Rejects control characters (0.00s)
--------------------------------------------------------------------------------------------------------------------


Time: 2.84 seconds, Memory: 12.00MB

OK (47 tests, 133 assertions)

neam/php-sie 适用场景与选型建议

neam/php-sie 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 107.92k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2016 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 neam/php-sie 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 107.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 15
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-21