|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of dispositif/wikibot application (@github) |
|
4
|
|
|
* 2019-2023 © Philippe M./Irønie <[email protected]> |
|
5
|
|
|
* For the full copyright and MIT license information, view the license file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace App\Domain; |
|
11
|
|
|
|
|
12
|
|
|
use App\Domain\Models\Wiki\OuvrageClean; |
|
13
|
|
|
use App\Domain\Models\Wiki\OuvrageTemplate; |
|
14
|
|
|
use App\Domain\WikiOptimizer\OptimizerFactory; |
|
15
|
|
|
use App\Infrastructure\BnfAdapter; |
|
16
|
|
|
use App\Infrastructure\GoogleBooksAdapter; |
|
17
|
|
|
use App\Infrastructure\OpenLibraryAdapter; |
|
18
|
|
|
use Psr\Log\LoggerInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* todo hexa inject di (or move factory ?) |
|
22
|
|
|
*/ |
|
23
|
|
|
class OuvrageFactory |
|
24
|
|
|
{ |
|
25
|
|
|
private function __construct() |
|
26
|
|
|
{ |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public static function OpenLibraryFromIsbn(string $isbn): ?OuvrageTemplate |
|
30
|
|
|
{ |
|
31
|
|
|
$import = new ImportOuvrageFromApi(new OuvrageClean(), new OpenLibraryAdapter()); |
|
32
|
|
|
$import->hydrateFromIsbn($isbn); |
|
33
|
|
|
$ouvrage = $import->getOuvrage(); |
|
34
|
|
|
$ouvrage->setDataSource('OL'); |
|
35
|
|
|
|
|
36
|
|
|
return $ouvrage; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function GoogleFromIsbn(string $isbn): OuvrageTemplate |
|
40
|
|
|
{ |
|
41
|
|
|
$import = new ImportOuvrageFromApi(new OuvrageClean(), new GoogleBooksAdapter()); |
|
42
|
|
|
$import->hydrateFromIsbn($isbn); |
|
43
|
|
|
$ouvrage = $import->getOuvrage(); |
|
44
|
|
|
$ouvrage->setDataSource('GB'); |
|
45
|
|
|
|
|
46
|
|
|
return $ouvrage; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public static function BnfFromIsbn(string $isbn): OuvrageTemplate |
|
50
|
|
|
{ |
|
51
|
|
|
$import = new ImportOuvrageFromApi(new OuvrageClean(), new BnfAdapter()); |
|
52
|
|
|
$import->hydrateFromIsbn($isbn); |
|
53
|
|
|
$ouvrage = $import->getOuvrage(); |
|
54
|
|
|
$ouvrage->setDataSource('BnF'); |
|
55
|
|
|
|
|
56
|
|
|
return $ouvrage; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public static function OptimizedFromData(array $data, LoggerInterface $logger = null): OuvrageTemplate |
|
60
|
|
|
{ |
|
61
|
|
|
$ouvrage = new OuvrageClean(); |
|
62
|
|
|
$ouvrage->hydrate($data); |
|
63
|
|
|
$proc = OptimizerFactory::fromTemplate($ouvrage, null, $logger); |
|
|
|
|
|
|
64
|
|
|
$proc->doTasks(); |
|
65
|
|
|
|
|
66
|
|
|
return $proc->getOptiTemplate(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|