Zend_Validate-Identical.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.validate.set.identical">
  4. <title>Identical</title>
  5. <para>
  6. <classname>Zend_Validate_Identical</classname> allows you to validate if a given value is
  7. identical with an set haystack.
  8. </para>
  9. <sect3 id="zend.validate.set.identical.basic">
  10. <title>Basic usage</title>
  11. <para>
  12. To validate if two values are identical you need to set the origin value as haystack.
  13. See the following example which validates two strings.
  14. </para>
  15. <programlisting language="php"><![CDATA[
  16. $valid = new Zend_Validate_Identical('origin');
  17. if ($valid->isValid($value) {
  18. return true;
  19. }
  20. ]]></programlisting>
  21. <para>
  22. The validation will only then return <constant>TRUE</constant> when both values are
  23. 100% identical. In our example, when <varname>$value</varname> is 'origin'.
  24. </para>
  25. <para>
  26. You can set the wished token also afterwards by using the method
  27. <methodname>setToken()</methodname> and <methodname>getToken()</methodname> to get
  28. the actual set token.
  29. </para>
  30. </sect3>
  31. <sect3 id="zend.validate.set.identical.types">
  32. <title>Identical objects</title>
  33. <para>
  34. Of course <classname>Zend_Validate_Identical</classname> can not only validate strings,
  35. but also any other variable type like Boolean, Integer, Float, Array or even Objects.
  36. As already noted Haystack and Value must be identical.
  37. </para>
  38. <programlisting language="php"><![CDATA[
  39. $valid = new Zend_Validate_Identical(123);
  40. if ($valid->isValid($input)) {
  41. // input appears to be valid
  42. } else {
  43. // input is invalid
  44. }
  45. ]]></programlisting>
  46. <note>
  47. <title>Type comparison</title>
  48. <para>
  49. You should be aware that also the type of a variable is used for validation.
  50. This means that the string <emphasis>'3'</emphasis> is not identical with the
  51. integer <emphasis>3</emphasis>.
  52. </para>
  53. <para>
  54. This is also the case for Form Elements. They are objects or arrays. So you can't
  55. simply compare a Textfield which contains a password with an textual password
  56. from another source. The Element itself is given as array which also contains
  57. additional informations.
  58. </para>
  59. </note>
  60. </sect3>
  61. <sect3 id="zend.validate.set.identical.configuration">
  62. <title>Configuration</title>
  63. <para>
  64. As all other validators also <classname>Zend_Validate_Identical</classname> supports
  65. the usage of configuration settings as input parameter. This means that you can
  66. configure this validator with an <classname>Zend_Config</classname> object.
  67. </para>
  68. <para>
  69. But this adds one case which you have to be aware. When you are using an array as
  70. haystack then you should wrap it within an <property>'token'</property> key when
  71. it could contain only one element.
  72. </para>
  73. <programlisting language="php"><![CDATA[
  74. $valid = new Zend_Validate_Identical(array('token' => 123));
  75. if ($valid->isValid($input)) {
  76. // input appears to be valid
  77. } else {
  78. // input is invalid
  79. }
  80. ]]></programlisting>
  81. <para>
  82. The above example validates the integer 123. The reason for this special case is, that
  83. you can configure the token which has to be used by giving the
  84. <property>'token'</property> key.
  85. </para>
  86. <para>
  87. So, when your haystack contains one element and this element is named
  88. <property>'token'</property> then you have to wrap it like shown in the example below.
  89. </para>
  90. <programlisting language="php"><![CDATA[
  91. $valid = new Zend_Validate_Identical(array('token' => array('token' => 123)));
  92. if ($valid->isValid($input)) {
  93. // input appears to be valid
  94. } else {
  95. // input is invalid
  96. }
  97. ]]></programlisting>
  98. </sect3>
  99. </sect2>
  100. <!--
  101. vim:se ts=4 sw=4 et:
  102. -->