diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index 8691d827da..4aa579d927 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -234,6 +234,25 @@ class StubNumberFormatter $this->style = $style; } + /** + * Static constructor + * + * @param string $locale The locale code + * @param int $style Style of the formatting, one of the format style constants + * @param string $pattern A pattern string in case $style is NumberFormat::PATTERN_DECIMAL or + * NumberFormat::PATTERN_RULEBASED. It must conform to the syntax + * described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation + * @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details + * @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details + * @throws MethodArgumentValueNotImplementedException When $locale different than 'en' is passed + * @throws MethodArgumentValueNotImplementedException When the $style is not supported + * @throws MethodArgumentNotImplementedException When the pattern value is different than null + */ + public static function create($locale = 'en', $style = null, $pattern = null) + { + return new self($locale, $style, $pattern); + } + /** * Format a currency value * diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index e650766545..8924513878 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -65,6 +65,20 @@ class StubNumberFormatterTest extends LocaleTestCase $ret = $formatter->setAttribute(StubNumberFormatter::ROUNDING_MODE, null); } + public function testCreateStub() + { + $this->assertInstanceOf( + 'Symfony\Component\Locale\Stub\StubNumberFormatter', + StubNumberFormatter::create('en', StubNumberFormatter::DECIMAL) + ); + } + + public function testCreateIntl() + { + $this->skipIfIntlExtensionIsNotLoaded(); + $this->assertInstanceOf('\NumberFormatter', \NumberFormatter::create('en', \NumberFormatter::DECIMAL)); + } + /** * @dataProvider formatCurrencyWithDecimalStyleProvider */