1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SteamMarketProviders\ParserManager\Parser; |
6
|
|
|
|
7
|
|
|
use PHPHtmlParser\Exceptions\ChildNotFoundException; |
8
|
|
|
use PHPHtmlParser\Exceptions\CircularException; |
9
|
|
|
use PHPHtmlParser\Exceptions\ContentLengthException; |
10
|
|
|
use PHPHtmlParser\Exceptions\LogicalException; |
11
|
|
|
use PHPHtmlParser\Exceptions\NotLoadedException; |
12
|
|
|
use PHPHtmlParser\Exceptions\StrictException; |
13
|
|
|
use SteamMarketProviders\ParserManager\Builder\ParseRulesBuilder; |
14
|
|
|
use SteamMarketProviders\ParserManager\Contract\UrlBuilderInterface; |
15
|
|
|
use SteamMarketProviders\ParserManager\Exception\HttpException; |
16
|
|
|
use SteamMarketProviders\ParserManager\Contract\StrategyInterface; |
17
|
|
|
|
18
|
|
|
final class SteamParser |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param AbstractProvider $abstractProvider |
22
|
|
|
*/ |
23
|
3 |
|
public function __construct(readonly private AbstractProvider $abstractProvider) |
24
|
|
|
{ |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param StrategyInterface $strategy |
29
|
|
|
* @return $this |
30
|
|
|
*/ |
31
|
|
|
public function setHttpStrategy(StrategyInterface $strategy): SteamParser |
32
|
|
|
{ |
33
|
|
|
$this->abstractProvider->setHttpStrategy($strategy); |
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param ParseRulesBuilder $parseRulesBuilder |
39
|
|
|
* @return $this |
40
|
|
|
*/ |
41
|
|
|
public function setParseRules(ParseRulesBuilder $parseRulesBuilder): SteamParser |
42
|
|
|
{ |
43
|
|
|
$this->abstractProvider->setParseRules($parseRulesBuilder); |
44
|
|
|
|
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setUrl(UrlBuilderInterface $urlBuilder): SteamParser |
49
|
|
|
{ |
50
|
|
|
$this->abstractProvider->setUrl($urlBuilder); |
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param int $page |
57
|
|
|
* @return array |
58
|
|
|
* @throws ChildNotFoundException |
59
|
|
|
* @throws CircularException |
60
|
|
|
* @throws ContentLengthException |
61
|
|
|
* @throws LogicalException |
62
|
|
|
* @throws NotLoadedException |
63
|
|
|
* @throws StrictException |
64
|
|
|
* @throws HttpException |
65
|
|
|
*/ |
66
|
2 |
|
public function run(int $page = 1): array |
67
|
|
|
{ |
68
|
2 |
|
return $this->abstractProvider->start($page); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|