Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
916d2c18
Commit
916d2c18
authored
Sep 08, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure some BC
ensure some features that were recently added to formatter keep working after refactoring
parent
9418c9d2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
Formatter.php
framework/i18n/Formatter.php
+13
-4
FormatterTest.php
tests/unit/framework/i18n/FormatterTest.php
+9
-2
No files found.
framework/i18n/Formatter.php
View file @
916d2c18
...
@@ -145,6 +145,7 @@ class Formatter extends Component
...
@@ -145,6 +145,7 @@ class Formatter extends Component
public
$numberFormatterTextOptions
=
[];
public
$numberFormatterTextOptions
=
[];
/**
/**
* @var string the 3-letter ISO 4217 currency code indicating the default currency to use for [[asCurrency]].
* @var string the 3-letter ISO 4217 currency code indicating the default currency to use for [[asCurrency]].
* If not set, the currency code corresponding to [[locale]] will be used.
*/
*/
public
$currencyCode
;
public
$currencyCode
;
/**
/**
...
@@ -987,6 +988,7 @@ class Formatter extends Component
...
@@ -987,6 +988,7 @@ class Formatter extends Component
*
*
* @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 the currency to use.
* @param string $currency the 3-letter ISO 4217 currency code indicating the currency to use.
* If null, [[currencyCode]] will be used.
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $options optional configuration for the number formatter. 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.
...
@@ -1000,16 +1002,23 @@ class Formatter extends Component
...
@@ -1000,16 +1002,23 @@ class Formatter extends Component
}
}
$value
=
$this
->
normalizeNumericValue
(
$value
);
$value
=
$this
->
normalizeNumericValue
(
$value
);
if
(
$this
->
_intlLoaded
)
{
$formatter
=
$this
->
createNumberFormatter
(
NumberFormatter
::
CURRENCY
,
null
,
$options
,
$textOptions
);
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.'
);
$currency
=
$formatter
->
getSymbol
(
NumberFormatter
::
INTL_CURRENCY_SYMBOL
);
}
}
else
{
$currency
=
$this
->
currencyCode
;
$currency
=
$this
->
currencyCode
;
}
}
if
(
$this
->
_intlLoaded
)
{
}
$formatter
=
$this
->
createNumberFormatter
(
NumberFormatter
::
CURRENCY
,
null
,
$options
,
$textOptions
);
return
$formatter
->
formatCurrency
(
$value
,
$currency
);
return
$formatter
->
formatCurrency
(
$value
,
$currency
);
}
else
{
}
else
{
if
(
$currency
===
null
)
{
if
(
$this
->
currencyCode
===
null
)
{
throw
new
InvalidConfigException
(
'The default currency code for the formatter is not defined.'
);
}
$currency
=
$this
->
currencyCode
;
}
return
$currency
.
' '
.
$this
->
asDecimal
(
$value
,
2
,
$options
,
$textOptions
);
return
$currency
.
' '
.
$this
->
asDecimal
(
$value
,
2
,
$options
,
$textOptions
);
}
}
}
}
...
...
tests/unit/framework/i18n/FormatterTest.php
View file @
916d2c18
...
@@ -546,7 +546,12 @@ class FormatterTest extends TestCase
...
@@ -546,7 +546,12 @@ class FormatterTest extends TestCase
public
function
testIntlAsCurrency
()
public
function
testIntlAsCurrency
()
{
{
$this
->
formatter
->
locale
=
'en_US'
;
$this
->
formatter
->
locale
=
'en-US'
;
$this
->
assertSame
(
'$123.00'
,
$this
->
formatter
->
asCurrency
(
'123'
));
$this
->
assertSame
(
'$123,456.00'
,
$this
->
formatter
->
asCurrency
(
'123456'
));
$this
->
assertSame
(
'$0.00'
,
$this
->
formatter
->
asCurrency
(
'0'
));
$this
->
formatter
->
locale
=
'en-US'
;
$this
->
formatter
->
currencyCode
=
'USD'
;
$this
->
formatter
->
currencyCode
=
'USD'
;
$this
->
assertSame
(
'$123.00'
,
$this
->
formatter
->
asCurrency
(
'123'
));
$this
->
assertSame
(
'$123.00'
,
$this
->
formatter
->
asCurrency
(
'123'
));
$this
->
assertSame
(
'$123,456.00'
,
$this
->
formatter
->
asCurrency
(
'123456'
));
$this
->
assertSame
(
'$123,456.00'
,
$this
->
formatter
->
asCurrency
(
'123456'
));
...
@@ -556,7 +561,9 @@ class FormatterTest extends TestCase
...
@@ -556,7 +561,9 @@ class FormatterTest extends TestCase
// $value = '-123456.123';
// $value = '-123456.123';
// $this->assertSame("($123,456.12)", $this->formatter->asCurrency($value));
// $this->assertSame("($123,456.12)", $this->formatter->asCurrency($value));
$this
->
formatter
->
locale
=
'de_DE'
;
$this
->
formatter
->
locale
=
'de-DE'
;
$this
->
formatter
->
currencyCode
=
null
;
$this
->
assertSame
(
'123,00 €'
,
$this
->
formatter
->
asCurrency
(
'123'
));
$this
->
formatter
->
currencyCode
=
'USD'
;
$this
->
formatter
->
currencyCode
=
'USD'
;
$this
->
assertSame
(
'123,00 $'
,
$this
->
formatter
->
asCurrency
(
'123'
));
$this
->
assertSame
(
'123,00 $'
,
$this
->
formatter
->
asCurrency
(
'123'
));
$this
->
formatter
->
currencyCode
=
'EUR'
;
$this
->
formatter
->
currencyCode
=
'EUR'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment