Pārlūkot izejas kodu

[ZF-7489] Zend_Validate_Int/_Float:

- added usage of registry locale

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17798 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 gadi atpakaļ
vecāks
revīzija
db223d4bd3

+ 7 - 0
library/Zend/Validate/Float.php

@@ -57,6 +57,13 @@ class Zend_Validate_Float extends Zend_Validate_Abstract
      */
     public function __construct($locale = null)
     {
+        if ($locale === null) {
+            require_once 'Zend/Registry.php';
+            if (Zend_Registry::isRegistered('Zend_Locale')) {
+                $locale = Zend_Registry::get('Zend_Locale');
+            }
+        }
+
         if ($locale !== null) {
             $this->setLocale($locale);
         }

+ 7 - 0
library/Zend/Validate/Int.php

@@ -57,6 +57,13 @@ class Zend_Validate_Int extends Zend_Validate_Abstract
      */
     public function __construct($locale = null)
     {
+        if ($locale === null) {
+            require_once 'Zend/Registry.php';
+            if (Zend_Registry::isRegistered('Zend_Locale')) {
+                $locale = Zend_Registry::get('Zend_Locale');
+            }
+        }
+
         if ($locale !== null) {
             $this->setLocale($locale);
         }

+ 10 - 0
tests/Zend/Validate/FloatTest.php

@@ -104,4 +104,14 @@ class Zend_Validate_FloatTest extends PHPUnit_Framework_TestCase
     {
         $this->assertFalse($this->_validator->isValid(array(1 => 1)));
     }
+
+    /**
+     * @ZF-7489
+     */
+    public function testUsingApplicationLocale()
+    {
+        Zend_Registry::set('Zend_Locale', new Zend_Locale('de'));
+        $valid = new Zend_Validate_Float();
+        $this->assertTrue($valid->isValid('123,456'));
+    }
 }

+ 10 - 0
tests/Zend/Validate/IntTest.php

@@ -114,4 +114,14 @@ class Zend_Validate_IntTest extends PHPUnit_Framework_TestCase
     {
         $this->assertFalse($this->_validator->isValid(array(1 => 1)));
     }
+
+    /**
+     * @ZF-7489
+     */
+    public function testUsingApplicationLocale()
+    {
+        Zend_Registry::set('Zend_Locale', new Zend_Locale('de'));
+        $valid = new Zend_Validate_Int();
+        $this->assertTrue($valid->isValid('10.000'));
+    }
 }