2017 © Pedro Peláez
 

library isbn

A PHP library to convert and validate ISBN & EAN

image

biblys/isbn

A PHP library to convert and validate ISBN & EAN

  • Wednesday, November 22, 2017
  • by biblys
  • Repository
  • 7 Watchers
  • 9 Stars
  • 7,358 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 10 Versions
  • 19 % Grown

The README.md

biblys/isbn

tests Latest Stable Version Total Downloads License Gitpod ready-to-code, (*1)

biblys/isbn can be used to:, (*2)

  • validate a string against the ISBN-10, ISBN-13 and EAN-13 formats
  • convert an ISBN to ISBN-10, ISBN-13, EAN-13, GTIN-14 and ISBN-A/DOI formats
  • parse an ISBN to extract registration agency, publisher code, publication code, checksum, etc.

CHANGELOG, (*3)

Installation

  • Requirements: PHP 7.2 or above

Install with composer:, (*4)

composer require biblys/isbn:~3.0

Usage

Convert

Use case: converting an EAN (9782843449499) to an ISBN-13 (978-2-84344-949-9)., (*5)

<?php

use Biblys\Isbn\Isbn;

try {
    $input = "9782843449499";
    $isbn13 = Isbn::convertToIsbn13($input);
    echo "ISBN-13: $isbn13"; // Prints ISBN-13: 978-2-84344-949-9
} catch(Exception $e) {
    echo "An error occurred while attempting to format ISBN $input: ".$e->getMessage();
}

All formatting methods:, (*6)

  • Isbn::convertToIsbn10
  • Isbn::convertToIsbn13
  • Isbn::convertToEan13
  • Isbn::convertToGtin14
  • Isbn::convertToIsbnA

Validate

Use case: validating an incorrectly formed ISBN-13 (978-2-843-44949-9, should be 978-2-84344-949-9)., (*7)

<?php

use Biblys\Isbn\Isbn;

try {
    $input = "978-2-843-44949-9";
    Isbn::validateAsIsbn13($input);
    echo "ISBN $input is valid!";
} catch(Exception $e) { // Will throw because third hyphen is misplaced
    echo "ISBN $input is invalid: ".$e->getMessage();
}

All validating methods:, (*8)

  • Isbn::validateAsIsbn10
  • Isbn::validateAsIsbn13
  • Isbn::validateAsEan13
  • Isbn::isParsable

Learn more about validating ISBNs, (*9)

Parse

Use case: extracting the publisher code from an ISBN., (*10)

<?php
use Biblys\Isbn\Isbn;

$input = "9782956420132";
$isbn = Isbn::parse($input);
echo $isbn->getRegistrantElement(); // Prints "9564201"

Isbn::parse returns a ParsedIsbn object implementing the following methods: - ParsedIsbn->getGs1Element:: EAN product code - ParsedIsbn->getRegistrationGroupElement: Country, geographical region or language aera code - ParsedIsbn->getRegistrantElement: Publisher (or imprint within a group) code - ParsedIsbn->getPublicationElement: Publication code - ParsedIsbn->getCheckDigit: Checksum used for validation, (*11)

Development

Using Gitpod

You can start a dev environment by clicking Gitpod ready-to-code and start hacking in your browser right away!, (*12)

Locally

If you'd rather set up a local dev environment, you'll need:, (*13)

  • PHP 7.x
  • Composer
  • (Optional) Docker to run tests and debug against different version of PHP

Clone this repository and run composer install to get started!, (*14)

Tests

Run tests with PHPUnit:, (*15)

composer install
composer test

Run tests in a docker container:, (*16)

composer docker:test

Run tests in a docker container using a specific PHP version:, (*17)

PHP_VERSION=7.1 composer docker:test

ISBN ranges update

New ISBN ranges may be added from time to time by the International ISBN Agency. Whenever it happens, this library must be updated. If a range update is necessary, please open an issue on GitHub. You can also open a pull request after updating the ranges your self with the following commands:, (*18)

composer install
composer run update-ranges

Or using a docker container:, (*19)

composer docker:update-ranges

Create a minor release after ranges autoupdate

read "PR_NUMBER?Pull request number: "
gh pr merge --auto -dr "$PR_NUMBER" \
    && git fetch --tags \
    && CURRENT_VERSION=$(git tag --sort=-v:refname | head -n 1) \
    && IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" \
    && NEW_VERSION="$major.$minor.$((patch + 1))" \
    && read "RELEASE_NOTES?Release notes: " \
    && gh release create "$NEW_VERSION" --title "$NEW_VERSION" --notes "$RELEASE_NOTES"

Changelog

See GitHub releases, (*20)

The Versions

22/11 2017

dev-master

9999999-dev https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

22/11 2017

dev-develop

dev-develop https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

22/11 2017

dev-hotfix/2.0.6

dev-hotfix/2.0.6 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

22/11 2017

2.0.6

2.0.6.0 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

07/11 2017

2.0.5

2.0.5.0 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

29/06 2017

2.0.4

2.0.4.0 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

06/07 2016

2.0.3

2.0.3.0 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

13/04 2016

2.0.2

2.0.2.0 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

11/04 2016

2.0.1

2.0.1.0 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn

01/03 2016

2.0.0

2.0.0.0 https://github.com/biblys/isbn

A PHP library to convert and validate ISBN & EAN

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Clement Bourgoin

ean book isbn