Пример #1
0
 private function clean(sfValidatorBase $v, $value)
 {
     $this->result = 'true';
     try {
         $v->clean($value);
     } catch (Exception $e) {
         $this->result = 'false';
     }
     $this->renderText($this->result);
 }
Пример #2
0
 /**
  * @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
0
 /**
  * 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;
 }