1 | <?php |
||
20 | class Parser implements ParserInterface { |
||
21 | |||
22 | /** |
||
23 | * |
||
24 | * @var null|\Xparse\ElementFinder\ElementFinder |
||
25 | */ |
||
26 | protected $lastPage = null; |
||
27 | |||
28 | /** |
||
29 | * @var ClientInterface |
||
30 | */ |
||
31 | protected $client = null; |
||
32 | |||
33 | /** |
||
34 | * @var ElementFinderFactoryInterface |
||
35 | */ |
||
36 | protected $elementFinderFactory = null; |
||
37 | |||
38 | /** |
||
39 | * @var null|ResponseInterface |
||
40 | */ |
||
41 | protected $lastResponse = null; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * @param ClientInterface|null $client |
||
46 | * @param ElementFinderFactoryInterface|null $elementFinderFactory |
||
47 | */ |
||
48 | 9 | public function __construct(ClientInterface $client = null, ElementFinderFactoryInterface $elementFinderFactory = null) { |
|
49 | 9 | if ($client === null) { |
|
50 | 3 | $client = new Client([ |
|
51 | 3 | RequestOptions::ALLOW_REDIRECTS => true, |
|
52 | 3 | RequestOptions::COOKIES => new \GuzzleHttp\Cookie\CookieJar(), |
|
53 | 3 | ]); |
|
54 | 3 | } |
|
55 | |||
56 | 9 | if ($elementFinderFactory === null) { |
|
57 | 9 | $elementFinderFactory = new ElementFinderFactory(); |
|
58 | 9 | } |
|
59 | |||
60 | 9 | $this->elementFinderFactory = $elementFinderFactory; |
|
61 | |||
62 | 9 | $this->client = $client; |
|
63 | 9 | } |
|
64 | |||
65 | |||
66 | /** |
||
67 | * @param string $url |
||
68 | * @param array $options |
||
69 | * @return ElementFinder |
||
70 | * @throws \Exception |
||
71 | * @throws \InvalidArgumentException |
||
72 | */ |
||
73 | 4 | public function get($url, array $options = []) { |
|
81 | |||
82 | |||
83 | /** |
||
84 | * @param string $url |
||
85 | * @param string|resource|\Psr\Http\Message\StreamInterface $body Message body. |
||
86 | * @param array $options |
||
87 | * @return ElementFinder |
||
88 | * @throws \Exception |
||
89 | * @throws \InvalidArgumentException |
||
90 | */ |
||
91 | 2 | public function post($url, $body = null, array $options = []) { |
|
101 | |||
102 | |||
103 | /** |
||
104 | * @return \Xparse\ElementFinder\ElementFinder |
||
105 | */ |
||
106 | 2 | public function getLastPage() { |
|
109 | |||
110 | |||
111 | /** |
||
112 | * @param \Xparse\ElementFinder\ElementFinder $lastPage |
||
113 | * @return $this |
||
114 | */ |
||
115 | 4 | public function setLastPage($lastPage) { |
|
119 | |||
120 | |||
121 | /** |
||
122 | * @return null|ResponseInterface |
||
123 | */ |
||
124 | 1 | public function getLastResponse() { |
|
127 | |||
128 | |||
129 | /** |
||
130 | * @return ClientInterface |
||
131 | */ |
||
132 | 4 | public function getClient() { |
|
135 | |||
136 | |||
137 | /** |
||
138 | * @param $request |
||
139 | * @param array $options |
||
140 | * @return \Xparse\ElementFinder\ElementFinder |
||
141 | * @throws \Exception |
||
142 | */ |
||
143 | 4 | public function send(RequestInterface $request, array $options = []) { |
|
163 | |||
164 | |||
165 | /** |
||
166 | * @return ElementFinderFactoryInterface |
||
167 | */ |
||
168 | 1 | public function getElementFinderFactory() { |
|
171 | |||
172 | } |
||
173 |