protected function saveFile($field, $filename = null, sfValidatedFile $file = null)
{
if (!$this->validatorSchema[$field] instanceof sfValidatorFile) {
throw new LogicException(sprintf('You cannot save the current file for field "%s" as the field is not a file.', $field));
}
if (null === $file) {
$file = $this->getValue($field);
}
$column = call_user_func(array($this->getPeer(), 'translateFieldName'), $field, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
$method = sprintf('generate%sFilename', $column);
if (null !== $filename) {
return $file->save($filename);
} else {
if (method_exists($this, $method)) {
return $file->save($this->{$method}($file));
} else {
if (method_exists($this->getObject(), $method)) {
return $file->save($this->getObject()->{$method}($file));
} else {
return $file->save();
}
}
}
}