Browse Source

[ZF-6371] Zend_Validate_Date:

- added handling of application wide locale

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16377 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 năm trước cách đây
mục cha
commit
1cfff6e9bf
2 tập tin đã thay đổi với 17 bổ sung0 xóa
  1. 7 0
      library/Zend/Validate/Date.php
  2. 10 0
      tests/Zend/Validate/DateTest.php

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

@@ -73,6 +73,13 @@ class Zend_Validate_Date extends Zend_Validate_Abstract
     public function __construct($format = null, $locale = null)
     {
         $this->setFormat($format);
+        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/DateTest.php

@@ -213,6 +213,16 @@ class Zend_Validate_DateTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * @ZF-6374
+     */
+    public function testUsingApplicationLocale()
+    {
+        Zend_Registry::set('Zend_Locale', new Zend_Locale('de'));
+        $valid = new Zend_Validate_Date();
+        $this->assertTrue($valid->isValid('10.April.2008'));
+    }
+
+    /**
      * Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
      *
      * @param  integer $errno