PageRenderTime 33ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Captcha/Base.php

http://github.com/michael-romer/zf-boilerplate
PHP | 176 lines | 63 code | 14 blank | 99 comment | 5 complexity | b357456f14463f60bdd2eb70fc37400c MD5 | raw file
Possible License(s): Unlicense, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Captcha
  17. * @subpackage Adapter
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** @see Zend_Captcha_Adapter */
  22. require_once 'Zend/Captcha/Adapter.php';
  23. /** @see Zend_Validate_Abstract */
  24. require_once 'Zend/Validate/Abstract.php';
  25. /**
  26. * Base class for Captcha adapters
  27. *
  28. * Provides some utility functionality to build on
  29. *
  30. * @category Zend
  31. * @package Zend_Captcha
  32. * @subpackage Adapter
  33. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @version $Id: Base.php 23775 2011-03-01 17:25:24Z ralph $
  36. */
  37. abstract class Zend_Captcha_Base extends Zend_Validate_Abstract implements Zend_Captcha_Adapter
  38. {
  39. /**
  40. * Element name
  41. *
  42. * Useful to generate/check form fields
  43. *
  44. * @var string
  45. */
  46. protected $_name;
  47. /**
  48. * Captcha options
  49. *
  50. * @var array
  51. */
  52. protected $_options = array();
  53. /**
  54. * Options to skip when processing options
  55. * @var array
  56. */
  57. protected $_skipOptions = array(
  58. 'options',
  59. 'config',
  60. );
  61. /**
  62. * Get name
  63. *
  64. * @return string
  65. */
  66. public function getName()
  67. {
  68. return $this->_name;
  69. }
  70. /**
  71. * Set name
  72. *
  73. * @param string $name
  74. */
  75. public function setName($name)
  76. {
  77. $this->_name = $name;
  78. return $this;
  79. }
  80. /**
  81. * Constructor
  82. *
  83. * @param array|Zend_Config $options
  84. * @return void
  85. */
  86. public function __construct($options = null)
  87. {
  88. // Set options
  89. if (is_array($options)) {
  90. $this->setOptions($options);
  91. } else if ($options instanceof Zend_Config) {
  92. $this->setConfig($options);
  93. }
  94. }
  95. /**
  96. * Set single option for the object
  97. *
  98. * @param string $key
  99. * @param string $value
  100. * @return Zend_Form_Element
  101. */
  102. public function setOption($key, $value)
  103. {
  104. if (in_array(strtolower($key), $this->_skipOptions)) {
  105. return $this;
  106. }
  107. $method = 'set' . ucfirst ($key);
  108. if (method_exists ($this, $method)) {
  109. // Setter exists; use it
  110. $this->$method ($value);
  111. $this->_options[$key] = $value;
  112. } elseif (property_exists($this, $key)) {
  113. // Assume it's metadata
  114. $this->$key = $value;
  115. $this->_options[$key] = $value;
  116. }
  117. return $this;
  118. }
  119. /**
  120. * Set object state from options array
  121. *
  122. * @param array $options
  123. * @return Zend_Form_Element
  124. */
  125. public function setOptions($options = null)
  126. {
  127. foreach ($options as $key => $value) {
  128. $this->setOption($key, $value);
  129. }
  130. return $this;
  131. }
  132. /**
  133. * Retrieve options representing object state
  134. *
  135. * @return array
  136. */
  137. public function getOptions()
  138. {
  139. return $this->_options;
  140. }
  141. /**
  142. * Set object state from config object
  143. *
  144. * @param Zend_Config $config
  145. * @return Zend_Captcha_Base
  146. */
  147. public function setConfig(Zend_Config $config)
  148. {
  149. return $this->setOptions($config->toArray());
  150. }
  151. /**
  152. * Get optional decorator
  153. *
  154. * By default, return null, indicating no extra decorator needed.
  155. *
  156. * @return null
  157. */
  158. public function getDecorator()
  159. {
  160. return null;
  161. }
  162. }