QIF 解析器

dev-master 2019-01-29 20:33 UTC

This package is not auto-updated.

Last update: 2024-09-20 02:23:57 UTC


README

该库可以将 QIF 文件解析为交易对象以便于处理。

<?php
/**
 * General usage.
 */
$parser = new JasonStanley\QIF\Parser();
$results = $parser->parseString($somestring);
$results = $parser->parseFile('./path/to/file.qif');

/**
 * Check if the thing parsed is valid.
 */
$results->isValid();

/**
 * Get the parsed transactions.
 */
$transactions = $results->getComplete();
$transactions[0]->getAmount(); // -1.23
$transactions[0]->getPayee(); // SOME LONG PAYEE STRING £1.00
$transactions[0]->getDate(); // 10/10/2018

/**
 * If validation failed you can see why as follows.
 * Incomplete returns an array of transactions which couldn't be parsed along with an error.
 */
$failed = $results->getIncomplete();
$failed[0]->getErrors();

几点注意事项。

$transaction->getDate() 不返回一个日期时间对象。主要原因是我不知道日期格式,并且我没有看到可以在不分析文件的情况下进行。据我所知,一些 QIF 文件有 dd/mm/yy 或 dd/mm/yyyy 或 mm/dd/yy 等格式,但没有标准化格式。

$transaction->getAmount() 不返回一个货币对象。我曾经考虑允许开发者指定一个工厂来创建交易货币对象。我可能还会回到这个想法。

路线图

1.0

  • 添加金额验证以确保数字是浮点数
  • 添加货币工厂以允许开发者指定货币对象的构造
  • 创建一个助手来处理收款人行