lamoda / gs1-barcode-parser
GS1条形码解析器和验证器,兼容官方GS1文档
1.1.0
2022-02-14 08:35 UTC
Requires
- php: ^7.1 | ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- phpunit/phpunit: ^7.5.20 | ^8.2 | ^9.0
README
安装
Composer
composer require lamoda/gs1-barcode-parser
描述
此库根据GS1通用规范和GS1数据矩阵指南提供GS1条形码的解析。
库还提供了一个通用的条形码内容验证器。
用法
解析器
<?php $config = new \Lamoda\GS1Parser\Parser\ParserConfig(); $parser = new \Lamoda\GS1Parser\Parser\Parser($config); $value = ']d201034531200000111719112510ABCD1234'; $barcode = $parser->parse($value); // $barcode is an object of Barcode class
验证器
<?php $parserConfig = new \Lamoda\GS1Parser\Parser\ParserConfig(); $parser = new \Lamoda\GS1Parser\Parser\Parser($parserConfig); $validatorConfig = new \Lamoda\GS1Parser\Validator\ValidatorConfig(); $validator = new \Lamoda\GS1Parser\Validator\Validator($parser, $validatorConfig); $value = ']d201034531200000111719112510ABCD1234'; $resolution = $validator->validate($value); if ($resolution->isValid()) { // ... } else { var_dump($resolution->getErrors()); }