Zend_Captcha-Adapters.xml 13 KB

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