4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\Globals
;
15 * Provides fake static versions of the global functions in the intl extension
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 abstract class IntlGlobals
22 * Indicates that no error occurred
26 const U_ZERO_ERROR
= 0;
29 * Indicates that an invalid argument was passed
33 const U_ILLEGAL_ARGUMENT_ERROR
= 1;
36 * Indicates that the parse() operation failed
40 const U_PARSE_ERROR
= 9;
43 * All known error codes
47 private static $errorCodes = array(
48 self
::U_ZERO_ERROR
=> 'U_ZERO_ERROR',
49 self
::U_ILLEGAL_ARGUMENT_ERROR
=> 'U_ILLEGAL_ARGUMENT_ERROR',
50 self
::U_PARSE_ERROR
=> 'U_PARSE_ERROR',
54 * The error code of the last operation
58 private static $errorCode = self
::U_ZERO_ERROR
;
61 * The error code of the last operation
65 private static $errorMessage = 'U_ZERO_ERROR';
68 * Returns whether the error code indicates a failure
70 * @param integer $errorCode The error code returned by IntlGlobals::getErrorCode()
74 public static function isFailure($errorCode)
76 return isset(self
::$errorCodes[$errorCode])
77 && $errorCode > self
::U_ZERO_ERROR
;
81 * Returns the error code of the last operation
83 * Returns IntlGlobals::U_ZERO_ERROR if no error occurred.
87 public static function getErrorCode()
89 return self
::$errorCode;
93 * Returns the error message of the last operation
95 * Returns "U_ZERO_ERROR" if no error occurred.
99 public static function getErrorMessage()
101 return self
::$errorMessage;
105 * Returns the symbolic name for a given error code
107 * @param integer $code The error code returned by IntlGlobals::getErrorCode()
111 public static function getErrorName($code)
113 if (isset(self
::$errorCodes[$code])) {
114 return self
::$errorCodes[$code];
117 return '[BOGUS UErrorCode]';
121 * Sets the current error
123 * @param integer $code One of the error constants in this class
124 * @param string $message The ICU class error message
126 * @throws \InvalidArgumentException If the code is not one of the error constants in this class
128 public static function setError($code, $message = '')
130 if (!isset(self
::$errorCodes[$code])) {
131 throw new \
InvalidArgumentException(sprintf('No such error code: "%s"', $code));
134 self
::$errorMessage = $message ? sprintf('%s: %s', $message, self
::$errorCodes[$code]) : self
::$errorCodes[$code];
135 self
::$errorCode = $code;