Zend_Captcha-Adapters.xml 12 KB

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