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