cedcommerce/validator

一组用于管理条形码的PHP类。

2.2.0 2022-06-10 06:28 UTC

This package is not auto-updated.

Last update: 2024-09-23 17:32:27 UTC


README

一个用于检查EAN8, EAN13, UPC和GTIN条形码是否有效的PHP类(基于校验位)。

Travis CI Packagist Packagist Packagist Packagist PHP 7 ready

https://packagist.org.cn/packages/cedcommerce/validator

注意:该项目目前除了包含一些验证函数外,不做其他操作。我预计未来会添加更多功能。

安装(使用composer)

composer require cedcommerce/validator

用法

// Class instantation
$barcode = '5060411950139';
$validator = new \Ced\Validator\Barcode();
$validator->setBarcode($barcode);

// Check barcode is in valid format
if ($validator->isValid()) {
	echo 'Valid :)';
} else {
	echo 'Invalid :(';
}


// Get the barcode type
echo 'Barcode is in format of ' . $validator->getType();
// Possible formats returned are:
// (string) "GTIN" which equals constant \Ced\Validator\Barcode::TYPE_GTIN
// (string) "EAN-8" which equals constant \Ced\Validator\Barcode::TYPE_EAN_8
// (string) "EAN" which equals constant \Ced\Validator\Barcode::TYPE_EAN
// (string) "EAN Restricted" which equals constant \Ced\Validator\Barcode::TYPE_EAN_RESTRICTED
// (string) "UPC" which equals constant \Ced\Validator\Barcode::TYPE_UPC
// (string) "UPC Coupon Code" which equals constant \Ced\Validator\Barcode::TYPE_UPC_COUPON_CODE


// Returns the barcode in GTIN-14 format
$validator->getGTIN14()


// Returns the barcode as entered
$validator->getBarcode()

待办事项

  • 条形码生成
  • GS1-128条形码生成和解释

鸣谢