本文整理汇总了PHP中sfValidatorBase::clean方法的典型用法代码示例。如果您正苦于以下问题:PHP sfValidatorBase::clean方法的具体用法?PHP sfValidatorBase::clean怎么用?PHP sfValidatorBase::clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfValidatorBase
的用法示例。
在下文中一共展示了sfValidatorBase::clean方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clean
private function clean(sfValidatorBase $v, $value)
{
$this->result = 'true';
try {
$v->clean($value);
} catch (Exception $e) {
$this->result = 'false';
}
$this->renderText($this->result);
}
示例2: doAskAndValidate
/**
* @see askAndValidate()
*/
public static function doAskAndValidate(sfTask $task, $question, sfValidatorBase $validator, array $options = array())
{
if (!is_array($question)) {
$question = array($question);
}
$options = array_merge(array('value' => null, 'attempts' => 3, 'style' => 'QUESTION'), $options);
while ($options['attempts']--) {
$value = is_null($options['value']) ? $task->ask(isset($error) && 'required' != $error->getCode() ? array_merge(array($error->getMessage(), ''), $question) : $question, isset($error) ? 'ERROR' : $options['style']) : $options['value'];
try {
$value = $validator->clean($value);
return $value;
} catch (sfValidatorError $error) {
$value = null;
}
}
throw $error;
}
示例3: askAndValidate
/**
* Asks for a value and validates the response.
*
* Available options:
*
* * value: A value to try against the validator before asking the user
* * attempts: Max number of times to ask before giving up (false by default, which means infinite)
* * style: Style for question output (QUESTION by default)
*
* @param string|array $question
* @param sfValidatorBase $validator
* @param array $options
*
* @return mixed
*/
public function askAndValidate($question, sfValidatorBase $validator, array $options = array())
{
if (!is_array($question)) {
$question = array($question);
}
$options = array_merge(array('value' => null, 'attempts' => false, 'style' => 'QUESTION'), $options);
// does the provided value passes the validator?
if ($options['value']) {
try {
return $validator->clean($options['value']);
} catch (sfValidatorError $error) {
}
}
// no, ask the user for a valid user
$error = null;
while (false === $options['attempts'] || $options['attempts']--) {
if (null !== $error) {
$this->logBlock($error->getMessage(), 'ERROR');
}
$value = $this->ask($question, $options['style'], null);
try {
return $validator->clean($value);
} catch (sfValidatorError $error) {
}
}
throw $error;
}