lamoda/gs1-barcode-parser

GS1条形码解析器和验证器,兼容官方GS1文档

1.1.0 2022-02-14 08:35 UTC

This package is auto-updated.

Last update: 2024-09-14 14:36:31 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Build Status

安装

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());
}