sfValidatorDecorator.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfValidatorDecorator decorates another validator.
  11. *
  12. * This validator has exactly the same behavior as the Decorator validator.
  13. *
  14. * The options and messages are proxied from the decorated validator.
  15. *
  16. * @package symfony
  17. * @subpackage validator
  18. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  19. * @version SVN: $Id: sfValidatorDecorator.class.php 7902 2008-03-15 13:17:33Z fabien $
  20. */
  21. abstract class sfValidatorDecorator extends sfValidatorBase
  22. {
  23. protected
  24. $validator = null;
  25. /**
  26. * @see sfValidatorBase
  27. */
  28. public function __construct($options = array(), $messages = array())
  29. {
  30. $this->validator = $this->getValidator();
  31. if (!$this->validator instanceof sfValidatorBase)
  32. {
  33. throw new RuntimeException('The getValidator() method must return a sfValidatorBase instance.');
  34. }
  35. foreach ($options as $key => $value)
  36. {
  37. $this->validator->setOption($key, $value);
  38. }
  39. foreach ($messages as $key => $value)
  40. {
  41. $this->validator->setMessage($key, $value);
  42. }
  43. }
  44. /**
  45. * Returns the decorated validator.
  46. *
  47. * Every subclass must implement this method.
  48. *
  49. * @return sfValidatorBase A sfValidatorBase instance
  50. */
  51. abstract protected function getValidator();
  52. /**
  53. * @see sfValidatorBase
  54. */
  55. public function clean($value)
  56. {
  57. return $this->doClean($value);
  58. }
  59. /**
  60. * @see sfValidatorBase
  61. */
  62. protected function doClean($value)
  63. {
  64. return $this->validator->clean($value);
  65. }
  66. /**
  67. * @see sfValidatorBase
  68. */
  69. public function getMessage($name)
  70. {
  71. return $this->validator->getMessage($name);
  72. }
  73. /**
  74. * @see sfValidatorBase
  75. */
  76. public function setMessage($name, $value)
  77. {
  78. $this->validator->setMessage($name, $value);
  79. }
  80. /**
  81. * @see sfValidatorBase
  82. */
  83. public function getMessages()
  84. {
  85. return $this->validator->getMessages();
  86. }
  87. /**
  88. * @see sfValidatorBase
  89. */
  90. public function setMessages($values)
  91. {
  92. return $this->validator->setMessages($values);
  93. }
  94. /**
  95. * @see sfValidatorBase
  96. */
  97. public function getOption($name)
  98. {
  99. return $this->validator->getOption($name);
  100. }
  101. /**
  102. * @see sfValidatorBase
  103. */
  104. public function setOption($name, $value)
  105. {
  106. $this->validator->setOption($name, $value);
  107. }
  108. /**
  109. * @see sfValidatorBase
  110. */
  111. public function hasOption($name)
  112. {
  113. return $this->validator->hasOption($name);
  114. }
  115. /**
  116. * @see sfValidatorBase
  117. */
  118. public function getOptions()
  119. {
  120. return $this->validator->getOptions();
  121. }
  122. /**
  123. * @see sfValidatorBase
  124. */
  125. public function setOptions($values)
  126. {
  127. $this->validator->setOptions($values);
  128. }
  129. /**
  130. * @see sfValidatorBase
  131. */
  132. public function asString($indent = 0)
  133. {
  134. return $this->validator->asString($indent);
  135. }
  136. /**
  137. * @see sfValidatorBase
  138. */
  139. public function getDefaultOptions()
  140. {
  141. return $this->validator->getDefaultOptions();
  142. }
  143. /**
  144. * @see sfValidatorBase
  145. */
  146. public function getDefaultMessages()
  147. {
  148. return $this->validator->getDefaultMessages();
  149. }
  150. }