Просмотр исходного кода

[ZF-7705, ZF-3164, ZF-3920] Zend_Validate:

- added format token
- unified keys

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17874 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 лет назад
Родитель
Сommit
f941f43f12

+ 1 - 5
documentation/manual/en/module_specs/Zend_Validate-Messages.xml

@@ -14,7 +14,7 @@
 
     <table id="zend.validate.messages.table">
         <title>Available Validation Messages</title>
-        <tgroup cols="4">
+        <tgroup cols="3">
             <thead>
                 <row>
                     <entry>Validator</entry>
@@ -96,10 +96,6 @@
                     <entry>'%value%' does not appear to be a valid date</entry>
                 </row>
                 <row>
-                    <entry><constant>NOT_YYYY_MM_DD</constant></entry>
-                    <entry>'%value%' is not of the format YYYY-MM-DD</entry>
-                </row>
-                <row>
                     <entry morerows="1" valign="middle">Db_Abstract</entry>
                     <entry><constant>ERROR_NO_RECORD_FOUND</constant></entry>
                     <entry>No record matching %value% was found</entry>

+ 87 - 0
documentation/manual/en/module_specs/Zend_Validate-Migration.xml

@@ -59,5 +59,92 @@ My_Validator extends Zend_Validate_Abstract
 }
 ]]></programlisting>
         </sect3>
+
+        <sect3 id="zend.validate.migration.fromoneninetooneten.datevalidator">
+            <title>Simplification in date validator</title>
+
+            <para>
+                Before Zend Framework 1.10 2 identical messages were thrown within the date
+                validator. These were <constant>NOT_YYYY_MM_DD</constant> and
+                <constant>FALSEFORMAT</constant>. As of Zend Framework 1.10 only the
+                <constant>FALSEFORMAT</constant> message will be returned when the given date
+                does not match the set format.
+            </para>
+        </sect3>
+
+        <sect3 id="zend.validate.migration.fromoneninetooneten.barcodevalidator">
+            <title>Fixes in Alpha, Alnum and Barcode validator</title>
+
+            <para>
+                Before Zend Framework 1.10 the messages within the 2 barcode adapters, the Alpha
+                and the Alnum validator were identical. This introduced problems when using custom
+                messages, translations or multiple instances of these validators.
+            </para>
+
+            <para>
+                As with Zend Framework 1.10 the values of the constants were changed to
+                be unique. When you used the constants as proposed in the manual there is
+                no change for you. But when you used the content of the constants in your code
+                then you will have to change them. The following table shows you the changed values:
+            </para>
+
+            <table id="zend.validate.messages.table">
+                <title>Available Validation Messages</title>
+                <tgroup cols="3">
+                    <thead>
+                        <row>
+                            <entry>Validator</entry>
+                            <entry>Constant</entry>
+                            <entry>Value</entry>
+                        </row>
+                    </thead>
+
+                    <tbody>
+                        <row>
+                            <entry>Alnum</entry>
+                            <entry><constant>STRING_EMPTY</constant></entry>
+                            <entry>alnumStringEmpty</entry>
+                        </row>
+
+                        <row>
+                            <entry>Alpha</entry>
+                            <entry><constant>STRING_EMPTY</constant></entry>
+                            <entry>alphaStringEmpty</entry>
+                        </row>
+
+                        <row>
+                            <entry>Barcode_Ean13</entry>
+                            <entry><constant>INVALID</constant></entry>
+                            <entry>ean13Invalid</entry>
+                        </row>
+
+                        <row>
+                            <entry>Barcode_Ean13</entry>
+                            <entry><constant>INVALID_LENGTH</constant></entry>
+                            <entry>ean13InvalidLength</entry>
+                        </row>
+
+                        <row>
+                            <entry>Barcode_UpcA</entry>
+                            <entry><constant>INVALID</constant></entry>
+                            <entry>upcaInvalid</entry>
+                        </row>
+
+                        <row>
+                            <entry>Barcode_UpcA</entry>
+                            <entry><constant>INVALID_LENGTH</constant></entry>
+                            <entry>upcaInvalidLength</entry>
+                        </row>
+
+                        <row>
+                            <entry>Digits</entry>
+                            <entry><constant>STRING_EMPTY</constant></entry>
+                            <entry>digitsStringEmpty</entry>
+                        </row>
+                    </tbody>
+                </tgroup>
+            </table>
+
+        </sect3>
     </sect2>
 </sect1>

+ 1 - 1
library/Zend/Validate/Alnum.php

@@ -34,7 +34,7 @@ class Zend_Validate_Alnum extends Zend_Validate_Abstract
 {
     const INVALID      = 'alnumInvalid';
     const NOT_ALNUM    = 'notAlnum';
-    const STRING_EMPTY = 'stringEmpty';
+    const STRING_EMPTY = 'alnumStringEmpty';
 
     /**
      * Whether to allow white space characters; off by default

+ 1 - 1
library/Zend/Validate/Alpha.php

@@ -34,7 +34,7 @@ class Zend_Validate_Alpha extends Zend_Validate_Abstract
 {
     const INVALID      = 'alphaInvalid';
     const NOT_ALPHA    = 'notAlpha';
-    const STRING_EMPTY = 'stringEmpty';
+    const STRING_EMPTY = 'alphaStringEmpty';
 
     /**
      * Whether to allow white space characters; off by default

+ 2 - 2
library/Zend/Validate/Barcode/Ean13.php

@@ -39,13 +39,13 @@ class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract
      * Validation failure message key for when the value is
      * an invalid barcode
      */
-    const INVALID = 'invalid';
+    const INVALID = 'ean13Invalid';
 
     /**
      * Validation failure message key for when the value is
      * not 13 characters long
      */
-    const INVALID_LENGTH = 'invalidLength';
+    const INVALID_LENGTH = 'ean13InvalidLength';
 
     /**
      * Validation failure message key for when the value

+ 2 - 2
library/Zend/Validate/Barcode/UpcA.php

@@ -39,13 +39,13 @@ class Zend_Validate_Barcode_UpcA extends Zend_Validate_Abstract
      * Validation failure message key for when the value is
      * an invalid barcode
      */
-    const INVALID = 'invalid';
+    const INVALID = 'upcaInvalid';
 
     /**
      * Validation failure message key for when the value is
      * not 12 characters long
      */
-    const INVALID_LENGTH = 'invalidLength';
+    const INVALID_LENGTH = 'upcaInvalidLength';
 
     /**
      * Validation failure message template definitions

+ 12 - 5
library/Zend/Validate/Date.php

@@ -33,8 +33,7 @@ require_once 'Zend/Validate/Abstract.php';
 class Zend_Validate_Date extends Zend_Validate_Abstract
 {
     const INVALID        = 'dateInvalid';
-    const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD';
-    const INVALID_DATE    = 'dateInvalidDate';
+    const INVALID_DATE   = 'dateInvalidDate';
     const FALSEFORMAT    = 'dateFalseFormat';
 
     /**
@@ -44,9 +43,15 @@ class Zend_Validate_Date extends Zend_Validate_Abstract
      */
     protected $_messageTemplates = array(
         self::INVALID        => "Invalid type given, value should be string, integer, array or Zend_Date",
-        self::NOT_YYYY_MM_DD => "'%value%' is not of the format YYYY-MM-DD",
         self::INVALID_DATE   => "'%value%' does not appear to be a valid date",
-        self::FALSEFORMAT    => "'%value%' does not fit given date format"
+        self::FALSEFORMAT    => "'%value%' does not fit the date format '%format'"
+    );
+
+    /**
+     * @var array
+     */
+    protected $_messageVariables = array(
+        'format'  => '_format'
     );
 
     /**
@@ -163,7 +168,9 @@ class Zend_Validate_Date extends Zend_Validate_Abstract
             }
         } else {
             if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
-                $this->_error(self::NOT_YYYY_MM_DD);
+                $this->_format = 'yyyy-MM-dd';
+                $this->_error(self::FALSEFORMAT);
+                $this->_format = null;
                 return false;
             }
 

+ 1 - 1
library/Zend/Validate/Digits.php

@@ -36,7 +36,7 @@ require_once 'Zend/Validate/Abstract.php';
 class Zend_Validate_Digits extends Zend_Validate_Abstract
 {
     const NOT_DIGITS   = 'notDigits';
-    const STRING_EMPTY = 'stringEmpty';
+    const STRING_EMPTY = 'digitsStringEmpty';
     const INVALID      = 'digitsInvalid';
 
     /**