"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "framework/i18n/Formatter.php" between
yii2-2.0.36.tar.gz and yii2-2.0.37.tar.gz

About: Yii 2 is a high-performance component-based PHP framework for developing large-scale Web applications (source).

Formatter.php  (yii2-2.0.36):Formatter.php  (yii2-2.0.37)
skipping to change at line 612 skipping to change at line 612
return $this->nullDisplay; return $this->nullDisplay;
} }
return $value ? $this->booleanFormat[1] : $this->booleanFormat[0]; return $value ? $this->booleanFormat[1] : $this->booleanFormat[0];
} }
// date and time formats // date and time formats
/** /**
* Formats the value as a date. * Formats the value as a date.
* @param int|string|DateTime $value the value to be formatted. The followin g * @param int|string|DateTime|DateTimeInterface $value the value to be forma tted. The following
* types of value are supported: * types of value are supported:
* *
* - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition. * - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition.
* - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php). * - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given. * The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given.
* - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject. You may set the time zone * - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject. You may set the time zone
* for the DateTime object to specify the source time zone. * for the DateTime object to specify the source time zone.
* *
* The formatter will convert date values according to [[timeZone]] before f ormatting it. * The formatter will convert date values according to [[timeZone]] before f ormatting it.
* If no timezone conversion should be performed, you need to set [[defaultT imeZone]] and [[timeZone]] to the same value. * If no timezone conversion should be performed, you need to set [[defaultT imeZone]] and [[timeZone]] to the same value.
* Also no conversion will be performed on values that have no time informat ion, e.g. `"2017-06-05"`. * Also no conversion will be performed on values that have no time informat ion, e.g. `"2017-06-05"`.
* *
* @param string $format the format used to convert the value into a date st ring. * @param string|null $format the format used to convert the value into a da te string.
* If null, [[dateFormat]] will be used. * If null, [[dateFormat]] will be used.
* *
* This can be "short", "medium", "long", or "full", which represents a pres et format of different lengths. * This can be "short", "medium", "long", or "full", which represents a pres et format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://us erguide.icu-project.org/formatparse/datetime). * It can also be a custom format as specified in the [ICU manual](http://us erguide.icu-project.org/formatparse/datetime).
* *
* Alternatively this can be a string prefixed with `php:` representing a fo rmat that can be recognized by the * Alternatively this can be a string prefixed with `php:` representing a fo rmat that can be recognized by the
* PHP [date()](https://secure.php.net/manual/en/function.date.php)-function . * PHP [date()](https://secure.php.net/manual/en/function.date.php)-function .
* *
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value can not be evaluated as a date value. * @throws InvalidArgumentException if the input value can not be evaluated as a date value.
skipping to change at line 650 skipping to change at line 650
{ {
if ($format === null) { if ($format === null) {
$format = $this->dateFormat; $format = $this->dateFormat;
} }
return $this->formatDateTimeValue($value, $format, 'date'); return $this->formatDateTimeValue($value, $format, 'date');
} }
/** /**
* Formats the value as a time. * Formats the value as a time.
* @param int|string|DateTime $value the value to be formatted. The followin g * @param int|string|DateTime|DateTimeInterface $value the value to be forma tted. The following
* types of value are supported: * types of value are supported:
* *
* - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition. * - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition.
* - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php). * - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given. * The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given.
* - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject. You may set the time zone * - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject. You may set the time zone
* for the DateTime object to specify the source time zone. * for the DateTime object to specify the source time zone.
* *
* The formatter will convert date values according to [[timeZone]] before f ormatting it. * The formatter will convert date values according to [[timeZone]] before f ormatting it.
* If no timezone conversion should be performed, you need to set [[defaultT imeZone]] and [[timeZone]] to the same value. * If no timezone conversion should be performed, you need to set [[defaultT imeZone]] and [[timeZone]] to the same value.
* *
* @param string $format the format used to convert the value into a date st ring. * @param string|null $format the format used to convert the value into a da te string.
* If null, [[timeFormat]] will be used. * If null, [[timeFormat]] will be used.
* *
* This can be "short", "medium", "long", or "full", which represents a pres et format of different lengths. * This can be "short", "medium", "long", or "full", which represents a pres et format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://us erguide.icu-project.org/formatparse/datetime). * It can also be a custom format as specified in the [ICU manual](http://us erguide.icu-project.org/formatparse/datetime).
* *
* Alternatively this can be a string prefixed with `php:` representing a fo rmat that can be recognized by the * Alternatively this can be a string prefixed with `php:` representing a fo rmat that can be recognized by the
* PHP [date()](https://secure.php.net/manual/en/function.date.php)-function . * PHP [date()](https://secure.php.net/manual/en/function.date.php)-function .
* *
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value can not be evaluated as a date value. * @throws InvalidArgumentException if the input value can not be evaluated as a date value.
skipping to change at line 687 skipping to change at line 687
{ {
if ($format === null) { if ($format === null) {
$format = $this->timeFormat; $format = $this->timeFormat;
} }
return $this->formatDateTimeValue($value, $format, 'time'); return $this->formatDateTimeValue($value, $format, 'time');
} }
/** /**
* Formats the value as a datetime. * Formats the value as a datetime.
* @param int|string|DateTime $value the value to be formatted. The followin g * @param int|string|DateTime|DateTimeInterface $value the value to be forma tted. The following
* types of value are supported: * types of value are supported:
* *
* - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition. * - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition.
* - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php). * - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given. * The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given.
* - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject. You may set the time zone * - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject. You may set the time zone
* for the DateTime object to specify the source time zone. * for the DateTime object to specify the source time zone.
* *
* The formatter will convert date values according to [[timeZone]] before f ormatting it. * The formatter will convert date values according to [[timeZone]] before f ormatting it.
* If no timezone conversion should be performed, you need to set [[defaultT imeZone]] and [[timeZone]] to the same value. * If no timezone conversion should be performed, you need to set [[defaultT imeZone]] and [[timeZone]] to the same value.
* *
* @param string $format the format used to convert the value into a date st ring. * @param string|null $format the format used to convert the value into a da te string.
* If null, [[datetimeFormat]] will be used. * If null, [[datetimeFormat]] will be used.
* *
* This can be "short", "medium", "long", or "full", which represents a pres et format of different lengths. * This can be "short", "medium", "long", or "full", which represents a pres et format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://us erguide.icu-project.org/formatparse/datetime). * It can also be a custom format as specified in the [ICU manual](http://us erguide.icu-project.org/formatparse/datetime).
* *
* Alternatively this can be a string prefixed with `php:` representing a fo rmat that can be recognized by the * Alternatively this can be a string prefixed with `php:` representing a fo rmat that can be recognized by the
* PHP [date()](https://secure.php.net/manual/en/function.date.php)-function . * PHP [date()](https://secure.php.net/manual/en/function.date.php)-function .
* *
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value can not be evaluated as a date value. * @throws InvalidArgumentException if the input value can not be evaluated as a date value.
skipping to change at line 733 skipping to change at line 733
* @var array map of short format names to IntlDateFormatter constant values . * @var array map of short format names to IntlDateFormatter constant values .
*/ */
private $_dateFormats = [ private $_dateFormats = [
'short' => 3, // IntlDateFormatter::SHORT, 'short' => 3, // IntlDateFormatter::SHORT,
'medium' => 2, // IntlDateFormatter::MEDIUM, 'medium' => 2, // IntlDateFormatter::MEDIUM,
'long' => 1, // IntlDateFormatter::LONG, 'long' => 1, // IntlDateFormatter::LONG,
'full' => 0, // IntlDateFormatter::FULL, 'full' => 0, // IntlDateFormatter::FULL,
]; ];
/** /**
* @param int|string|DateTime $value the value to be formatted. The followin g * @param int|string|DateTime|DateTimeInterface $value the value to be forma tted. The following
* types of value are supported: * types of value are supported:
* *
* - an integer representing a UNIX timestamp * - an integer representing a UNIX timestamp
* - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php). * - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given. * The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given.
* - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject * - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject
* *
* @param string $format the format used to convert the value into a date st ring. * @param string $format the format used to convert the value into a date st ring.
* @param string $type 'date', 'time', or 'datetime'. * @param string $type 'date', 'time', or 'datetime'.
* @throws InvalidConfigException if the date format is invalid. * @throws InvalidConfigException if the date format is invalid.
skipping to change at line 809 skipping to change at line 809
$timestamp->setTimezone(new DateTimeZone($timeZone)); $timestamp->setTimezone(new DateTimeZone($timeZone));
} }
} }
return $timestamp->format($format); return $timestamp->format($format);
} }
/** /**
* Normalizes the given datetime value as a DateTime object that can be take n by various date/time formatting methods. * Normalizes the given datetime value as a DateTime object that can be take n by various date/time formatting methods.
* *
* @param int|string|DateTime $value the datetime value to be normalized. Th e following * @param int|string|DateTime|DateTimeInterface $value the datetime value to be normalized. The following
* types of value are supported: * types of value are supported:
* *
* - an integer representing a UNIX timestamp * - an integer representing a UNIX timestamp
* - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php). * - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given. * The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given.
* - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject * - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject
* *
* @param bool $checkDateTimeInfo whether to also check if the date/time val ue has some time and date information attached. * @param bool $checkDateTimeInfo whether to also check if the date/time val ue has some time and date information attached.
* Defaults to `false`. If `true`, the method will then return an array with the first element being the normalized * Defaults to `false`. If `true`, the method will then return an array with the first element being the normalized
* timestamp, the second a boolean indicating whether the timestamp has time information and third a boolean indicating * timestamp, the second a boolean indicating whether the timestamp has time information and third a boolean indicating
skipping to change at line 869 skipping to change at line 869
return new DateTime($value, new DateTimeZone($this->defaultTimeZone) ); return new DateTime($value, new DateTimeZone($this->defaultTimeZone) );
} catch (\Exception $e) { } catch (\Exception $e) {
throw new InvalidArgumentException("'$value' is not a valid date tim e value: " . $e->getMessage() throw new InvalidArgumentException("'$value' is not a valid date tim e value: " . $e->getMessage()
. "\n" . print_r(DateTime::getLastErrors(), true), $e->getCode() , $e); . "\n" . print_r(DateTime::getLastErrors(), true), $e->getCode() , $e);
} }
} }
/** /**
* Formats a date, time or datetime in a float number as UNIX timestamp (sec onds since 01-01-1970). * Formats a date, time or datetime in a float number as UNIX timestamp (sec onds since 01-01-1970).
* @param int|string|DateTime $value the value to be formatted. The followin g * @param int|string|DateTime|DateTimeInterface $value the value to be forma tted. The following
* types of value are supported: * types of value are supported:
* *
* - an integer representing a UNIX timestamp * - an integer representing a UNIX timestamp
* - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php). * - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given. * The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given.
* - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject * - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject
* *
* @return string the formatted result. * @return string the formatted result.
*/ */
public function asTimestamp($value) public function asTimestamp($value)
skipping to change at line 897 skipping to change at line 897
/** /**
* Formats the value as the time interval between a date and now in human re adable form. * Formats the value as the time interval between a date and now in human re adable form.
* *
* This method can be used in three different ways: * This method can be used in three different ways:
* *
* 1. Using a timestamp that is relative to `now`. * 1. Using a timestamp that is relative to `now`.
* 2. Using a timestamp that is relative to the `$referenceTime`. * 2. Using a timestamp that is relative to the `$referenceTime`.
* 3. Using a `DateInterval` object. * 3. Using a `DateInterval` object.
* *
* @param int|string|DateTime|DateInterval $value the value to be formatted. The following * @param int|string|DateTime|DateTimeInterface|DateInterval $value the valu e to be formatted. The following
* types of value are supported: * types of value are supported:
* *
* - an integer representing a UNIX timestamp * - an integer representing a UNIX timestamp
* - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php). * - a string that can be [parsed to create a DateTime object](https://secur e.php.net/manual/en/datetime.formats.php).
* The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given. * The timestamp is assumed to be in [[defaultTimeZone]] unless a time zon e is explicitly given.
* - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject * - a PHP [DateTime](https://secure.php.net/manual/en/class.datetime.php) o bject
* - a PHP DateInterval object (a positive time interval will refer to the p ast, a negative one to the future) * - a PHP DateInterval object (a positive time interval will refer to the p ast, a negative one to the future)
* *
* @param int|string|DateTime $referenceTime if specified the value is used as a reference time instead of `now` * @param int|string|DateTime|DateTimeInterface|null $referenceTime if speci fied the value is used as a reference time instead of `now`
* when `$value` is not a `DateInterval` object. * when `$value` is not a `DateInterval` object.
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value can not be evaluated as a date value. * @throws InvalidArgumentException if the input value can not be evaluated as a date value.
*/ */
public function asRelativeTime($value, $referenceTime = null) public function asRelativeTime($value, $referenceTime = null)
{ {
if ($value === null) { if ($value === null) {
return $this->nullDisplay; return $this->nullDisplay;
} }
skipping to change at line 1110 skipping to change at line 1110
* Formats the value as a decimal number. * Formats the value as a decimal number.
* *
* Property [[decimalSeparator]] will be used to represent the decimal point . The * Property [[decimalSeparator]] will be used to represent the decimal point . The
* value is rounded automatically to the defined decimal digits. * value is rounded automatically to the defined decimal digits.
* *
* Since 2.0.16 numbers that are mispresented after normalization are format ted as strings using fallback function * Since 2.0.16 numbers that are mispresented after normalization are format ted as strings using fallback function
* without [PHP intl extension](https://secure.php.net/manual/en/book.intl.p hp) support. For very big numbers it's * without [PHP intl extension](https://secure.php.net/manual/en/book.intl.p hp) support. For very big numbers it's
* recommended to pass them as strings and not use scientific notation other wise the output might be wrong. * recommended to pass them as strings and not use scientific notation other wise the output might be wrong.
* *
* @param mixed $value the value to be formatted. * @param mixed $value the value to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* If not given, the number of digits depends in the input value and is dete rmined based on * If not given, the number of digits depends in the input value and is dete rmined based on
* `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION _DIGITS`, which can be configured * `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION _DIGITS`, which can be configured
* using [[$numberFormatterOptions]]. * using [[$numberFormatterOptions]].
* If the PHP intl extension is not available, the default value is `2`. * If the PHP intl extension is not available, the default value is `2`.
* If you want consistent behavior between environments where intl is availa ble and not, you should explicitly * If you want consistent behavior between environments where intl is availa ble and not, you should explicitly
* specify a value here. * specify a value here.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
skipping to change at line 1160 skipping to change at line 1160
} }
/** /**
* Formats the value as a percent number with "%" sign. * Formats the value as a percent number with "%" sign.
* *
* Since 2.0.16 numbers that are mispresented after normalization are format ted as strings using fallback function * Since 2.0.16 numbers that are mispresented after normalization are format ted as strings using fallback function
* without [PHP intl extension](https://secure.php.net/manual/en/book.intl.p hp) support. For very big numbers it's * without [PHP intl extension](https://secure.php.net/manual/en/book.intl.p hp) support. For very big numbers it's
* recommended to pass them as strings and not use scientific notation other wise the output might be wrong. * recommended to pass them as strings and not use scientific notation other wise the output might be wrong.
* *
* @param mixed $value the value to be formatted. It must be a factor e.g. ` 0.75` will result in `75%`. * @param mixed $value the value to be formatted. It must be a factor e.g. ` 0.75` will result in `75%`.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* If not given, the number of digits depends in the input value and is dete rmined based on * If not given, the number of digits depends in the input value and is dete rmined based on
* `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION _DIGITS`, which can be configured * `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION _DIGITS`, which can be configured
* using [[$numberFormatterOptions]]. * using [[$numberFormatterOptions]].
* If the PHP intl extension is not available, the default value is `0`. * If the PHP intl extension is not available, the default value is `0`.
* If you want consistent behavior between environments where intl is availa ble and not, you should explicitly * If you want consistent behavior between environments where intl is availa ble and not, you should explicitly
* specify a value here. * specify a value here.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
skipping to change at line 1205 skipping to change at line 1205
} }
$normalizedValue *= 100; $normalizedValue *= 100;
return number_format($normalizedValue, $decimals, $this->decimalSeparato r, $this->thousandSeparator) . '%'; return number_format($normalizedValue, $decimals, $this->decimalSeparato r, $this->thousandSeparator) . '%';
} }
/** /**
* Formats the value as a scientific number. * Formats the value as a scientific number.
* *
* @param mixed $value the value to be formatted. * @param mixed $value the value to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* If not given, the number of digits depends in the input value and is dete rmined based on * If not given, the number of digits depends in the input value and is dete rmined based on
* `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION _DIGITS`, which can be configured * `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION _DIGITS`, which can be configured
* using [[$numberFormatterOptions]]. * using [[$numberFormatterOptions]].
* If the [PHP intl extension](https://secure.php.net/manual/en/book.intl.ph p) is not available, the default value depends on your PHP configuration. * If the [PHP intl extension](https://secure.php.net/manual/en/book.intl.ph p) is not available, the default value depends on your PHP configuration.
* If you want consistent behavior between environments where intl is availa ble and not, you should explicitly * If you want consistent behavior between environments where intl is availa ble and not, you should explicitly
* specify a value here. * specify a value here.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
skipping to change at line 1251 skipping to change at line 1251
* Formats the value as a currency number. * Formats the value as a currency number.
* *
* This function does not require the [PHP intl extension](https://secure.ph p.net/manual/en/book.intl.php) to be installed * This function does not require the [PHP intl extension](https://secure.ph p.net/manual/en/book.intl.php) to be installed
* to work, but it is highly recommended to install it to get good formattin g results. * to work, but it is highly recommended to install it to get good formattin g results.
* *
* Since 2.0.16 numbers that are mispresented after normalization are format ted as strings using fallback function * Since 2.0.16 numbers that are mispresented after normalization are format ted as strings using fallback function
* without PHP intl extension support. For very big numbers it's recommended to pass them as strings and not use * without PHP intl extension support. For very big numbers it's recommended to pass them as strings and not use
* scientific notation otherwise the output might be wrong. * scientific notation otherwise the output might be wrong.
* *
* @param mixed $value the value to be formatted. * @param mixed $value the value to be formatted.
* @param string $currency the 3-letter ISO 4217 currency code indicating th e currency to use. * @param string|null $currency the 3-letter ISO 4217 currency code indicati ng the currency to use.
* If null, [[currencyCode]] will be used. * If null, [[currencyCode]] will be used.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException if no currency is given and [[currencyCode ]] is not defined. * @throws InvalidConfigException if no currency is given and [[currencyCode ]] is not defined.
*/ */
public function asCurrency($value, $currency = null, $options = [], $textOpt ions = []) public function asCurrency($value, $currency = null, $options = [], $textOpt ions = [])
{ {
if ($value === null) { if ($value === null) {
skipping to change at line 1370 skipping to change at line 1370
/** /**
* Formats the value in bytes as a size in human readable form for example ` 12 kB`. * Formats the value in bytes as a size in human readable form for example ` 12 kB`.
* *
* This is the short form of [[asSize]]. * This is the short form of [[asSize]].
* *
* If [[sizeFormatBase]] is 1024, [binary prefixes](http://en.wikipedia.org/ wiki/Binary_prefix) (e.g. kibibyte/KiB, mebibyte/MiB, ...) * If [[sizeFormatBase]] is 1024, [binary prefixes](http://en.wikipedia.org/ wiki/Binary_prefix) (e.g. kibibyte/KiB, mebibyte/MiB, ...)
* are used in the formatting result. * are used in the formatting result.
* *
* @param string|int|float $value value in bytes to be formatted. * @param string|int|float $value value in bytes to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @see sizeFormatBase * @see sizeFormatBase
* @see asSize * @see asSize
*/ */
public function asShortSize($value, $decimals = null, $options = [], $textOp tions = []) public function asShortSize($value, $decimals = null, $options = [], $textOp tions = [])
{ {
if ($value === null) { if ($value === null) {
skipping to change at line 1426 skipping to change at line 1426
} }
} }
/** /**
* Formats the value in bytes as a size in human readable form, for example `12 kilobytes`. * Formats the value in bytes as a size in human readable form, for example `12 kilobytes`.
* *
* If [[sizeFormatBase]] is 1024, [binary prefixes](http://en.wikipedia.org/ wiki/Binary_prefix) (e.g. kibibyte/KiB, mebibyte/MiB, ...) * If [[sizeFormatBase]] is 1024, [binary prefixes](http://en.wikipedia.org/ wiki/Binary_prefix) (e.g. kibibyte/KiB, mebibyte/MiB, ...)
* are used in the formatting result. * are used in the formatting result.
* *
* @param string|int|float $value value in bytes to be formatted. * @param string|int|float $value value in bytes to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @see sizeFormatBase * @see sizeFormatBase
* @see asShortSize * @see asShortSize
*/ */
public function asSize($value, $decimals = null, $options = [], $textOptions = []) public function asSize($value, $decimals = null, $options = [], $textOptions = [])
{ {
if ($value === null) { if ($value === null) {
skipping to change at line 1481 skipping to change at line 1481
} }
} }
} }
/** /**
* Formats the value as a length in human readable form for example `12 mete rs`. * Formats the value as a length in human readable form for example `12 mete rs`.
* Check properties [[baseUnits]] if you need to change unit of value as the multiplier * Check properties [[baseUnits]] if you need to change unit of value as the multiplier
* of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. * of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]].
* *
* @param float|int $value value to be formatted. * @param float|int $value value to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* @param array $numberOptions optional configuration for the number formatt er. This parameter will be merged with [[numberFormatterOptions]]. * @param array $numberOptions optional configuration for the number formatt er. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not con tain required information. * @throws InvalidConfigException when INTL is not installed or does not con tain required information.
* @see asLength * @see asLength
* @since 2.0.13 * @since 2.0.13
* @author John Was <janek.jan@gmail.com> * @author John Was <janek.jan@gmail.com>
*/ */
public function asLength($value, $decimals = null, $numberOptions = [], $tex tOptions = []) public function asLength($value, $decimals = null, $numberOptions = [], $tex tOptions = [])
skipping to change at line 1504 skipping to change at line 1504
} }
/** /**
* Formats the value as a length in human readable form for example `12 m`. * Formats the value as a length in human readable form for example `12 m`.
* This is the short form of [[asLength]]. * This is the short form of [[asLength]].
* *
* Check properties [[baseUnits]] if you need to change unit of value as the multiplier * Check properties [[baseUnits]] if you need to change unit of value as the multiplier
* of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. * of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]].
* *
* @param float|int $value value to be formatted. * @param float|int $value value to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not con tain required information. * @throws InvalidConfigException when INTL is not installed or does not con tain required information.
* @see asLength * @see asLength
* @since 2.0.13 * @since 2.0.13
* @author John Was <janek.jan@gmail.com> * @author John Was <janek.jan@gmail.com>
*/ */
public function asShortLength($value, $decimals = null, $options = [], $text Options = []) public function asShortLength($value, $decimals = null, $options = [], $text Options = [])
{ {
return $this->formatUnit(self::UNIT_LENGTH, self::FORMAT_WIDTH_SHORT, $v alue, null, null, $decimals, $options, $textOptions); return $this->formatUnit(self::UNIT_LENGTH, self::FORMAT_WIDTH_SHORT, $v alue, null, null, $decimals, $options, $textOptions);
} }
/** /**
* Formats the value as a weight in human readable form for example `12 kilo grams`. * Formats the value as a weight in human readable form for example `12 kilo grams`.
* Check properties [[baseUnits]] if you need to change unit of value as the multiplier * Check properties [[baseUnits]] if you need to change unit of value as the multiplier
* of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. * of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]].
* *
* @param float|int $value value to be formatted. * @param float|int $value value to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not con tain required information. * @throws InvalidConfigException when INTL is not installed or does not con tain required information.
* @since 2.0.13 * @since 2.0.13
* @author John Was <janek.jan@gmail.com> * @author John Was <janek.jan@gmail.com>
*/ */
public function asWeight($value, $decimals = null, $options = [], $textOptio ns = []) public function asWeight($value, $decimals = null, $options = [], $textOptio ns = [])
{ {
skipping to change at line 1547 skipping to change at line 1547
} }
/** /**
* Formats the value as a weight in human readable form for example `12 kg`. * Formats the value as a weight in human readable form for example `12 kg`.
* This is the short form of [[asWeight]]. * This is the short form of [[asWeight]].
* *
* Check properties [[baseUnits]] if you need to change unit of value as the multiplier * Check properties [[baseUnits]] if you need to change unit of value as the multiplier
* of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. * of the smallest unit and [[systemOfUnits]] to switch between [[UNIT_SYSTE M_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]].
* *
* @param float|int $value value to be formatted. * @param float|int $value value to be formatted.
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed. * @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not con tain required information. * @throws InvalidConfigException when INTL is not installed or does not con tain required information.
* @since 2.0.13 * @since 2.0.13
* @author John Was <janek.jan@gmail.com> * @author John Was <janek.jan@gmail.com>
*/ */
public function asShortWeight($value, $decimals = null, $options = [], $text Options = []) public function asShortWeight($value, $decimals = null, $options = [], $text Options = [])
{ {
skipping to change at line 1752 skipping to change at line 1752
} }
/** /**
* Creates a number formatter based on the given type and format. * Creates a number formatter based on the given type and format.
* *
* You may override this method to create a number formatter based on patter ns. * You may override this method to create a number formatter based on patter ns.
* *
* @param int $style the type of the number formatter. * @param int $style the type of the number formatter.
* Values: NumberFormatter::DECIMAL, ::CURRENCY, ::PERCENT, ::SCIENTIFIC, :: SPELLOUT, ::ORDINAL * Values: NumberFormatter::DECIMAL, ::CURRENCY, ::PERCENT, ::SCIENTIFIC, :: SPELLOUT, ::ORDINAL
* ::DURATION, ::PATTERN_RULEBASED, ::DEFAULT_STYLE, ::IGNORE * ::DURATION, ::PATTERN_RULEBASED, ::DEFAULT_STYLE, ::IGNORE
* @param int $decimals the number of digits after the decimal point. * @param int|null $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]]. * @param array $options optional configuration for the number formatter. Th is parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]]. * @param array $textOptions optional configuration for the number formatter . This parameter will be merged with [[numberFormatterTextOptions]].
* @return NumberFormatter the created formatter instance * @return NumberFormatter the created formatter instance
*/ */
protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = []) protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = [])
{ {
$formatter = new NumberFormatter($this->locale, $style); $formatter = new NumberFormatter($this->locale, $style);
// set text attributes // set text attributes
foreach ($this->numberFormatterTextOptions as $name => $attribute) { foreach ($this->numberFormatterTextOptions as $name => $attribute) {
skipping to change at line 2019 skipping to change at line 2019
return $this->asDecimalStringFallback($integerPart, 0); return $this->asDecimalStringFallback($integerPart, 0);
} }
/** /**
* Fallback for formatting value as a percent number with "%" sign. * Fallback for formatting value as a percent number with "%" sign.
* *
* Property [[decimalSeparator]] will be used to represent the decimal point . The value is rounded automatically * Property [[decimalSeparator]] will be used to represent the decimal point . The value is rounded automatically
* to the defined decimal digits. * to the defined decimal digits.
* *
* @param string|int|float $value the value to be formatted. * @param string|int|float $value the value to be formatted.
* @param int $decimals the number of digits after the decimal point. The de fault value is `0`. * @param int|null $decimals the number of digits after the decimal point. T he default value is `0`.
* @return string the formatted result. * @return string the formatted result.
* @since 2.0.16 * @since 2.0.16
*/ */
protected function asPercentStringFallback($value, $decimals = null) protected function asPercentStringFallback($value, $decimals = null)
{ {
if (empty($value)) { if (empty($value)) {
$value = 0; $value = 0;
} }
if ($decimals === null) { if ($decimals === null) {
skipping to change at line 2059 skipping to change at line 2059
$multipliedValue = $value . '00'; $multipliedValue = $value . '00';
} }
return $this->asDecimalStringFallback($multipliedValue, $decimals) . '%' ; return $this->asDecimalStringFallback($multipliedValue, $decimals) . '%' ;
} }
/** /**
* Fallback for formatting value as a currency number. * Fallback for formatting value as a currency number.
* *
* @param string|int|float $value the value to be formatted. * @param string|int|float $value the value to be formatted.
* @param string $currency the 3-letter ISO 4217 currency code indicating th e currency to use. * @param string|null $currency the 3-letter ISO 4217 currency code indicati ng the currency to use.
* If null, [[currencyCode]] will be used. * If null, [[currencyCode]] will be used.
* @return string the formatted result. * @return string the formatted result.
* @throws InvalidConfigException if no currency is given and [[currencyCode ]] is not defined. * @throws InvalidConfigException if no currency is given and [[currencyCode ]] is not defined.
* @since 2.0.16 * @since 2.0.16
*/ */
protected function asCurrencyStringFallback($value, $currency = null) protected function asCurrencyStringFallback($value, $currency = null)
{ {
if ($currency === null) { if ($currency === null) {
if ($this->currencyCode === null) { if ($this->currencyCode === null) {
throw new InvalidConfigException('The default currency code for the formatter is not defined.'); throw new InvalidConfigException('The default currency code for the formatter is not defined.');
 End of changes. 24 change blocks. 
24 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)