Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Library to retrieve data about books

License

NotificationsYou must be signed in to change notification settings

MacFJA/BookRetriever

Repository files navigation

Library to retrieve data about books

Installation

composer require macfja/book-retriever

Usage

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

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

Using thePool 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)

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 automaticallyMacFJA\BookRetriever\ProviderInterface:tags:['app.provider']MacFJA\BookRetriever\:resource:'../vendor/macfja/book-retriever/lib/'MacFJA\BookRetriever\Pool:arguments:$providers:!tagged_iterator app.providerMacFJA\BookRetriever\ProviderConfigurationInterface:'@App\Repository\ProviderConfigurationRepository'

src/Entity/ProviderConfiguration.php

<?phpnamespaceApp\Entity;useDoctrine\ORM\MappingasORM;/** @ORM\Entity(repositoryClass="App\Repository\ProviderConfigurationRepository") */class ProviderConfiguration{/**     * @ORM\Id()     * @ORM\GeneratedValue()     * @ORM\Column(type="integer")     */private$id;/** @ORM\Column(type="string", length=50) */private$provider;/** @ORM\Column(type="boolean") */private$active;/** @ORM\Column(type="json") */private$parameters = [];// All Getters/Setters// Removed in this example for readability}

src/Repository/ProviderConfigurationRepository.php

<?phpnamespaceApp\Repository;useApp\Entity\ProviderConfiguration;useDoctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;useDoctrine\Common\Persistence\ManagerRegistry;useMacFJA\BookRetriever\ProviderConfigurationInterface;useMacFJA\BookRetriever\ProviderInterface;class ProviderConfigurationRepositoryextends ServiceEntityRepositoryimplements ProviderConfigurationInterface{publicfunction__construct(ManagerRegistry$registry)    {parent::__construct($registry, ProviderConfiguration::class);    }publicfunctiongetParameters(ProviderInterface$provider):array    {$configuration =$this->findOneBy(['provider' =>$provider->getCode()]);return$configuration !==null ?$configuration->getParameters() : [];    }publicfunctionisActive(ProviderInterface$provider):bool    {$configuration =$this->findOneBy(['provider' =>$provider->getCode()]);// not active by defaultreturn$configuration !==null ?$configuration->getActive() :false;    }}

src/Controller/SomeController.php

<?phpnamespaceApp\Controller;useMacFJA\BookRetriever\Pool;useSymfony\Bundle\FrameworkBundle\Controller\AbstractController;useSymfony\Component\HttpFoundation\JsonResponse;useSymfony\Component\Routing\Annotation\Route;class SomeControllerextends AbstractController{/** @Route("/test") */publicfunctionindex(Pool$pool)    {returnnewJsonResponse($pool->searchIsbn('9782253006329'));    }}

Providers

There are currently20 built-in providers.You can findmore details here.

Contributing

You can contribute to the library.To do so, you have Github issues to:

  • ask your question
  • notify any change in the providers
  • suggest new provider
  • request any change (typo, bad code, etc.)
  • and much more...

You also have PR to:

  • add a new provider
  • suggest a correction
  • and much more...

Local installation

First clone the project (either this repository, or your fork),next run:

make install# Install project vendormake all# Run QA tools + tests suites + generate docs

Validate your code

When you done writing your code run the following command check if the quality meet defined rule and to format it:

make analyze# Run QA tools + tests suites

If you add unit tests you run the following to do the same on test suite code:

make analyze-tests# Run QA tools on tests suites

License

The MIT License (MIT). Please seeLicense File for more information.


[8]ページ先頭

©2009-2025 Movatter.jp