Development

Changeset 6968

You must first sign up to be able to contribute.

Changeset 6968

Show
Ignore:
Timestamp:
01/06/08 07:48:13 (11 months ago)
Author:
fabien
Message:

added an arguments option to sfValidatorCallback

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/validator/sfValidatorCallback.class.php

    r5882 r6968  
    2424   * Available options: 
    2525   * 
    26    *  * callback: A valid PHP callback (required) 
     26   *  * callback:  A valid PHP callback (required) 
     27   *  * arguments: An array of arguments to pass to the callback 
    2728   * 
    2829   * @see sfValidator 
     
    3132  { 
    3233    $this->addRequiredOption('callback'); 
     34    $this->addOption('arguments', array()); 
    3335 
    3436    $this->setOption('required', false); 
     
    4042  protected function doClean($value) 
    4143  { 
    42     return call_user_func($this->getOption('callback'), $this, $value); 
     44    return call_user_func($this->getOption('callback'), $this, $value, $this->getOption('arguments')); 
    4345  } 
    4446} 
  • branches/1.1/test/unit/validator/sfValidatorCallbackTest.php

    r6945 r6968  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(6, new lime_output_color()); 
     13$t = new lime_test(7, new lime_output_color()); 
    1414 
    15 function clean_test($validator, $value
     15function clean_test($validator, $value, $arguments
    1616{ 
    1717  if ($value != 'foo') 
     
    2020  } 
    2121 
    22   return "*$value*"
     22  return "*$value*".implode('-', $arguments)
    2323} 
    2424 
     
    3737$v = new sfValidatorCallback(array('callback' => 'clean_test')); 
    3838 
     39// ->configure() 
     40$t->diag('->configure()'); 
     41$t->is($v->clean(''), null, '->configure() switch required to false by default'); 
     42 
    3943// ->clean() 
    4044$t->diag('->clean()'); 
     
    5256} 
    5357 
    54 // ->configure() 
    55 $t->diag('->configure()'); 
    56 $t->is($v->clean(''), null, '->configure() switch required to false by default'); 
     58$t->diag('callback with arguments'); 
     59$v = new sfValidatorCallback(array('callback' => 'clean_test', 'arguments' => array('fabien', 'symfony'))); 
     60$t->is($v->clean('foo'), '*foo*fabien-symfony', '->configure() can take an arguments option'); 
    5761 
    5862// ->asString() 
    5963$t->diag('->asString()'); 
     64$v = new sfValidatorCallback(array('callback' => 'clean_test')); 
    6065$t->is($v->asString(), 'Callback({ callback: clean_test })', '->asString() returns a string representation of the validator');