1. Go to this page and download the library: Download macfja/book-retriever library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
macfja / book-retriever example snippets
$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
$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
$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
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/** @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
}
namespace App\Repository;
use App\Entity\ProviderConfiguration;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use MacFJA\BookRetriever\ProviderConfigurationInterface;
use MacFJA\BookRetriever\ProviderInterface;
class ProviderConfigurationRepository extends ServiceEntityRepository implements ProviderConfigurationInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ProviderConfiguration::class);
}
public function getParameters(ProviderInterface $provider): array
{
$configuration = $this->findOneBy(['provider' => $provider->getCode()]);
return $configuration !== null ? $configuration->getParameters() : [];
}
public function isActive(ProviderInterface $provider): bool
{
$configuration = $this->findOneBy(['provider' => $provider->getCode()]);
// not active by default
return $configuration !== null ? $configuration->getActive() : false;
}
}
namespace App\Controller;
use MacFJA\BookRetriever\Pool;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
class SomeController extends AbstractController
{
/** @Route("/test") */
public function index(Pool $pool)
{
return new JsonResponse($pool->searchIsbn('9782253006329'));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.