Browse Source

[Locale] added static constructor

Eriksen Costa 14 years ago
parent
commit
b58e25cc83

+ 19 - 0
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
      *

+ 14 - 0
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
      */