Base.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Base class file for all Text_CAPTCHA drivers.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Text
  8. * @package Text_CAPTCHA
  9. * @author Michael Cramer <michael@bigmichi1.de>
  10. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  11. * @link http://pear.php.net/package/Text_CAPTCHA
  12. */
  13. require_once 'Text/CAPTCHA/Driver.php';
  14. /**
  15. * Base class file for all Text_CAPTCHA drivers.
  16. *
  17. * @category Text
  18. * @package Text_CAPTCHA
  19. * @author Michael Cramer <michael@bigmichi1.de>
  20. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  21. * @link http://pear.php.net/package/Text_CAPTCHA
  22. */
  23. abstract class Text_CAPTCHA_Driver_Base implements Text_CAPTCHA_Driver
  24. {
  25. /**
  26. * Captcha
  27. *
  28. * @var object|string
  29. */
  30. private $_captcha;
  31. /**
  32. * Phrase
  33. *
  34. * @var string
  35. */
  36. private $_phrase;
  37. /**
  38. * Sets secret CAPTCHA phrase.
  39. * This method sets the CAPTCHA phrase (use null for a random phrase)
  40. *
  41. * @param string $phrase The (new) phrase
  42. *
  43. * @return void
  44. */
  45. public final function setPhrase($phrase)
  46. {
  47. $this->_phrase = $phrase;
  48. }
  49. /**
  50. * Return secret CAPTCHA phrase
  51. * This method returns the CAPTCHA phrase
  52. *
  53. * @return string secret phrase
  54. */
  55. public final function getPhrase()
  56. {
  57. return $this->_phrase;
  58. }
  59. /**
  60. * Sets the generated captcha.
  61. *
  62. * @param object|string $captcha the generated captcha
  63. *
  64. * @return void
  65. */
  66. protected final function setCaptcha($captcha)
  67. {
  68. $this->_captcha = $captcha;
  69. }
  70. /**
  71. * Place holder for the real getCAPTCHA() method
  72. * used by extended classes to return the generated CAPTCHA
  73. * (as an image resource, as an ASCII text, ...)
  74. *
  75. * @return string|object
  76. */
  77. public final function getCAPTCHA()
  78. {
  79. return $this->_captcha;
  80. }
  81. /**
  82. * Reset the phrase and the CAPTCHA.
  83. *
  84. * @return void
  85. */
  86. public function resetDriver()
  87. {
  88. $this->setPhrase(null);
  89. $this->setCaptcha(null);
  90. }
  91. }