本文整理汇总了PHP中intl_is_failure函数的典型用法代码示例。如果您正苦于以下问题:PHP intl_is_failure函数的具体用法?PHP intl_is_failure怎么用?PHP intl_is_failure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了intl_is_failure函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: format
/**
* Currency format a number
*
* @throws Exception\RuntimeException
* @param float|string|int $number
* @return string
*/
public function format($number, ArrayObject $row = null)
{
$locale = $this->params['locale'];
//$formatterId = md5($locale);
$formatterId = $locale . (string) $this->params['pattern'];
if (!array_key_exists($formatterId, $this->formatters)) {
$this->loadFormatterId($formatterId);
}
if ($number !== null && !is_numeric($number)) {
$this->throwNumberFormatterException($this->formatters[$formatterId], $number);
}
if ($this->unit_column !== null) {
if (!isset($row[$this->unit_column])) {
throw new Exception\RuntimeException(__METHOD__ . " Cannot determine unit code based on column '{$this->unit_column}'.");
}
$value = $this->formatters[$formatterId]->format($number) . ' ' . $row[$this->unit_column];
} elseif ($this->params['unit'] != '') {
$value = $this->formatters[$formatterId]->format($number) . ' ' . $this->params['unit'];
} else {
throw new Exception\RuntimeException(__METHOD__ . " Unit code must be set prior to use the UnitFormatter");
}
if (intl_is_failure($this->formatters[$formatterId]->getErrorCode())) {
$this->throwNumberFormatterException($this->formatters[$formatterId], $number);
}
return $value;
}
开发者ID:robocoder,项目名称:solublecomponents,代码行数:33,代码来源:UnitFormatter.php
示例2: load
/**
*
* {@inheritdoc}
*
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!is_dir($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
try {
$rb = new \ResourceBundle($locale, $resource);
} catch (\Exception $e) {
// HHVM compatibility: constructor throws on invalid resource
$rb = null;
}
if (!$rb) {
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
} elseif (intl_is_failure($rb->getErrorCode())) {
throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
}
$messages = $this->flatten($rb);
$catalogue = new MessageCatalogue($locale);
$catalogue->add($messages, $domain);
if (class_exists('Symfony\\Component\\Config\\Resource\\DirectoryResource')) {
$catalogue->addResource(new DirectoryResource($resource));
}
return $catalogue;
}
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:32,代码来源:IcuResFileLoader.php
示例3: reverseTransform
/**
* Transforms a localized number into an integer or float
*
* @param string $value
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new \InvalidArgumentException(sprintf('Expected argument of type string, %s given', gettype($value)));
}
$formatter = $this->getNumberFormatter();
$value = $formatter->parse($value);
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
return $value;
}
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:17,代码来源:NumberToLocalizedStringTransformer.php
示例4: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
$rb = new \ResourceBundle($locale, $resource);
if (!$rb) {
throw new \RuntimeException("cannot load this resource : {$resource}");
} elseif (intl_is_failure($rb->getErrorCode())) {
throw new \RuntimeException($rb->getErrorMessage(), $rb->getErrorCode());
}
$messages = $this->flatten($rb);
$catalogue = new MessageCatalogue($locale);
$catalogue->add($messages, $domain);
$catalogue->addResource(new FileResource($resource . '.dat'));
return $catalogue;
}
开发者ID:unkerror,项目名称:Budabot,代码行数:17,代码来源:IcuDatFileLoader.php
示例5: reverseTransform
/**
* Transforms a localized number into an integer or float
*
* @param string $value
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
}
if ('' === $value) {
return null;
}
$formatter = $this->getNumberFormatter();
$value = $formatter->parse($value);
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
return $value;
}
开发者ID:noelg,项目名称:symfony-demo,代码行数:20,代码来源:NumberToLocalizedStringTransformer.php
示例6: validate
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value)) {
throw new UnexpectedTypeException($value, 'string');
}
$formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
$position = 0;
$formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
if (intl_is_failure($formatter->getErrorCode()) || $position < strlen($value)) {
/** @var Decimal $constraint */
$this->context->addViolation($constraint->message, ['{{ value }}' => $this->formatValue($value)]);
}
}
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:19,代码来源:DecimalValidator.php
示例7: reverseTransform
/**
* Transforms between a percentage value into a normalized format (integer or float).
*
* @param number $value Percentage value.
* @return number Normalized value.
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new \InvalidArgumentException(sprintf('Expected argument of type string, %s given', gettype($value)));
}
$formatter = $this->getNumberFormatter();
// replace normal spaces so that the formatter can read them
$value = $formatter->parse(str_replace(' ', ' ', $value));
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
if (self::FRACTIONAL == $this->getOption('type')) {
$value /= 100;
}
return $value;
}
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:22,代码来源:PercentToLocalizedStringTransformer.php
示例8: reverseTransform
/**
* {@inheritdoc}
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new TransformationFailedException('Expected a string.');
}
if ('' === $value) {
return;
}
if ('NaN' === $value) {
throw new TransformationFailedException('"NaN" is not a valid integer');
}
$formatter = $this->getNumberFormatter();
$value = $formatter->parse($value, PHP_INT_SIZE == 8 ? $formatter::TYPE_INT64 : $formatter::TYPE_INT32);
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
return $value;
}
开发者ID:mm999,项目名称:EduSoho,代码行数:21,代码来源:IntegerToLocalizedStringTransformer.php
示例9: reverseTransform
/**
* Transforms between a percentage value into a normalized format (integer or float).
*
* @param number $value Percentage value.
* @return number Normalized value.
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
}
if ('' === $value) {
return null;
}
$formatter = $this->getNumberFormatter();
// replace normal spaces so that the formatter can read them
$value = $formatter->parse(str_replace(' ', ' ', $value));
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
if (self::FRACTIONAL == $this->getOption('type')) {
$value /= 100;
}
return $value;
}
开发者ID:yproximite,项目名称:symfony-legacy-form,代码行数:25,代码来源:PercentToLocalizedStringTransformer.php
示例10: transform
/**
* @inheritdoc
*/
public function transform($value)
{
if (!is_string($value) && !is_numeric($value)) {
throw new TransformationFailedException(sprintf('Expected a string to transform, got "%s" instead.', json_encode($value)));
}
if ('' === $value) {
return null;
}
if ('NaN' === $value) {
throw new TransformationFailedException('"NaN" is not a valid number');
}
$position = 0;
$formatter = $this->getNumberFormatter();
$groupSep = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
$decSep = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
if ('.' !== $decSep && (!$this->grouping || '.' !== $groupSep)) {
$value = str_replace('.', $decSep, $value);
}
if (',' !== $decSep && (!$this->grouping || ',' !== $groupSep)) {
$value = str_replace(',', $decSep, $value);
}
$result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
if ($result >= PHP_INT_MAX || $result <= -PHP_INT_MAX) {
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
}
$encoding = mb_detect_encoding($value);
$length = mb_strlen($value, $encoding);
// After parsing, position holds the index of the character where the parsing stopped
if ($position < $length) {
// Check if there are unrecognized characters at the end of the
// number (excluding whitespace characters)
$remainder = trim(mb_substr($value, $position, $length, $encoding), " \t\n\r\v ");
if ('' !== $remainder) {
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s"', $remainder));
}
}
// Only the format() method in the NumberFormatter rounds, whereas parse() does not
return $this->round($result);
}
开发者ID:treehouselabs,项目名称:feeder,代码行数:45,代码来源:LocalizedStringToNumberTransformer.php
示例11: format
/**
* {@inheritdoc}
*/
public function format($value, array $options = array())
{
if (null === $value) {
return $options['null_value'];
}
if (!is_numeric($value)) {
throw FormatterException::invalidType($this, $value, 'numeric value');
}
$formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
if (null !== $options['precision']) {
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $options['precision']);
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $options['rounding_mode']);
}
$formatter->setAttribute(\NumberFormatter::GROUPING_USED, $options['grouping']);
$value = $formatter->format($value);
if (intl_is_failure($formatter->getErrorCode())) {
throw FormatterException::intlError($this, $formatter->getErrorMessage());
}
return $value;
}
开发者ID:jfsimon,项目名称:datagrid,代码行数:23,代码来源:NumberFormatter.php
示例12: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource . '.dat')) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource . '.dat')) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$rb = new \ResourceBundle($locale, $resource);
if (!$rb) {
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
} elseif (intl_is_failure($rb->getErrorCode())) {
throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
}
$messages = $this->flatten($rb);
$catalogue = new MessageCatalogue($locale);
$catalogue->add($messages, $domain);
$catalogue->addResource(new FileResource($resource . '.dat'));
return $catalogue;
}
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:23,代码来源:IcuDatFileLoader.php
示例13: format
/**
* {@inheritdoc}
*/
public function format($value, array $options = array())
{
if (null === $value) {
return $options['null_value'];
}
if (!$value instanceof \DateTime) {
throw FormatterException::invalidType($this, $value, 'DateTime instance');
}
$dateTime = clone $value;
if ('UTC' !== $options['time_zone']) {
$dateTime->setTimezone(new \DateTimeZone('UTC'));
}
$formatter = new \IntlDateFormatter(\Locale::getDefault(), $options['date_format'], $options['time_format'], $options['time_zone'], $options['calendar'], $options['pattern']);
$formatter->setLenient(false);
$value = $formatter->format((int) $dateTime->format('U'));
if (intl_is_failure(intl_get_error_code())) {
throw FormatterException::intlError($this, intl_get_error_message());
}
$value = preg_replace('~GMT\\+00:00$~', 'GMT', $value);
return $value;
}
开发者ID:jfsimon,项目名称:datagrid,代码行数:24,代码来源:DateTimeFormatter.php
示例14: validate
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value)) {
throw new UnexpectedTypeException($value, 'string');
}
$formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, \NumberFormatter::ROUND_DOWN);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 0);
$decimalSeparator = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
$position = 0;
$formatter->parse($value, PHP_INT_SIZE == 8 ? $formatter::TYPE_INT64 : $formatter::TYPE_INT32, $position);
if (intl_is_failure($formatter->getErrorCode()) || strpos($value, $decimalSeparator) !== false || $position < strlen($value)) {
/** @var Integer $constraint */
$this->context->addViolation($constraint->message, ['{{ value }}' => $this->formatValue($value)]);
}
}
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:24,代码来源:IntegerValidator.php
示例15: transform
/**
* Transforms a normalized format into a localized money string.
*
* @param MoneyValue $value Normalized number
*
* @throws TransformationFailedException If the given value is not numeric or
* if the value can not be transformed
*
* @return string Localized money string
*/
public function transform($value)
{
if (null === $value) {
return '';
}
if (!$value instanceof MoneyValue) {
throw new TransformationFailedException('Expected a MoneyValue object.');
}
if (!is_numeric($value->value)) {
throw new TransformationFailedException('Expected a numeric value.');
}
$amountValue = $value->value;
$amountValue /= $this->divisor;
$formatter = $this->getNumberFormatter();
$value = $formatter->formatCurrency($amountValue, $value->currency);
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
// Convert fixed spaces to normal ones
$value = str_replace(" ", ' ', $value);
return $value;
}
开发者ID:rollerworks,项目名称:search,代码行数:32,代码来源:MoneyToLocalizedStringTransformer.php
示例16: getDisplayedValue
public function getDisplayedValue($value)
{
if ($value !== null && $value !== '') {
$formatter = new \NumberFormatter($this->locale, $this->style);
if ($this->precision !== null) {
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision);
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode);
}
if ($this->ruleSet !== null) {
$formatter->setTextAttribute(\NumberFormatter::DEFAULT_RULESET, $this->ruleSet);
}
$formatter->setAttribute(\NumberFormatter::GROUPING_USED, $this->grouping);
if ($this->style === \NumberFormatter::PERCENT && !$this->fractional) {
$value /= 100;
}
if ($this->style === \NumberFormatter::CURRENCY) {
if ($this->currencyCode === null) {
$this->currencyCode = $formatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE);
}
if (strlen($this->currencyCode) !== 3) {
throw new TransformationFailedException('Your locale definition is not complete, you have to define a language and a country. (.e.g en_US, fr_FR)');
}
$value = $formatter->formatCurrency($value, $this->currencyCode);
} else {
$value = $formatter->format($value);
}
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
if (key_exists((string) $value, $this->values)) {
$value = $this->values[$value];
}
return $value;
}
return '';
}
开发者ID:radmar,项目名称:APYDataGridBundle,代码行数:36,代码来源:NumberColumn.php
示例17: testParseErrorIntl
/**
* @dataProvider parseErrorProvider
*/
public function testParseErrorIntl($pattern, $value)
{
$errorCode = StubIntl::U_PARSE_ERROR;
$errorMessage = 'Date parsing failed: U_PARSE_ERROR';
$this->skipIfIntlExtensionIsNotLoaded();
$formatter = $this->createIntlFormatter($pattern);
$this->assertFalse($formatter->parse($value));
$this->assertSame($errorMessage, intl_get_error_message());
$this->assertSame($errorCode, intl_get_error_code());
$this->assertTrue(intl_is_failure(intl_get_error_code()));
}
开发者ID:senthil-r-wiredelta,项目名称:meilleure-visite,代码行数:14,代码来源:StubIntlDateFormatterTest.php
示例18: reverseTransform
/**
* Transforms a localized number into an integer or float.
*
* @param string $value The localized value
*
* @return int|float The numeric value
*
* @throws TransformationFailedException If the given value is not a string
* or if the value can not be transformed.
*/
public function reverseTransform($value)
{
if (!is_string($value)) {
throw new TransformationFailedException('Expected a string.');
}
if ('' === $value) {
return;
}
if ('NaN' === $value) {
throw new TransformationFailedException('"NaN" is not a valid number');
}
$position = 0;
$formatter = $this->getNumberFormatter();
$groupSep = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
$decSep = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
if ('.' !== $decSep && (!$this->grouping || '.' !== $groupSep)) {
$value = str_replace('.', $decSep, $value);
}
if (',' !== $decSep && (!$this->grouping || ',' !== $groupSep)) {
$value = str_replace(',', $decSep, $value);
}
if (false !== strpos($value, $decSep)) {
$type = \NumberFormatter::TYPE_DOUBLE;
} else {
$type = PHP_INT_SIZE === 8 ? \NumberFormatter::TYPE_INT64 : \NumberFormatter::TYPE_INT32;
}
$result = $formatter->parse($value, $type, $position);
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
if ($result >= PHP_INT_MAX || $result <= -PHP_INT_MAX) {
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
}
if (false !== ($encoding = mb_detect_encoding($value, null, true))) {
$length = mb_strlen($value, $encoding);
$remainder = mb_substr($value, $position, $length, $encoding);
} else {
$length = strlen($value);
$remainder = substr($value, $position, $length);
}
// After parsing, position holds the index of the character where the
// parsing stopped
if ($position < $length) {
// Check if there are unrecognized characters at the end of the
// number (excluding whitespace characters)
$remainder = trim($remainder, " \t\n\r\v ");
if ('' !== $remainder) {
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s"', $remainder));
}
}
// NumberFormatter::parse() does not round
return $this->round($result);
}
开发者ID:IsfacCDI,项目名称:Ecommerce,代码行数:63,代码来源:NumberToLocalizedStringTransformer.php
示例19: testParseIntl
/**
* @dataProvider parseProvider
*/
public function testParseIntl($pattern, $value, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR')
{
$this->skipIfIntlExtensionIsNotLoaded();
$formatter = $this->createIntlFormatter($pattern);
$this->assertSame($expected, $formatter->parse($value));
$this->assertSame($errorMessage, intl_get_error_message());
$this->assertSame($errorCode, intl_get_error_code());
$this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code()));
}
开发者ID:RogerWebb,项目名称:symfony,代码行数:12,代码来源:StubIntlDateFormatterTest.php
示例20: isValid
/**
* Returns true if and only if $value is a valid integer
*
* @param string|int $value
* @return bool
* @throws Exception\InvalidArgumentException
*/
public function isValid($value)
{
if (!is_string($value) && !is_int($value) && !is_float($value)) {
$this->error(self::INVALID);
return false;
}
if (is_int($value)) {
return true;
}
$this->setValue($value);
$locale = $this->getLocale();
$format = new NumberFormatter($locale, NumberFormatter::DECIMAL);
if (intl_is_failure($format->getErrorCode())) {
throw new Exception\InvalidArgumentException("Invalid locale string given");
}
$parsedInt = $format->parse($value, NumberFormatter::TYPE_INT64);
if (intl_is_failure($format->getErrorCode())) {
$this->error(self::NOT_INT);
return false;
}
$decimalSep = $format->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
$groupingSep = $format->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
$valueFiltered = str_replace($groupingSep, '', $value);
$valueFiltered = str_replace($decimalSep, '.', $valueFiltered);
if (strval($parsedInt) !== $valueFiltered) {
$this->error(self::NOT_INT);
return false;
}
return true;
}
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:37,代码来源:Int.php
注:本文中的intl_is_failure函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论