Download the PHP package nicebooks/isbn without Composer

On this page you can find all versions of the php package nicebooks/isbn. 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 isbn

Nicebooks ISBN library for PHP

This library provides functionality for validating, formatting, and converting ISBN numbers. It powers the nicebooks.com website and is available for use under the permissive MIT open-source license.

ISBN validation and formatting follow the rules defined by the ISBN range file published by the International ISBN Agency.

Build Status Coverage Status Latest Stable Version Total Downloads License

Installation

This library is installable via Composer:

Requirements

The current version of this library requires PHP 8.2 or higher.

You may use earlier versions of nicebooks/isbn with earlier versions of PHP, but you will only receive ISBN range updates if you use the latest version.

Project status & release process

While this library is still under development, it is well tested and should be stable enough to use in production environments. It is currently in use in production on nicebooks.com.

The current releases are numbered 0.x.y. When a non-breaking change is introduced (updating ISBN ranges, adding new methods, optimizing existing code, etc.), y is incremented.

When a breaking change is introduced, a new 0.x version cycle is always started.

It is therefore safe to lock your project to a given release cycle, such as 0.8.*.

If you need to upgrade to a newer release cycle, check the release history for a list of changes introduced by each further 0.x.0 version.

Overview

The Isbn class

The Isbn class is an abstract, immutable class representing an ISBN-10 or ISBN-13 with a valid format and a valid check digit.

It has 2 subclasses: Isbn10 and Isbn13, allowing for narrower typing if your application expects only ISBN-10 or only ISBN-13 at some point.

An Isbn instance is obtained with the of() factory method:

You can also use the Isbn10::of() and Isbn13::of() factory methods, which will attempt to convert the given ISBN to the corresponding subclass:

If the given string does not have a valid format or check digit, an InvalidIsbnException is thrown.

[!NOTE] Before validation, the provided string is stripped of all non-alphanumeric ASCII characters.

Checking the type of an ISBN

You can check the type of an ISBN with the is10() and is13() methods:

You can also use instanceof checks:

Converting between ISBN-10 and ISBN-13

An ISBN-10 can be converted to an ISBN-13 with the to13() method:

An ISBN-13 can be converted to an ISBN-10 with the to10() method:

Only ISBN-13 numbers starting with 978 can be converted to ISBN-10. You can check if an ISBN can be converted to an ISBN-10 with the isConvertibleTo10() method:

If you call to10() on an ISBN-13 that does not start with 978, an IsbnNotConvertibleException is thrown.

Comparing ISBN numbers

You can compare two Isbn instances with the isEqualTo() method. An ISBN-10 can be compared to an ISBN-13, and the comparison will be successful if both numbers resolve to the same ISBN-13 number:

Validating an ISBN

While an Isbn instance is guaranteed to have a valid format and a valid check digit, it may not belong to a valid range according to the range file published by the International ISBN Agency.

The Isbn class provides two methods to further validate an ISBN:

Method Description
hasValidRegistrationGroup() Only checks if the ISBN belongs to a known registration group.
isValid() Checks if the ISBN belongs to a known registration group and a known range.
This is the highest level of validation that can be performed by looking at the ISBN number alone.

[!NOTE] Which ISBNs are considered valid depends on the library version you are using. This library is kept in sync with the ISBN ranges published by the International ISBN Agency, so keep it up to date for proper validation.

Formatting an ISBN

The library provides two methods to format an ISBN:

Method Description ISBN-10 example ISBN-13 example
toString() Returns the unformatted ISBN 133887893X 9781338878936
toFormattedString() Returns the formatted ISBN if the ISBN is valid, otherwise returns the unformatted number 1-338-87893-X 978-1-338-87893-6

Splitting an ISBN into parts

An ISBN-13 is divided into 5 parts:

While an ISBN-10 is divided into 4 parts:

The Isbn class provides getters for each part:

Part Example Description Getter
A 978 Prefix getRegistrationGroup()->prefix
B 1 Registration group identifier getRegistrationGroup()->identifier
C 338 Publisher identifier (registrant) getPublisherIdentifier()
D 87893 Title identifier (publication) getTitleIdentifier()
E 6 Check digit getCheckDigit()

[!IMPORTANT]

  • Parts A and B require hasValidRegistrationGroup() (or isValid(), which implies it)
  • Parts C and D require isValid()

You can also get the ISBN parts as an array:

[!IMPORTANT] getParts() requires isValid()

If the part you're trying to access is not available because the ISBN does not belong to a valid registration group or range, an IsbnNotRecognizedException is thrown.

Getting the registration group name

getRegistrationGroup() also exposes the group's name:

Exceptions

Exceptions live in the Nicebooks\Isbn\Exception namespace.


All versions of isbn with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 nicebooks/isbn contains the following files

Loading the files please wait ...