PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / system / error.php
vikappointments / site / helpers / libraries / system Last commit date
error.php 1 month ago factory.php 1 month ago index.html 1 month ago
error.php
189 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 if (!class_exists('UIErrorFactory'))
15 {
16 /**
17 * Factory Error class.
18 *
19 * @since 1.7
20 * @deprecated 1.8 Use VAPHttpDocument instead.
21 */
22 final class UIErrorFactory
23 {
24 /**
25 * Class constructor.
26 * @private This object cannot be instantiated.
27 */
28 private function __construct()
29 {
30 // never called
31 }
32
33 /**
34 * Class cloner.
35 * @private This object cannot be cloned.
36 */
37 private function __clone()
38 {
39 // never called
40 }
41
42 /**
43 * Raises an error by sending the header.
44 *
45 * @param integer $code The error code.
46 * @param string $error An optional error message.
47 *
48 * @return void
49 *
50 * @uses getErrorMessage()
51 *
52 * @deprecated 1.8 Use VAPHttpDocument::close() instead.
53 */
54 public static function raiseError($code, $error = null)
55 {
56 VAPHttpDocument::getInstance()->close($code, $error);
57 }
58
59 /**
60 * Throws an exception by using the passed data.
61 *
62 * @param mixed $error The error code or the error message
63 * or the exception to throw.
64 *
65 * @return void
66 *
67 * @uses getErrorMessage()
68 *
69 * @throws Exception
70 *
71 * @deprecated 1.8 Without replacement.
72 */
73 public static function throwException($error)
74 {
75 // if error is an integer
76 if (is_integer($error))
77 {
78 // create an exception with the error related to the specified code
79 $error = new Exception(static::getErrorMessage($error), $error);
80 }
81 // else if the error is not an exception
82 else if ($error instanceof Exception === false)
83 {
84 // create an exception with the specified string
85 $error = new Exception((string) $error);
86 }
87 // otherwise it means that the error is already an exception to throw
88
89 // throw the exception
90 throw $error;
91 }
92
93 /**
94 * Get the error message related to the specified code.
95 *
96 * @param integer $code The error code.
97 *
98 * @return string The error message.
99 *
100 * @deprecated 1.8 Without replacement.
101 */
102 public static function getErrorMessage($code)
103 {
104 $code = (string) $code;
105
106 return $code . isset(static::$lookup[$code]) ? ' ' . $code . ' ' . static::$lookup[$code] : '';
107 }
108
109 /**
110 * The lookup array to retrieve a message starting from the error code.
111 *
112 * @var array
113 */
114 private static $lookup = array(
115 '100' => 'Continue',
116 '101' => 'Switching Protocols',
117 '102' => 'Processing',
118
119 '200' => 'OK',
120 '201' => 'Created',
121 '202' => 'Accepted',
122 '203' => 'Non-Authoritative Information',
123 '204' => 'No Content',
124 '205' => 'Reset Content',
125 '206' => 'Partial Content',
126 '207' => 'Multi-Status',
127 '208' => 'Already Reported',
128 '226' => 'IM Used',
129
130 '300' => 'Multiple Choices',
131 '301' => 'Moved Permanently',
132 '302' => 'Found',
133 '303' => 'See Other',
134 '304' => 'Not Modified',
135 '305' => 'Use Proxy',
136 '306' => 'Switch Proxy',
137 '307' => 'Temporary Redirect',
138 '308' => 'Permanent Redirect',
139
140 '400' => 'Bad Request',
141 '401' => 'Unauthorized',
142 '402' => 'Payment Required',
143 '403' => 'Forbidden',
144 '404' => 'Not Found',
145 '405' => 'Method Not Allowed',
146 '406' => 'Not Acceptable',
147 '407' => 'Proxy Authentication Required',
148 '408' => 'Request Timeout',
149 '409' => 'Conflict',
150 '410' => 'Gone',
151 '411' => 'Length Required',
152 '412' => 'Precondition Failed',
153 '413' => 'Request Entity Too Large',
154 '414' => 'Request-URI Too Long',
155 '415' => 'Unsupported Media Type',
156 '416' => 'Requested Range Not Satisfiable',
157 '417' => 'Expectation Failed',
158 '418' => 'I\'m a teapot',
159 '420' => 'Enhance your calm',
160 '421' => 'Misdirected Request',
161 '422' => 'Unprocessable Entity',
162 '423' => 'Locked',
163 '424' => 'Failed Dependency',
164 '426' => 'Upgrade Required',
165 '428' => 'Precondition Required',
166 '429' => 'Too Many Requests',
167 '431' => 'Request Header Fields Too Large',
168 '444' => 'Connection Closed Without Response',
169 '449' => 'Retry With',
170 '451' => 'Unavailable For Legal Reasons',
171 '499' => 'Client Closed Request',
172
173 '500' => 'Internal Server Error',
174 '501' => 'Not Implemented',
175 '502' => 'Bad Gateway',
176 '503' => 'Service Unavailable',
177 '504' => 'Gateway Timeout',
178 '505' => 'HTTP Version Not Supported',
179 '506' => 'Variant Also Negotiates',
180 '507' => 'Insufficient Storage',
181 '508' => 'Loop Detected',
182 '509' => 'Bandwidth Limit Exceeded',
183 '510' => 'Not Extended',
184 '511' => 'Network Authentication Required',
185 '599' => 'Network Connect Timeout Error',
186 );
187 }
188 }
189