Go to the documentation of this file.00001 <?php
00002
00031 class Robo47_Validate_StringContains extends Zend_Validate_Abstract
00032 {
00033 const CONTAINS = 'contains';
00034
00038 protected $_contains = '';
00039 protected $_messageTemplates = array(
00040 self::CONTAINS =>
00041 "'%value%' does not contain any of the specified strings",
00042 );
00043 protected $_messageVariables = array(
00044 'value' => '_value',
00045 );
00046
00050 public function __construct($contains)
00051 {
00052 $this->setContains($contains);
00053 }
00054
00061 public function setContains($contains)
00062 {
00063 if (is_string($contains)) {
00064 $contains = array($contains);
00065 }
00066 if (empty($contains)) {
00067 $message = '$contains is empty';
00068 throw new Robo47_Validate_Exception($message);
00069 }
00070 $this->_contains = $contains;
00071 return $this;
00072 }
00073
00079 public function getContains()
00080 {
00081 return $this->_contains;
00082 }
00083
00089 public function isValid($value)
00090 {
00091 $this->_setValue($value);
00092
00093 $isValid = false;
00094 foreach ($this->_contains as $contains) {
00095 if (false !== strpos($value, $contains)) {
00096 $isValid = true;
00097 $this->_error(self::CONTAINS);
00098 break;
00099 }
00100 }
00101 return $isValid;
00102 }
00103 }