artemsway / parser1c
用于解析 CommerceML2 文件的包。
dev-master
2017-06-13 10:58 UTC
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is not auto-updated.
Last update: 2024-09-26 02:39:14 UTC
README
该库的主要目标是解析 CommerceML 2 标准的 XML 文件,并将数据表示为对象。
安装
- 更新您的 composer.json 文件。
"repositories": [ { "type": "vcs", "url": "https://github.com/ArtemsWay/parser1c" } ], "require": { "artemsway/parser1c": "dev-master" },
- 执行命令
composer update
。
使用
require 'vendor/autoload.php'; $importFile = 'path/to/file/import0_1.xml'; $offersFile = 'path/to/file/offers0_1.xml'; $importData = \ArtemsWay\Parser1C\Parser1C::parseImportFile($importFile); $offersData = \ArtemsWay\Parser1C\Parser1C::parseOffersFile($offersFile);
输出数据
var_dump($importData); array:6 [▼ "schemaVersion" => "2.07" "importTime" => "2017-05-13T21:41:15" "onlyChanges" => false "categories" => array:218 [▶] "properties" => array:608 [▶] "products" => array:4535 [▶] ] var_dump($offersData); array:6 [▼ "schemaVersion" => "2.07" "importTime" => "2017-05-13T21:41:15" "onlyChanges" => false "priceTypes" => array:1 [▶] "warehouses" => array:2 [▶] "offers" => array:4535 [▶] ]
扩展
可能解析部分数据。
use ArtemsWay\Parser1C\Parser1C; use ArtemsWay\Parser1C\Parsers\DOM\ImportParser; $importFile = 'path/to/file/import0_1.xml'; $parser = new Parser1C($importFile, new ImportParser); $partOfData = $parser->load()->parseProducts()->getData();
可以添加新的解析器类。
use ArtemsWay\Parser1C\Parsers\DOM\DOMParser; use ArtemsWay\Parser1C\Parsers\ParserInterface; class ContractorParser extends DOMParser { public $contractors = []; public function parseContractors() { ... } }
使用
use ArtemsWay\Parser1C\Parser1C; use ArtemsWay\Parser1C\Parsers\DOM\ImportParser; $contractorsFile = 'path/to/file/contractors0_1.xml'; $parser = new Parser1C($contractorsFile, new ContractorParser); $partOfData = $parser->load()->parseAll()->getData();
待办事项
- 添加 SAX 解析器,以减少 RAM 内存消耗。