Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Locale] Improved error reporting and added stubs for intl_is_failure…
…(), intl_get_error_code() and intl_get_error_message()
- Loading branch information
Showing
5 changed files
with
196 additions
and
9 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Symfony/Component/Locale/Resources/stubs/functions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Stub implementation for the intl_is_failure function of the intl extension | ||
* | ||
* @author Bernhard Schussek <bernhard.schussek@symfony.com> | ||
* @param integer $errorCode The error code returned by intl_get_error_code() | ||
* @return Boolean Whether the error code indicates an error | ||
* @see Symfony\Component\Locale\Stub\StubIntl::isFailure | ||
*/ | ||
function intl_is_failure($errorCode) { | ||
return \Symfony\Component\Locale\Stub\StubIntl::isFailure($errorCode); | ||
} | ||
|
||
/** | ||
* Stub implementation for the intl_get_error_code function of the intl extension | ||
* | ||
* @author Bernhard Schussek <bernhard.schussek@symfony.com> | ||
* @return Boolean The error code of the last intl function call or | ||
* StubIntl::U_ZERO_ERROR if no error occurred | ||
* @see Symfony\Component\Locale\Stub\StubIntl::getErrorCode | ||
*/ | ||
function intl_get_error_code() { | ||
return \Symfony\Component\Locale\Stub\StubIntl::getErrorCode(); | ||
} | ||
/** | ||
* Stub implementation for the intl_get_error_code function of the intl extension | ||
* | ||
* @author Bernhard Schussek <bernhard.schussek@symfony.com> | ||
* @return Boolean The error message of the last intl function call or | ||
* "U_ZERO_ERROR" if no error occurred | ||
* @see Symfony\Component\Locale\Stub\StubIntl::getErrorMessage | ||
*/ | ||
function intl_get_error_message() { | ||
return \Symfony\Component\Locale\Stub\StubIntl::getErrorMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Locale\Stub; | ||
|
||
/** | ||
* Provides fake static versions of the global functions in the intl extension | ||
* | ||
* @author Bernhard Schussek <bernhard.schussek@symfony.com> | ||
*/ | ||
abstract class StubIntl | ||
{ | ||
/** | ||
* Indicates that no error occurred | ||
* @var integer | ||
*/ | ||
const U_ZERO_ERROR = 0; | ||
|
||
/** | ||
* Indicates that an invalid argument was passed | ||
* @var integer | ||
*/ | ||
const U_ILLEGAL_ARGUMENT_ERROR = 1; | ||
|
||
/** | ||
* Indicates that the parse() operation failed | ||
* @var integer | ||
*/ | ||
const U_PARSE_ERROR = 9; | ||
|
||
/** | ||
* All known error codes | ||
* @var array | ||
*/ | ||
private static $errorCodes = array( | ||
self::U_ZERO_ERROR, | ||
self::U_ILLEGAL_ARGUMENT_ERROR, | ||
self::U_PARSE_ERROR, | ||
); | ||
|
||
/** | ||
* The error messages of all known error codes | ||
* @var array | ||
*/ | ||
private static $errorMessages = array( | ||
self::U_ZERO_ERROR => 'U_ZERO_ERROR', | ||
self::U_ILLEGAL_ARGUMENT_ERROR => 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR', | ||
This comment has been minimized.
Sorry, something went wrong. |
||
self::U_PARSE_ERROR => 'Date parsing failed: U_PARSE_ERROR', | ||
); | ||
|
||
/** | ||
* The error code of the last operation | ||
* @var integer | ||
*/ | ||
private static $errorCode = self::U_ZERO_ERROR; | ||
|
||
/** | ||
* Returns whether the error code indicates a failure | ||
* | ||
* @param integer $errorCode The error code returned by StubIntl::getErrorCode() | ||
* @return Boolean | ||
*/ | ||
public static function isFailure($errorCode) { | ||
return in_array($errorCode, static::$errorCodes, true) | ||
&& $errorCode !== self::U_ZERO_ERROR; | ||
} | ||
|
||
/** | ||
* Returns the error code of the last operation | ||
* | ||
* Returns StubIntl::U_ZERO_ERROR if no error occurred. | ||
* | ||
* @return integer | ||
*/ | ||
public static function getErrorCode() { | ||
return static::$errorCode; | ||
} | ||
|
||
/** | ||
* Returns the error message of the last operation | ||
* | ||
* Returns "U_ZERO_ERROR" if no error occurred. | ||
* | ||
* @return string | ||
*/ | ||
public static function getErrorMessage() { | ||
return static::$errorMessages[static::$errorCode]; | ||
} | ||
|
||
/** | ||
* Sets the current error code | ||
* | ||
* @param integer $code One of the error constants in this class | ||
* @throws \InvalidArgumentException If the code is not one of the error | ||
* constants in this class | ||
*/ | ||
public static function setErrorCode($code) { | ||
if (!isset(static::$errorMessages[$code])) { | ||
throw new \InvalidArgumentException(sprintf('No such error code: "%s"', $code)); | ||
} | ||
|
||
static::$errorCode = $code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this error message has changed on Nov, 11 2010: http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/intl/dateformat/dateformat_format.c?r1=265868&r2=305580
So now assertion will fail on recent Intl.