Zend_Captcha-Adapters.xml 10 KB

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