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 array $data |
||
86 | * @param array $options |
||
87 | * @return ElementFinder |
||
88 | * @throws \Exception |
||
89 | * @throws \InvalidArgumentException |
||
90 | */ |
||
91 | 2 | public function post($url, $data, array $options = []) { |
|
103 | |||
104 | |||
105 | /** |
||
106 | * @return \Xparse\ElementFinder\ElementFinder |
||
107 | */ |
||
108 | 2 | public function getLastPage() { |
|
111 | |||
112 | |||
113 | /** |
||
114 | * @param \Xparse\ElementFinder\ElementFinder $lastPage |
||
115 | * @return $this |
||
116 | */ |
||
117 | 4 | public function setLastPage($lastPage) { |
|
121 | |||
122 | |||
123 | /** |
||
124 | * @return null|ResponseInterface |
||
125 | */ |
||
126 | 1 | public function getLastResponse() { |
|
129 | |||
130 | |||
131 | /** |
||
132 | * @return ClientInterface |
||
133 | */ |
||
134 | 4 | public function getClient() { |
|
137 | |||
138 | |||
139 | /** |
||
140 | * @param $request |
||
141 | * @param array $options |
||
142 | * @return \Xparse\ElementFinder\ElementFinder |
||
143 | * @throws \Exception |
||
144 | */ |
||
145 | 4 | public function send(RequestInterface $request, array $options = []) { |
|
165 | |||
166 | |||
167 | /** |
||
168 | * @return ElementFinderFactoryInterface |
||
169 | */ |
||
170 | 1 | public function getElementFinderFactory() { |
|
173 | |||
174 | } |
||
175 |