3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Captcha
;
13 use Zend\Validator\AbstractValidator
;
16 * Base class for Captcha adapters
18 * Provides some utility functionality to build on
20 abstract class AbstractAdapter
extends AbstractValidator
implements AdapterInterface
25 * Useful to generate/check form fields
36 protected $options = array();
39 * Options to skip when processing options
42 protected $skipOptions = array(
52 public function getName()
61 * @return AbstractAdapter
63 public function setName($name)
70 * Set single option for the object
73 * @param string $value
74 * @return AbstractAdapter
76 public function setOption($key, $value)
78 if (in_array(strtolower($key), $this->skipOptions
)) {
82 $method = 'set' . ucfirst($key);
83 if (method_exists($this, $method)) {
84 // Setter exists; use it
85 $this->$method($value);
86 $this->options
[$key] = $value;
87 } elseif (property_exists($this, $key)) {
88 // Assume it's metadata
90 $this->options
[$key] = $value;
96 * Set object state from options array
98 * @param array|Traversable $options
99 * @throws Exception\InvalidArgumentException
100 * @return AbstractAdapter
102 public function setOptions($options = array())
104 if (!is_array($options) && !$options instanceof Traversable
) {
105 throw new Exception\
InvalidArgumentException(__METHOD__
. ' expects an array or Traversable');
108 foreach ($options as $key => $value) {
109 $this->setOption($key, $value);
115 * Retrieve options representing object state
119 public function getOptions()
121 return $this->options
;
125 * Get helper name used to render captcha
127 * By default, return empty string, indicating no helper needed.
131 public function getHelperName()