Development

Changeset 5635

You must first sign up to be able to contribute.

Changeset 5635

Show
Ignore:
Timestamp:
10/23/07 09:08:10 (1 year ago)
Author:
fabien
Message:

added some methods to sfValidator base class

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/validator/sfValidator.class.php

    r5581 r5635  
    5252 
    5353  /** 
    54    * Returns an array of current error messages. 
    55    * 
    56    * @return array An array of messages 
    57    */ 
    58   public function getMessages() 
    59   { 
    60     return $this->messages; 
     54   * Returns an error message given an error code. 
     55   * 
     56   * @param  string The error code 
     57   * 
     58   * @return string The error message, or the empty string if the error code does not exist 
     59   */ 
     60  public function getMessage($name) 
     61  { 
     62    return isset($this->messages[$name]) ? $this->messages[$name] : ''; 
    6163  } 
    6264 
     
    7375 
    7476  /** 
    75    * Returns an error message given an error code. 
    76    * 
    77    * @param  string The error code 
    78    * 
    79    * @return string The error message, or the empty string if the error code does not exist 
    80    */ 
    81   public function getMessage($name) 
    82   { 
    83     return isset($this->messages[$name]) ? $this->messages[$name] : ''; 
     77   * Returns an array of current error messages. 
     78   * 
     79   * @return array An array of messages 
     80   */ 
     81  public function getMessages() 
     82  { 
     83    return $this->messages; 
     84  } 
     85 
     86  /** 
     87   * Changes all error messages. 
     88   * 
     89   * @param array An array of error messages 
     90   */ 
     91  public function setMessages($values) 
     92  { 
     93    $this->messages = $values; 
     94  } 
     95 
     96  /** 
     97   * Gets an option value. 
     98   * 
     99   * @param  string The option name 
     100   * 
     101   * @return mixed  The option value 
     102   */ 
     103  public function getOption($name) 
     104  { 
     105    return isset($this->options[$name]) ? $this->options[$name] : null; 
    84106  } 
    85107 
     
    96118 
    97119  /** 
    98    * Gets an option value. 
    99    * 
    100    * @param  string The option name 
    101    * 
    102    * @return mixed  The option value 
    103    */ 
    104   public function getOption($name) 
    105   { 
    106     return isset($this->options[$name]) ? $this->options[$name] : null; 
    107   } 
    108  
    109   /** 
    110120   * Returns true if the option exists. 
    111121   * 
     
    117127  { 
    118128    return isset($this->options[$name]); 
     129  } 
     130 
     131  /** 
     132   * Returns all options. 
     133   * 
     134   * @return array An array if options 
     135   */ 
     136  public function getOptions() 
     137  { 
     138    return $this->options; 
     139  } 
     140 
     141  /** 
     142   * Changes all options. 
     143   * 
     144   * @param array An array if options 
     145   */ 
     146  public function setOptions($values) 
     147  { 
     148    $this->options = $values; 
    119149  } 
    120150 
  • trunk/test/unit/validator/sfValidatorTest.php

    r5581 r5635  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(21, new lime_output_color()); 
     13$t = new lime_test(23, new lime_output_color()); 
    1414 
    1515class ValidatorIdentity extends sfValidator 
     
    8080$t->is($v->getOption('nonexistant'), null, '->getOption() returns null if the option does not exist'); 
    8181 
     82// ->getOptions() ->setOptions() 
     83$t->diag('->getOptions() ->setOptions()'); 
     84$v->setOptions(array('required' => true, 'trim' => false)); 
     85$t->is($v->getOptions(), array('required' => true, 'trim' => false), '->setOptions() changes all options'); 
     86 
    8287// ->getMessages() 
    8388$t->diag('->getMessages()'); 
     
    102107} 
    103108 
     109// ->setMessages() 
     110$t->diag('->setMessages()'); 
     111$v->setMessages(array('required' => 'This is required.')); 
     112$t->is($v->getMessages(), array('required' => 'This is required.'), '->setMessages() changes all error messages'); 
     113 
    104114// ->getErrorCodes() 
    105115$t->diag('->getErrorCodes()');