Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
SourceSite | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
isSourceSiteFor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLinkPrefix | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
retrieveImportDetails | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getImportTitleChecker | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPostImportHandler | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace FileImporter\Services; |
4 | |
5 | use FileImporter\Data\ImportDetails; |
6 | use FileImporter\Data\SourceUrl; |
7 | use FileImporter\Interfaces\DetailRetriever; |
8 | use FileImporter\Interfaces\ImportTitleChecker; |
9 | use FileImporter\Interfaces\LinkPrefixLookup; |
10 | use FileImporter\Interfaces\PostImportHandler; |
11 | use FileImporter\Interfaces\SourceUrlChecker; |
12 | |
13 | /** |
14 | * A SourceSite object is composed of services which can import files from configurable URLs. The |
15 | * SourceUrlChecker provided via the constructor dictates which SourceUrls are going to be processed |
16 | * by this service. |
17 | * |
18 | * @license GPL-2.0-or-later |
19 | * @author Addshore |
20 | */ |
21 | class SourceSite { |
22 | |
23 | /** @var SourceUrlChecker */ |
24 | private $sourceUrlChecker; |
25 | /** @var DetailRetriever */ |
26 | private $detailRetriever; |
27 | /** @var ImportTitleChecker */ |
28 | private $importTitleChecker; |
29 | /** @var SourceUrlNormalizer */ |
30 | private $sourceUrlNormalizer; |
31 | /** @var LinkPrefixLookup */ |
32 | private $linkPrefixLookup; |
33 | /** @var PostImportHandler */ |
34 | private $postImportHandler; |
35 | |
36 | public function __construct( |
37 | SourceUrlChecker $sourceUrlChecker, |
38 | DetailRetriever $detailRetriever, |
39 | ImportTitleChecker $importTitleChecker, |
40 | SourceUrlNormalizer $sourceUrlNormalizer, |
41 | LinkPrefixLookup $linkPrefixLookup, |
42 | PostImportHandler $postImportHandler |
43 | ) { |
44 | $this->sourceUrlChecker = $sourceUrlChecker; |
45 | $this->detailRetriever = $detailRetriever; |
46 | $this->importTitleChecker = $importTitleChecker; |
47 | $this->sourceUrlNormalizer = $sourceUrlNormalizer; |
48 | $this->linkPrefixLookup = $linkPrefixLookup; |
49 | $this->postImportHandler = $postImportHandler; |
50 | } |
51 | |
52 | /** |
53 | * @return bool is this the source site for the given URL |
54 | */ |
55 | public function isSourceSiteFor( SourceUrl $sourceUrl ): bool { |
56 | $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl ); |
57 | return $this->sourceUrlChecker->checkSourceUrl( $sourceUrl ); |
58 | } |
59 | |
60 | public function getLinkPrefix( SourceUrl $sourceUrl ): string { |
61 | $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl ); |
62 | return $this->linkPrefixLookup->getPrefix( $sourceUrl ); |
63 | } |
64 | |
65 | public function retrieveImportDetails( SourceUrl $sourceUrl ): ImportDetails { |
66 | $sourceUrl = $this->sourceUrlNormalizer->normalize( $sourceUrl ); |
67 | return $this->detailRetriever->getImportDetails( $sourceUrl ); |
68 | } |
69 | |
70 | public function getImportTitleChecker(): ImportTitleChecker { |
71 | return $this->importTitleChecker; |
72 | } |
73 | |
74 | public function getPostImportHandler(): PostImportHandler { |
75 | return $this->postImportHandler; |
76 | } |
77 | |
78 | } |