|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: famoser |
|
5
|
|
|
* Date: 13/11/2016 |
|
6
|
|
|
* Time: 12:29 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Famoser\XKCDCache\Types; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* used to distinguish frontend errors |
|
14
|
|
|
* |
|
15
|
|
|
* @package Famoser\XKCDCache\Types |
|
16
|
|
|
*/ |
|
17
|
|
|
class ServerError |
|
18
|
|
|
{ |
|
19
|
|
|
const CONNECTION_FAILED = 10; |
|
20
|
|
|
const CACHE_INACCESSIBLE = 11; |
|
21
|
|
|
const CACHING_FAILED = 12; |
|
22
|
|
|
const METHOD_NOT_ALLOWED = 13; |
|
23
|
|
|
const NODE_NOT_FOUND = 14; |
|
24
|
|
|
const CACHE_EMPTY = 15; |
|
25
|
|
|
const ZIP_FAILED = 16; |
|
26
|
|
|
const ZIP_NOT_FOUND = 17; |
|
27
|
|
|
const XKCD_CONNECTION_FAILED = 18; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* convert to string |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $code |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
3 |
|
public static function toString($code) |
|
36
|
|
|
{ |
|
37
|
|
|
switch ($code) { |
|
38
|
3 |
|
case static::CONNECTION_FAILED: |
|
39
|
1 |
|
return "could not connect to the XKCD server"; |
|
40
|
3 |
|
case static::CACHE_INACCESSIBLE: |
|
41
|
1 |
|
return "could not access the cache"; |
|
42
|
3 |
|
case static::CACHING_FAILED: |
|
43
|
1 |
|
return "could not cache the comic"; |
|
44
|
3 |
|
case static::METHOD_NOT_ALLOWED: |
|
45
|
1 |
|
return "this method is now allowed"; |
|
46
|
3 |
|
case static::NODE_NOT_FOUND: |
|
47
|
2 |
|
return "end node not found"; |
|
48
|
2 |
|
case static::CACHE_EMPTY: |
|
49
|
2 |
|
return "the cache is empty"; |
|
50
|
1 |
|
case static::ZIP_FAILED: |
|
51
|
1 |
|
return "zip could not be created"; |
|
52
|
1 |
|
case static::ZIP_NOT_FOUND: |
|
53
|
1 |
|
return "zip not found"; |
|
54
|
1 |
|
case static::XKCD_CONNECTION_FAILED: |
|
55
|
1 |
|
return "the server is not accessible"; |
|
56
|
|
|
default: |
|
57
|
1 |
|
return 'unknown error occurred with code ' . $code; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |