Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlatz committed Apr 18, 2019
2 parents ef2e3ed + c1e20f3 commit c9ce51f
Show file tree
Hide file tree
Showing 5 changed files with 718 additions and 577 deletions.
65 changes: 37 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/biblys/isbn.svg?branch=master)](https://travis-ci.org/biblys/isbn)

This package can be used to :
This package can be used to:

- validate an ISBN code
- convert codes between ISBN-10, ISBN-13 and EAN (without hyphens) formats
Expand All @@ -13,46 +13,46 @@ This package can be used to :

Install with composer:

$ composer require biblys/isbn:~2.0
```console
composer require biblys/isbn:^2.1.0
```

## Usage

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

```php
<?php

use Biblys\Isbn\Isbn as Isbn;

// Create an ISBN object from an EAN code
$isbn = new Isbn('9791091146098');

// Check if input is a valid ISBN code
if ($isbn->isValid()) {

// Print the code in ISBN-13 format
echo $isbn->format('ISBN-13');
$isbn = new Isbn('9782843449499');

// Print the code in ISBN-10 format
echo $isbn->format('ISBN-10');
$isbn = new Isbn($ean);

// Print the checksum digit
echo $isbn->getChecksum();

// Print the registration agency
echo $isbn->getAgency();

} else {

// Show validation errors
echo $isbn->getErrors();
try {
$isbn->validate();
$isbn13 = $isbn->format("ISBN-13");
echo "ISBN-13: $isbn13";
} catch(Exception $e) {
echo "An error occured while parsing $ean: ".$e->getMessage();
}
```

## Test

Run tests with PHPUnit:

$ composer install
$ composer test
```console
composer install
composer test
```

Run tests in a docker container:

```console
composer docker
```

## ISBN ranges update

Expand All @@ -63,14 +63,23 @@ open an issue on Github.
You can also open a pull request after updating the ranges your self with the
following commands:

$ composer install
$ composer run update-ranges
```console
composer install
composer run update-ranges
```

## Changelog

### 2.0.8
### 2.1.0 (2019-04-18)

- Added a `validate` method that throws an Exception on ISBN validation errors
- Fixed [#9] Improve error output
- Added composer scripts to run tests and update ranges in a Docker container
- Updated ISBN ranges

### 2.0.8 (2019-02-07)

- Fixed [#7](https://github.com/biblys/isbn/issues/7) ISBNs with invalid product
- Fixed [#7](https://github.com/biblys/isbn/issues/7): ISBNs with invalid product
code or country code are considered valid
- Added PHP versions 7.1 & 7.2 to travis config file

Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "biblys/isbn",
"description": "A PHP library to convert and validate ISBNs & EANs",
"time": "2019-02-07",
"time": "2019-04-18",
"keywords": [
"ISBN",
"EAN",
Expand Down Expand Up @@ -32,6 +32,8 @@
},
"scripts": {
"test": "vendor/bin/phpunit tests",
"update-ranges": "php bin/update-ranges.php"
"update-ranges": "php bin/update-ranges.php",
"docker:test": "docker run --rm --volume $PWD:/app --volume $COMPOSER_HOME:/tmp composer /bin/bash -c \"composer install && composer test\"",
"docker:update-ranges": "docker run --rm --volume $PWD:/app --volume $COMPOSER_HOME:/tmp composer /bin/bash -c \"composer install && composer update-ranges\""
}
}
Loading

0 comments on commit c9ce51f

Please sign in to comment.