PHPackages                             macfja/book-retriever - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. macfja/book-retriever

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

macfja/book-retriever
=====================

Library to retrieve data about books

1.1.1(5y ago)31121[6 issues](https://github.com/MacFJA/BookRetriever/issues)[1 PRs](https://github.com/MacFJA/BookRetriever/pulls)MITPHPPHP &gt;=7.2

Since Mar 29Pushed 4y ago1 watchersCompare

[ Source](https://github.com/MacFJA/BookRetriever)[ Packagist](https://packagist.org/packages/macfja/book-retriever)[ RSS](/packages/macfja-book-retriever/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (17)Versions (5)Used By (0)

Book Retriever
==============

[](#book-retriever)

Library to retrieve data about books

Installation
------------

[](#installation)

```
composer require macfja/book-retriever
```

Usage
-----

[](#usage)

### Simple provider

[](#simple-provider)

To get information of a book on a specific provider:

```
$htmlGetter = new \MacFJA\BookRetriever\Helper\HtmlGetter();
$isbnTool = new \Isbn\Isbn();

$antoineOnline = new \MacFJA\BookRetriever\Provider\AntoineOnline($htmlGetter, $isbnTool);
$books = $antoineOnline->searchIsbn('9782253006329');
// $books contains a list of \MacFJA\BookRetriever\SearchResultInterface
```

### Configurable provider

[](#configurable-provider)

To get information of a book with a configurable provider:

```
$providerConfiguration = ...; // A class that implement \MacFJA\BookRetriever\ProviderConfigurationInterface
$configurator = new \MacFJA\BookRetriever\ProviderConfigurator($providerConfiguration);
$amazon = new \MacFJA\BookRetriever\Provider\Amazon();
$configurator->configure($amazon);
$books = $amazon->searchIsbn('9782253006329');
// $books contains a list of \MacFJA\BookRetriever\SearchResultInterface
```

### Multiple providers

[](#multiple-providers)

Using the `Pool` provider to request several providers:

```
$providerConfiguration = ...; // A class that implement \MacFJA\BookRetriever\ProviderConfigurationInterface
$configurator = new \MacFJA\BookRetriever\ProviderConfigurator($providerConfiguration);

$htmlGetter = new \MacFJA\BookRetriever\Helper\HtmlGetter();
$isbn = new \Isbn\Isbn();
$opds = new \MacFJA\BookRetriever\Helper\OPDSParser();
$sru = new \MacFJA\BookRetriever\Helper\SRUParser();

$providers = [
    new \MacFJA\BookRetriever\Provider\AbeBooks($htmlGetter),
    new \MacFJA\BookRetriever\Provider\Amazon(),
    new \MacFJA\BookRetriever\Provider\AntoineOnline($htmlGetter, $isbn),
    new \MacFJA\BookRetriever\Provider\ArchiveOrg($opds),
    new \MacFJA\BookRetriever\Provider\LibraryHub($sru),
    new \MacFJA\BookRetriever\Provider\DigitEyes(),
    new \MacFJA\BookRetriever\Provider\Ebay()
];
array_walk($providers, [$configurator, 'configure']);

$pool = new \MacFJA\BookRetriever\Pool($providers, $providerConfiguration);

$books = $pool->searchIsbn('9782253006329');
// $books contains a list of \MacFJA\BookRetriever\SearchResultInterface
```

If you use an dependency injection library, lots of code can be remove. (see below for a Symfony example)

### With Symfony (and Doctrine)

[](#with-symfony-and-doctrine)

An example of integration in Symfony with configuration stored in database with Doctrine as ORM.

`config/services.yaml`

```
services:
    _instanceof:
        # services whose classes are instances of ProviderInterface will be tagged automatically
        MacFJA\BookRetriever\ProviderInterface:
            tags: ['app.provider']
    MacFJA\BookRetriever\:
        resource: '../vendor/macfja/book-retriever/lib/'
    MacFJA\BookRetriever\Pool:
        arguments:
            $providers: !tagged_iterator app.provider
    MacFJA\BookRetriever\ProviderConfigurationInterface: '@App\Repository\ProviderConfigurationRepository'
```

`src/Entity/ProviderConfiguration.php`

```
