1 | <?php |
||
12 | class Application extends AbstractWebApplication |
||
13 | { |
||
14 | /** |
||
15 | * Response mime type. |
||
16 | * |
||
17 | * @var string |
||
18 | * @since 1.0 |
||
19 | */ |
||
20 | public $mimeType = 'application/json'; |
||
21 | |||
22 | /** |
||
23 | * Application router. |
||
24 | * |
||
25 | * @var Router |
||
26 | * @since 1.0 |
||
27 | */ |
||
28 | private $router; |
||
29 | |||
30 | /** |
||
31 | * Method to run the application routines. |
||
32 | * |
||
33 | * @return void |
||
34 | * |
||
35 | * @since 1.0 |
||
36 | */ |
||
37 | 5 | public function doExecute() |
|
61 | |||
62 | /** |
||
63 | * Set the HTTP Response Header for error conditions. |
||
64 | * |
||
65 | * @param \Exception $exception The Exception object to process. |
||
66 | * |
||
67 | * @return void |
||
68 | * |
||
69 | * @since 1.0 |
||
70 | */ |
||
71 | 4 | private function setErrorHeader(\Exception $exception) |
|
72 | { |
||
73 | 4 | switch ($exception->getCode()) |
|
74 | { |
||
75 | 4 | case 401: |
|
76 | 1 | $this->setHeader('HTTP/1.1 401 Unauthorized', 401, true); |
|
77 | |||
78 | 1 | break; |
|
79 | |||
80 | 3 | case 403: |
|
81 | 1 | $this->setHeader('HTTP/1.1 403 Forbidden', 403, true); |
|
82 | |||
83 | 1 | break; |
|
84 | |||
85 | 2 | case 404: |
|
86 | 1 | $this->setHeader('HTTP/1.1 404 Not Found', 404, true); |
|
87 | |||
88 | 1 | break; |
|
89 | |||
90 | 1 | case 500: |
|
91 | 1 | default: |
|
92 | 1 | $this->setHeader('HTTP/1.1 500 Internal Server Error', 500, true); |
|
93 | |||
94 | 1 | break; |
|
95 | 4 | } |
|
96 | 4 | } |
|
97 | |||
98 | /** |
||
99 | * Set the application's router. |
||
100 | * |
||
101 | * @param Router $router Router object to set. |
||
102 | * |
||
103 | * @return $this |
||
104 | * |
||
105 | * @since 1.0 |
||
106 | */ |
||
107 | 1 | public function setRouter(Router $router) |
|
113 | } |
||
114 |