Download the PHP package kankro/simple-gtin-validator without Composer

On this page you can find all versions of the php package kankro/simple-gtin-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package simple-gtin-validator

simple-gtin-validator

Lightweight PHP library for validating GTIN (Global Trade Item Number) values and generating check digits.

GTIN is the umbrella format behind common barcode identifiers such as GTIN-8, UPC, EAN, and GTIN-14. This package normalizes the input, applies prefix filtering, and verifies the checksum used by the GTIN standard.

Contents

Requirements

Installation

Install the package with Composer:

Then load Composer's autoloader in your project:

What the library does

The GtinValidator class provides two public operations:

Supported GTIN lengths for validation:

Accepted input styles:

Inputs are normalized before validation: numeric values are cast to strings, and hyphens are removed from string inputs.

Quick start

Working flow

Validation flow

When you call isValidGtin($code), the validator works in this order:

  1. Normalize the input
    • Numeric values are converted to strings
    • String inputs are trimmed and hyphens are removed
  2. Check the prefix
    • The validator rejects codes that begin with configured restricted prefixes
  3. Validate format
    • The code must be numeric
    • The length must be 8, 12, 13, or 14 digits
  4. Verify the check digit
    • The value is left-padded to 14 digits
    • The GTIN checksum is calculated and compared with the last digit

Check digit generation flow

When you call addCheckDigit($code), the validator:

  1. Normalizes the input
  2. Left-pads the value to 13 digits
  3. Calculates the GTIN checksum
  4. Returns the normalized value with the new check digit appended

This means short inputs are padded with leading zeroes before the check digit is generated.

API reference

isValidGtin($code): bool

Validates a GTIN code after normalization, prefix checks, and checksum verification.

Parameters

Returns

Throws

addCheckDigit($code): string

Generates and appends a GTIN check digit.

Parameters

Returns

Usage examples

Validate a standard GTIN

Validate input with hyphens

Hyphens are removed before validation, so this behaves the same as validating 9780552133265.

Understand a rejected code

This value is mathematically well-formed as an ISBN-style identifier, but the default prefix filter rejects 978 and 979.

Generate a check digit

Prefix filtering

The validator includes a public static prefix list that is checked before checksum validation:

By default, the list excludes these prefixes:

This is important because some values may have a valid checksum but still return false due to business rules in the prefix list.

If your use case needs different behavior, you can adjust the static list before validating:

Development workflow

This repository is intentionally minimal and currently does not include a dedicated automated test suite.

Useful local checks:

Typical workflow for local changes:

  1. Install dependencies with Composer if needed
  2. Update the source or documentation
  3. Run composer validate --no-check-publish
  4. Run php -l src/GtinValidator.php
  5. Manually verify usage with a small PHP script or php -r

Limitations

License

Apache-2.0

Credits


All versions of simple-gtin-validator with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kankro/simple-gtin-validator contains the following files

Loading the files please wait ...