1 | <?php |
||
9 | abstract class AbstractDriver implements Driver |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $url; |
||
15 | |||
16 | /** |
||
17 | * @var Client |
||
18 | */ |
||
19 | protected $client; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $category; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $board; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $thread; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $baseUrl; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $encoding; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $cookie; |
||
50 | |||
51 | /** |
||
52 | * AbstractDriver constructor. |
||
53 | * |
||
54 | * @param string $url |
||
55 | * @param Client $client |
||
56 | */ |
||
57 | public function __construct(string $url, Client $client) |
||
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | public function getCategory(): string |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | public function getBoard(): string |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getThread(): string |
||
87 | |||
88 | /** |
||
89 | * renew array. |
||
90 | * |
||
91 | * @param array $array |
||
92 | * |
||
93 | * @return array |
||
94 | */ |
||
95 | protected function renewArray(array $array): array |
||
99 | |||
100 | /** |
||
101 | * send request. |
||
102 | * |
||
103 | * @param string $method |
||
104 | * @param string $url |
||
105 | * @param array $options |
||
106 | * |
||
107 | * @return mixed|string |
||
108 | * @throws MonarException |
||
109 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
110 | */ |
||
111 | protected function request(string $method, string $url, array $options = []) |
||
128 | |||
129 | /** |
||
130 | * encode body text. |
||
131 | * |
||
132 | * @param string $body |
||
133 | * @param string $from |
||
134 | * @param string $to |
||
135 | * |
||
136 | * @return mixed|string |
||
137 | */ |
||
138 | protected function encode(string $body, string $from, string $to) |
||
142 | |||
143 | /** |
||
144 | * parse url. |
||
145 | * |
||
146 | * @return void |
||
147 | */ |
||
148 | abstract protected function parse(): void; |
||
149 | |||
150 | /** |
||
151 | * parse dat collection. |
||
152 | * |
||
153 | * @param string $body |
||
154 | * @param int|null $start |
||
155 | * @param int|null $end |
||
156 | * |
||
157 | * @return \Illuminate\Support\Collection |
||
158 | */ |
||
159 | abstract protected function parseDatCollection(string $body, ?int $start = null, ?int $end = null): Collection; |
||
160 | |||
161 | /** |
||
162 | * parse threads collection. |
||
163 | * |
||
164 | * @param string $body |
||
165 | * |
||
166 | * @return \Illuminate\Support\Collection |
||
167 | */ |
||
168 | abstract protected function parseThreadsCollection(string $body): Collection; |
||
169 | |||
170 | /** |
||
171 | * build message url. |
||
172 | * |
||
173 | * @param int $start |
||
174 | * @param int|null $end |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | abstract protected function messagesUrl(int $start = 1, ?int $end = null): string; |
||
179 | |||
180 | /** |
||
181 | * build thread url. |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | abstract protected function threadsUrl(): string; |
||
186 | |||
187 | /** |
||
188 | * build post url. |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | abstract protected function postUrl(): string; |
||
193 | } |
||
194 |