Zend_Validate-Identical.xml 4.7 KB

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