1 | <?php |
||
17 | class ErrorDetector |
||
18 | { |
||
19 | /** |
||
20 | * @param ResponseInterface $response |
||
21 | * @param string $path |
||
22 | * @param array $options |
||
23 | * |
||
24 | * @return string |
||
25 | */ |
||
26 | 7 | public function detect(ResponseInterface $response, $path, array $options = []) |
|
27 | { |
||
28 | 7 | if ($response->getStatusCode() == 404) { |
|
29 | 1 | throw NotFoundException::page(); |
|
30 | } |
||
31 | |||
32 | 6 | $content = $response->getBody()->getContents(); |
|
33 | |||
34 | 6 | if ($this->isBanned($content)) { |
|
35 | 2 | throw BannedException::banned(); |
|
36 | } |
||
37 | |||
38 | if ( |
||
39 | 4 | strpos($path, '/animation/animation.php') !== false && |
|
40 | 4 | ($id = $this->isAkiraSubstitution($content, $path, $options)) |
|
41 | 4 | ) { |
|
42 | 2 | throw NotFoundException::anime($id); |
|
43 | } |
||
44 | |||
45 | 2 | return $content; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param string $content |
||
50 | * |
||
51 | * @return bool |
||
52 | */ |
||
53 | 6 | private function isBanned($content) |
|
54 | { |
||
55 | return |
||
56 | 6 | strpos($content, 'url=http://www.world-art.ru/not_connect.html') !== false || |
|
57 | 5 | strpos($content, 'NETGEAR ProSecure') !== false |
|
58 | 6 | ; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Return anime Akira page if anime not found. |
||
63 | * |
||
64 | * @see http://www.world-art.ru/animation/animation.php?id=10000000 |
||
65 | * |
||
66 | * @param string $content |
||
67 | * @param string $path |
||
68 | * @param array $options |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | 4 | private function isAkiraSubstitution($content, $path, array $options) |
|
86 | |||
87 | /** |
||
88 | * Is not a Akira. |
||
89 | * |
||
90 | * @see http://www.world-art.ru/animation/animation.php?id=1 |
||
91 | * |
||
92 | * @param int $id |
||
93 | * @param string $content |
||
94 | * |
||
95 | * @return bool |
||
96 | */ |
||
97 | 4 | private function isNotAkira($id, $content) |
|
101 | } |
||
102 |