定制 pmigut/gtin-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pmigut/gtin-validator

最新稳定版本:1.2.3

Composer 安装命令:

composer require pmigut/gtin-validator

包简介

This library is a set of static methods for GTIN validation. Methods return true if given string is publicly available GTIN-8, GTIN-12, GTIN-13 or GTIN-14 code. Checks include format, check digit and prefix.

README 文档

README

This library is a set of static methods for GTIN validation.

The library is best suited for quick validation of many codes without instantiating a new object for each code. Simple true or false is returned and no additional details are provided on failure. Only trade product codes return true, codes with restricted or special use prefixes return false.

Supported codes

  • GTIN-8 (former EAN-8)
  • GTIN-12 (former UPC)
  • GTIN-13 (former EAN-13)
  • GTIN-14

Checks performed

  • format
  • check digit
  • GS1 prefix

Implementation is based on GS1 General Specifications ver. 18, Jan 2018. Prefix list verified on 2 Jan 2026.

Installation

Via Composer

$ composer require pmigut/gtin-validator

Via Git

$ git clone git@github.com:pmigut/gtin-validator.git

Examples

Basic usage

<?php

use Pmigut\GtinValidator\Gtin8;

var_dump(Gtin8::isValid('12312312'));
// Output: false

Strict types

isValid method expects string argument. If strict_types=1 is declared, isValid may throw TypeError.

<?php
declare(strict_types=1);

use Pmigut\GtinValidator\Gtin8;

var_dump(Gtin8::isValid(12312312));
// Output: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to
// Pmigut\GtinValidator\Gtin8::isValid() must be of the type string, integer given

Leading zeros

Codes are validated as is, no leading zeros are added.

<?php

use Pmigut\GtinValidator\Gtin13;

var_dump(Gtin13::isValid('0000906332847'));
// Output: true

var_dump(Gtin13::isValid('906332847'));
// Output: false

Testing

$ composer test

License

This library is licensed under the MIT License, see LICENSE for details.

统计信息

  • 总下载量: 160.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 3
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固