|
Revision 75, 0.9 kB
(checked in by nperriault, 3 months ago)
|
[1.1]:
- Companies and people modules migrated, with according form classes and templates, and functional test suite
- Enhanced SymfoniansTestBrowser?
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
class sfValidatorTags extends sfValidatorBase |
|---|
| 7 |
{ |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
* Configures the validator |
|---|
| 11 |
* |
|---|
| 12 |
* @param unknown_type $options |
|---|
| 13 |
* @param unknown_type $messages |
|---|
| 14 |
*/ |
|---|
| 15 |
public function configure($options = array(), $messages = array()) |
|---|
| 16 |
{ |
|---|
| 17 |
$this->addOption('separator', ','); |
|---|
| 18 |
$this->setMessage('invalid', 'Looks like your tags should be separated by the "%separator%" char'); |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
* Apply validator |
|---|
| 23 |
* |
|---|
| 24 |
* @param mixed $value |
|---|
| 25 |
* @return mixed |
|---|
| 26 |
*/ |
|---|
| 27 |
public function doClean($value) |
|---|
| 28 |
{ |
|---|
| 29 |
if (' ' === $this->getOption('separator')) |
|---|
| 30 |
{ |
|---|
| 31 |
return $value; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
$words = str_word_count($value); |
|---|
| 35 |
$seps = substr_count($value, $this->getOption('separator')); |
|---|
| 36 |
|
|---|
| 37 |
if ($seps < $words / 2) |
|---|
| 38 |
{ |
|---|
| 39 |
throw new sfValidatorError($this, 'invalid', array('separator' => $this->getOption('separator'))); |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
return $value; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
} |
|---|
| 46 |
|
|---|