Zend_Captcha-Adapters.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.captcha.adapters">
  4. <title>CAPTCHA Adapters</title>
  5. <para>
  6. The following adapters are shipped with Zend Framework by default.
  7. </para>
  8. <sect2 id="zend.captcha.adapters.word">
  9. <title>Zend_Captcha_Word</title>
  10. <para>
  11. <classname>Zend_Captcha_Word</classname> is an abstract adapter that serves as the base
  12. class for most other CAPTCHA adapters. It provides mutators for
  13. specifying word length, session TTL, the session namespace object
  14. to use, and the session namespace class to use for persistence if
  15. you do not wish to use <classname>Zend_Session_Namespace</classname>.
  16. <classname>Zend_Captcha_Word</classname> encapsulates validation logic.
  17. </para>
  18. <para>
  19. By default, the word length is 8 characters, the session timeout is
  20. 5 minutes, and <classname>Zend_Session_Namespace</classname> is used for persistence
  21. (using the namespace "Zend_Form_Captcha_&lt;captcha ID&gt;").
  22. </para>
  23. <para>
  24. In addition to the methods required by the
  25. <classname>Zend_Captcha_Adapter</classname> interface,
  26. <classname>Zend_Captcha_Word</classname> exposes the following methods:
  27. </para>
  28. <itemizedlist>
  29. <listitem><para>
  30. <methodname>setWordLen($length)</methodname> and
  31. <methodname>getWordLen()</methodname> allow you to specify the length of the
  32. generated "word" in characters, and to retrieve the current value.
  33. </para></listitem>
  34. <listitem><para>
  35. <methodname>setTimeout($ttl)</methodname> and <methodname>getTimeout()</methodname>
  36. allow you to specify the time-to-live of the session token, and
  37. to retrieve the current value. <varname>$ttl</varname> should be
  38. specified in seconds.
  39. </para></listitem>
  40. <listitem><para>
  41. <methodname>setSessionClass($class)</methodname> and
  42. <methodname>getSessionClass()</methodname> allow you to specify an
  43. alternate <classname>Zend_Session_Namespace</classname> implementation to
  44. use to persist the CAPTCHA token and to retrieve the
  45. current value.
  46. </para></listitem>
  47. <listitem><para>
  48. <methodname>getId()</methodname> allows you to retrieve the current token
  49. identifier.
  50. </para></listitem>
  51. <listitem><para>
  52. <methodname>getWord()</methodname> allows you to retrieve the generated
  53. word to use with the CAPTCHA. It will generate the word for you if
  54. none has been generated yet.
  55. </para></listitem>
  56. <listitem><para>
  57. <methodname>setSession(Zend_Session_Namespace $session)</methodname> allows
  58. you to specify a session object to use for persisting the
  59. CAPTCHA token. <methodname>getSession()</methodname> allows you to retrieve
  60. the current session object.
  61. </para></listitem>
  62. </itemizedlist>
  63. <para>
  64. All word CAPTCHAs allow you to pass an array of options to the
  65. constructor, or, alternately, pass them to
  66. <methodname>setOptions()</methodname>. You can also pass a
  67. <classname>Zend_Config</classname> object to <methodname>setConfig()</methodname>. By
  68. default, the <emphasis>wordLen</emphasis>, <emphasis>timeout</emphasis>, and
  69. <emphasis>sessionClass</emphasis> keys may all be used. Each concrete
  70. implementation may define additional keys or utilize the options in
  71. other ways.
  72. </para>
  73. <note>
  74. <para>
  75. <classname>Zend_Captcha_Word</classname> is an abstract class and may not be
  76. instantiated directly.
  77. </para>
  78. </note>
  79. </sect2>
  80. <sect2 id="zend.captcha.adapters.dumb">
  81. <title>Zend_Captcha_Dumb</title>
  82. <para>
  83. The <classname>Zend_Captch_Dumb</classname> adapter is mostly self-descriptive. It
  84. provides a random string that must be typed in reverse to validate. As such, it's
  85. not a good CAPTCHA solution and should only be used for
  86. testing. It extends <classname>Zend_Captcha_Word</classname>.
  87. </para>
  88. </sect2>
  89. <sect2 id="zend.captcha.adapters.figlet">
  90. <title>Zend_Captcha_Figlet</title>
  91. <para>
  92. The <classname>Zend_Captcha_Figlet</classname> adapter utilizes <link
  93. linkend="zend.text.figlet"><classname>Zend_Text_Figlet</classname></link> to present
  94. a figlet to the user.
  95. </para>
  96. <para>
  97. Options passed to the constructor will also be passed to the <link
  98. linkend="zend.text.figlet">Zend_Text_Figlet</link> object. See
  99. the <link linkend="zend.text.figlet">Zend_Text_Figlet</link>documentation for
  100. details on what configuration options are available.
  101. </para>
  102. </sect2>
  103. <sect2 id="zend.captcha.adapters.image">
  104. <title>Zend_Captcha_Image</title>
  105. <para>
  106. The Zend_Captcha_Image adapter takes the generated word and renders it as an
  107. image, performing various skewing permutations to make it
  108. difficult to automatically decipher. It
  109. requires the <ulink url="http://php.net/gd">GD extension</ulink>
  110. compiled with TrueType or Freetype support. Currently, the Zend_Captcha_Image
  111. adapter can only generate PNG images.
  112. </para>
  113. <para>
  114. <classname>Zend_Captcha_Image</classname> extends
  115. <classname>Zend_Captcha_Word</classname>, and additionally exposes the
  116. following methods:
  117. </para>
  118. <itemizedlist>
  119. <listitem><para>
  120. <methodname>setExpiration($expiration)</methodname> and
  121. <methodname>getExpiration()</methodname> allow you to specify a maximum
  122. lifetime the CAPTCHA image may reside on the filesystem. This is
  123. typically a longer than the session lifetime. Garbage
  124. collection is run periodically each time the CAPTCHA object is
  125. invoked, deleting all images that have expired.
  126. Expiration values should be specified in seconds.
  127. </para></listitem>
  128. <listitem><para>
  129. <methodname>setGcFreq($gcFreq)</methodname> and <methodname>getGcFreg()</methodname>
  130. allow you to specify how frequently garbage collection should
  131. run. Garbage collection will run every <emphasis>1/$gcFreq</emphasis>
  132. calls. The default is 100.
  133. </para></listitem>
  134. <listitem><para>
  135. <methodname>setFont($font)</methodname> and <methodname>getFont()</methodname> allow
  136. you to specify the font you will use. <varname>$font</varname>
  137. should be a fully qualified path to the font file.
  138. This value is required; the CAPTCHA will throw an
  139. exception during generation if the font file has not been specified.
  140. </para></listitem>
  141. <listitem><para>
  142. <methodname>setFontSize($fsize)</methodname> and
  143. <methodname>getFontSize()</methodname> allow you to specify the font size in pixels
  144. for generating the CAPTCHA. The default is 24px.
  145. </para></listitem>
  146. <listitem><para>
  147. <methodname>setHeight($height)</methodname> and <methodname>getHeight()</methodname>
  148. allow you to specify the height in pixels of the generated
  149. CAPTCHA image. The default is 50px.
  150. </para></listitem>
  151. <listitem><para>
  152. <methodname>setWidth($width)</methodname> and <methodname>getWidth()</methodname>
  153. allow you to specify the width in pixels of the generated
  154. CAPTCHA image. The default is 200px.
  155. </para></listitem>
  156. <listitem><para>
  157. <methodname>setImgDir($imgDir)</methodname> and <methodname>getImgDir()</methodname>
  158. allow you to specify the directory for storing CAPTCHA images.
  159. The default is "./images/captcha/", relative to the bootstrap script.
  160. </para></listitem>
  161. <listitem><para>
  162. <methodname>setImgUrl($imgUrl)</methodname> and <methodname>getImgUrl()</methodname>
  163. allow you to specify the relative path to a CAPTCHA image to
  164. use for HTML markup. The default is "/images/captcha/".
  165. </para></listitem>
  166. <listitem><para>
  167. <methodname>setSuffix($suffix)</methodname> and <methodname>getSuffix()</methodname>
  168. allow you to specify the filename suffix for the CAPTCHA image. The
  169. default is ".png". Note: changing this value will not change the
  170. type of the generated image.
  171. </para></listitem>
  172. </itemizedlist>
  173. <para>
  174. All of the above options may be passed to the
  175. constructor by simply removing the 'set' method prefix and casting
  176. the initial letter to lowercase: "suffix", "height", "imgUrl", etc.
  177. </para>
  178. </sect2>
  179. <sect2 id="zend.captcha.adapters.recaptcha">
  180. <title>Zend_Captcha_ReCaptcha</title>
  181. <para>
  182. The <classname>Zend_Captcha_ReCaptcha</classname> adapter uses <link
  183. linkend="zend.service.recaptcha">Zend_Service_ReCaptcha</link>
  184. to generate and validate CAPTCHAs. It exposes the following
  185. methods:
  186. </para>
  187. <itemizedlist>
  188. <listitem><para>
  189. <methodname>setPrivKey($key)</methodname> and <methodname>getPrivKey()</methodname>
  190. allow you to specify the private key to use for the ReCaptcha
  191. service. This must be specified during construction, although it
  192. may be overridden at any point.
  193. </para></listitem>
  194. <listitem><para>
  195. <methodname>setPubKey($key)</methodname> and <methodname>getPubKey()</methodname>
  196. allow you to specify the public key to use with the ReCaptcha
  197. service. This must be specified during construction, although it
  198. may be overridden at any point.
  199. </para></listitem>
  200. <listitem><para>
  201. <methodname>setService(Zend_Service_ReCaptcha $service)</methodname> and
  202. <methodname>getService()</methodname> allow you to set and get
  203. the ReCaptcha service object.
  204. </para></listitem>
  205. </itemizedlist>
  206. </sect2>
  207. </sect1>
  208. <!--
  209. vim:se ts=4 sw=4 et:
  210. -->