|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Locale\Stub; |
|
|
13 |
|
|
|
14 |
/** |
|
|
15 |
* Provides fake static versions of the global functions in the intl extension |
|
|
16 |
* |
|
|
17 |
* @author Bernhard Schussek <bernhard.schussek@symfony.com> |
|
|
18 |
*/ |
|
|
19 |
abstract class StubIntl |
|
|
20 |
{ |
|
|
21 |
/** |
|
|
22 |
* Indicates that no error occurred |
|
|
23 |
* @var integer |
|
|
24 |
*/ |
|
|
25 |
const U_ZERO_ERROR = 0; |
|
|
26 |
|
|
|
27 |
/** |
|
|
28 |
* Indicates that an invalid argument was passed |
|
|
29 |
* @var integer |
|
|
30 |
*/ |
|
|
31 |
const U_ILLEGAL_ARGUMENT_ERROR = 1; |
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
* Indicates that the parse() operation failed |
|
|
35 |
* @var integer |
|
|
36 |
*/ |
|
|
37 |
const U_PARSE_ERROR = 9; |
|
|
38 |
|
|
|
39 |
/** |
|
|
40 |
* All known error codes |
|
|
41 |
* @var array |
|
|
42 |
*/ |
|
|
43 |
private static $errorCodes = array( |
|
|
44 |
self::U_ZERO_ERROR, |
|
|
45 |
self::U_ILLEGAL_ARGUMENT_ERROR, |
|
|
46 |
self::U_PARSE_ERROR, |
|
|
47 |
); |
|
|
48 |
|
|
|
49 |
/** |
|
|
50 |
* The error messages of all known error codes |
|
|
51 |
* @var array |
|
|
52 |
*/ |
|
|
53 |
private static $errorMessages = array( |
|
|
54 |
self::U_ZERO_ERROR => 'U_ZERO_ERROR', |
|
|
55 |
self::U_ILLEGAL_ARGUMENT_ERROR => 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR', |
|
|
56 |
self::U_PARSE_ERROR => 'Date parsing failed: U_PARSE_ERROR', |
|
|
57 |
); |
|
|
58 |
|
|
|
59 |
/** |
|
|
60 |
* The error code of the last operation |
|
|
61 |
* @var integer |
|
|
62 |
*/ |
|
|
63 |
private static $errorCode = self::U_ZERO_ERROR; |
|
|
64 |
|
|
|
65 |
/** |
|
|
66 |
* Returns whether the error code indicates a failure |
|
|
67 |
* |
|
|
68 |
* @param integer $errorCode The error code returned by StubIntl::getErrorCode() |
|
|
69 |
* @return Boolean |
|
|
70 |
*/ |
|
|
71 |
static public function isFailure($errorCode) { |
|
|
72 |
return in_array($errorCode, static::$errorCodes, true) |
|
|
73 |
&& $errorCode !== self::U_ZERO_ERROR; |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
/** |
|
|
77 |
* Returns the error code of the last operation |
|
|
78 |
* |
|
|
79 |
* Returns StubIntl::U_ZERO_ERROR if no error occurred. |
|
|
80 |
* |
|
|
81 |
* @return integer |
|
|
82 |
*/ |
|
|
83 |
static public function getErrorCode() { |
|
|
84 |
return static::$errorCode; |
|
|
85 |
} |
|
|
86 |
|
|
|
87 |
/** |
|
|
88 |
* Returns the error message of the last operation |
|
|
89 |
* |
|
|
90 |
* Returns "U_ZERO_ERROR" if no error occurred. |
|
|
91 |
* |
|
|
92 |
* @return string |
|
|
93 |
*/ |
|
|
94 |
static public function getErrorMessage() { |
|
|
95 |
return static::$errorMessages[static::$errorCode]; |
|
|
96 |
} |
|
|
97 |
|
|
|
98 |
/** |
|
|
99 |
* Sets the current error code |
|
|
100 |
* |
|
|
101 |
* @param integer $code One of the error constants in this class |
|
|
102 |
* @throws \InvalidArgumentException If the code is not one of the error |
|
|
103 |
* constants in this class |
|
|
104 |
*/ |
|
|
105 |
static public function setErrorCode($code) { |
|
|
106 |
if (!isset(static::$errorMessages[$code])) { |
|
|
107 |
throw new \InvalidArgumentException(sprintf('No such error code: "%s"', $code)); |
|
|
108 |
} |
|
|
109 |
|
|
|
110 |
static::$errorCode = $code; |
|
|
111 |
} |
|
|
112 |
} |