1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpCfdi\SatCatalogosPopulate\Origins; |
6
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
8
|
|
|
use LogicException; |
9
|
|
|
|
10
|
|
|
class ScrapingOrigin implements OriginInterface |
11
|
|
|
{ |
12
|
|
|
/** @var string */ |
13
|
|
|
private $name; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
private $toScrapUrl; |
17
|
|
|
|
18
|
|
|
/** @var DateTimeImmutable|null */ |
19
|
|
|
private $lastVersion; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
private $destinationFilename; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $downloadUrl; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $linkText; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
string $name, |
34
|
|
|
string $toScrapUrl, |
35
|
|
|
string $destinationFilename, |
36
|
|
|
string $linkText, |
37
|
|
|
?DateTimeImmutable $lastVersion = null, |
38
|
|
|
string $downloadUrl = '' |
39
|
|
|
) { |
40
|
|
|
$this->name = $name; |
41
|
|
|
$this->toScrapUrl = $toScrapUrl; |
42
|
|
|
$this->lastVersion = $lastVersion; |
43
|
|
|
$this->destinationFilename = $destinationFilename; |
44
|
|
|
$this->downloadUrl = $downloadUrl; |
45
|
|
|
$this->linkText = $linkText; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function withLastModified(?DateTimeImmutable $lastModified): self |
49
|
|
|
{ |
50
|
|
|
$clone = clone $this; |
51
|
|
|
$clone->lastVersion = $lastModified; |
52
|
|
|
return $clone; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function withDownloadUrl(string $downloadUrl): self |
56
|
|
|
{ |
57
|
|
|
$clone = clone $this; |
58
|
|
|
$clone->downloadUrl = $downloadUrl; |
59
|
|
|
return $clone; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function name(): string |
63
|
|
|
{ |
64
|
|
|
return $this->name; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function url(): string |
68
|
|
|
{ |
69
|
|
|
return $this->toScrapUrl; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function lastVersion(): DateTimeImmutable |
73
|
|
|
{ |
74
|
|
|
if (! $this->lastVersion instanceof DateTimeImmutable) { |
75
|
|
|
throw new LogicException('There is no last version in the origin'); |
76
|
|
|
} |
77
|
|
|
return $this->lastVersion; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function hasLastVersion(): bool |
81
|
|
|
{ |
82
|
|
|
return $this->lastVersion instanceof DateTimeImmutable; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function destinationFilename(): string |
86
|
|
|
{ |
87
|
|
|
return $this->destinationFilename; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function downloadUrl(): string |
91
|
|
|
{ |
92
|
|
|
return $this->downloadUrl; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function hasDownloadUrl(): bool |
96
|
|
|
{ |
97
|
|
|
return ('' !== $this->downloadUrl); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function linkText(): string |
101
|
|
|
{ |
102
|
|
|
return $this->linkText; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|