123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- class Text_CAPTCHA
- {
-
- private $_driver;
-
- private $_driverInitDone = false;
-
- function __construct($driver)
- {
- if (is_null($driver)) {
- throw new Text_CAPTCHA_Exception("No driver given");
- }
- $this->_driver = $driver;
- $this->_driverInitDone = false;
- }
-
- public static function factory($driver)
- {
- $driver = basename($driver);
- $class = 'Text_CAPTCHA_Driver_' . $driver;
-
- $driver = new $class;
- return new Text_CAPTCHA($driver);
- }
-
- public final function generate($newPhrase = false)
- {
- if (!$this->_driverInitDone) {
- throw new Text_CAPTCHA_Exception("Driver not initialized");
- }
- if ($newPhrase === true || is_null($this->_driver->getPhrase())) {
- $this->_driver->createPhrase();
- } else if (strlen($newPhrase) > 0) {
- $this->_driver->setPhrase($newPhrase);
- }
- $this->_driver->createCAPTCHA();
- }
-
- public final function init($options = array())
- {
- $this->_driver->resetDriver();
- $this->_driver->initDriver($options);
- $this->_driverInitDone = true;
- $this->generate();
- }
-
- public final function getCAPTCHA()
- {
- return $this->_driver->getCAPTCHA();
- }
-
- public final function getPhrase()
- {
- return $this->_driver->getPhrase();
- }
-
- public function getCAPTCHAAsJPEG()
- {
- return $this->_driver->_getCAPTCHAAsJPEG();
- }
- }
|