Development

Changeset 8525

You must first sign up to be able to contribute.

Changeset 8525

Show
Ignore:
Timestamp:
04/18/08 16:48:08 (6 months ago)
Author:
fabien
Message:

added a new validated_file_class option to sfValidatorFile

Files:

Legend:

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

    r7902 r8525  
    6969        'image/gif', 
    7070    ))); 
     71    $this->addOption('validated_file_class', 'sfValidatedFile'); 
    7172 
    7273    $this->addMessage('max_size', 'File is too large (maximum is %max_size% bytes).'); 
     
    152153    } 
    153154 
    154     return new sfValidatedFile($value['name'], $mimeType, $value['tmp_name'], $value['size']); 
     155    $class = $this->getOption('validated_file_class'); 
     156 
     157    return new $class($value['name'], $mimeType, $value['tmp_name'], $value['size']); 
    155158  } 
    156159 
  • branches/1.1/test/unit/validator/sfValidatorFileTest.php

    r6945 r8525  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(58, new lime_output_color()); 
     13$t = new lime_test(59, new lime_output_color()); 
    1414 
    1515$tmpDir = sfToolkit::getTmpDir(); 
     
    128128$t->is($f->getSize(), strlen($content), '->clean() returns a sfValidatedFile with a computed file size if the size is not passed in the initial value'); 
    129129$t->is($f->getType(), 'text/plain', '->clean() returns a sfValidatedFile with a guessed content type'); 
     130 
     131class myValidatedFile extends sfValidatedFile 
     132{ 
     133} 
     134 
     135$v->setOption('validated_file_class', 'myValidatedFile'); 
     136$f = $v->clean(array('tmp_name' => $tmpDir.'/test.txt')); 
     137$t->ok($f instanceof myValidatedFile, '->clean() can take a "validated_file_class" option'); 
    130138 
    131139foreach (array(UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION) as $error)