Created
March 15, 2012 09:33
-
-
Save Allisone/2043245 to your computer and use it in GitHub Desktop.
PasswordValidator but with StringLengthValidator code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Me\My\Validation\Validator; | |
use TYPO3\FLOW3\Annotations as FLOW3; | |
/** | |
* Validator for password | |
* | |
* @api | |
* @FLOW3\Scope("singleton") | |
*/ | |
class PasswordValidator extends \TYPO3\FLOW3\Validation\Validator\AbstractValidator { | |
/** | |
* Checks if the given $value is a valid string and its length is between 'minimum' (defaults to 0 if not specified) | |
* and 'maximum' (defaults to infinite if not specified) to be specified in the validation options. | |
* Note: a value of NULL or empty string ('') is considered valid | |
* | |
* @param mixed $value The value that should be validated | |
* @return void | |
* @api | |
*/ | |
protected function isValid($value) { | |
echo \TYPO3\FLOW3\var_dump($this->options); | |
echo "PasswordValidator<br/>"; | |
// echo $this->options['minimum']; | |
echo "minimum ".((isset($this->options['minimum']) === true) ? "gesetzt" : "nicht da") . "<br/>"; | |
echo "maximum ".((isset($this->options['maximum']) === true) ? "gesetzt" : "nicht da") . "<br/>"; | |
// echo $this->options['minimum']; | |
die(); | |
if (isset($this->options['minimum']) && isset($this->options['maximum']) | |
&& $this->options['maximum'] < $this->options['minimum']) { | |
throw new \TYPO3\FLOW3\Validation\Exception\InvalidValidationOptionsException('The \'maximum\' is less than the \'minimum\' in the StringLengthValidator.', 1238107096); | |
} | |
if (is_object($value)) { | |
if (!method_exists($value, '__toString')) { | |
$this->addError('The given object could not be converted to a string.', 1238110957); | |
return; | |
} | |
} elseif (!is_string($value)) { | |
$this->addError('The given value was not a valid string.', 1269883975); | |
return; | |
} | |
$stringLength = strlen($value); | |
$isValid = TRUE; | |
if (isset($this->options['minimum']) && $stringLength < $this->options['minimum']) { | |
$isValid = FALSE; | |
} | |
if (isset($this->options['maximum']) && $stringLength > $this->options['maximum']) { | |
$isValid = FALSE; | |
} | |
if ($isValid === FALSE) { | |
if (isset($this->options['minimum']) && isset($this->options['maximum'])) { | |
$this->addError('The length of this text must be between %1$d and %2$d characters.', 1238108067, array($this->options['minimum'], $this->options['maximum'])); | |
} elseif (isset($this->options['minimum'])) { | |
$this->addError('This field must contain at least %1$d characters.', 1238108068, array($this->options['minimum'])); | |
} else { | |
$this->addError('This text may not exceed %1$d characters.', 1238108069, array($this->options['maximum'])); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment