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

Debug toolbar