/**
  * Returns a new (child of) sfFilebasePluginFile. It returns an instance,
  * not regarding if the file exists or not. So you can fetch an instance
  * and create the underlying file by sfFilebasePlugin-methods.
  *
  * This method checks if file is a directory, an image
  * a link ... but beware, some attributes can only
  * be calculated if the file really exists in file system.
  *
  * For example, if you want to retrieve a directory that does
  * not exists, an instance of sfFilebasePluginFile is recieved.
  *
  * This behavior is simple and logically correct, but you have to keep it in
  * mind: sfFilebasePlugin cannot forecast what files you want to create. It
  * is probably more confusing for windows users where files are mostly
  * identified by its extension.
  *
  * If the dir exists, you'll get a sfFilebasePluginDirectory.
  *
  * @example $filebase->getFilebaseFile('path/to/directory') retrieves a dir
  *          if it exists in FS, or a sfFilebaseFile if not.
  *
  * @example Creating a new file:
  *          $new_file = $filebase->getFilebaseFile('path/to/new/file.txt');
  *          $filebase->touch($new_file);
  *          In Short: $filebase->touch('path/to/new/file.txt');
  *
  * @example Short way retrieving files:
  *          foreach ($filebase AS $file) ...
  *          with ArrayAccess:
  *          $file = $filebase['/path/to/file'];
  *
  * @todo Implement (sym)link handling.
  * @param string | sfFilebasePluginFile  $filename
  * @return sfFilebasePluginFile
  */
 public function getFilebaseFile($filename)
 {
     if (is_string($filename)) {
         //$filename = sfFilebasePluginUtil::unifySlashes($filename);
         if (strlen($filename) > 0) {
             if (sfFilebasePluginUtil::isAbsolutePathname($filename)) {
                 $filename = new sfFilebasePluginFile($filename, $this->filebase);
             } else {
                 $filename = new sfFilebasePluginFile($this->getPathname() . '/' . $filename, $this->filebase);
             }
         } else {
             $filename = $this;
         }
     }
     if ($filename instanceof sfFilebasePluginFile) {
         // returns only true if file exists, so beware of that
         if ($filename->isLink()) {
             throw new sfFilebasePluginException(sprintf('Error retrieving link %s: Link handling is not yet implemented', $filename->getPathname()));
             //return new sfFilebasePluginLink($filename->getPathname());
         } elseif ($filename->isDir()) {
             $filename = new sfFilebasePluginDirectory($filename->getPathname(), $this->filebase);
         } elseif ($this->filebase->getIsSupportedImage($filename)) {
             $filename = new sfFilebasePluginImage($filename->getPathname(), $this->filebase);
         }
         return $filename;
     }
     throw new sfFilebasePluginException(sprintf('File %s must be of type [string] or instanceof FilebaseFile', $filename));
 }
 $t->ok($width = $i1->getWidth(), 'sfFilebasePluginImage::getWidth() returned ' . $width);
 $t->ok($height = $i1->getHeight(), 'sfFilebasePluginImage::getHeight() returned ' . $height);
 $t->ok($mime = $i1->getMimeType(), 'sfFilebasePluginImage::getMimeType() returned ' . $mime);
 $t->diag('Check the sfImageTransformPlugin mixins');
 $t->isa_ok($i2 = $i1->copy('test.png'), 'sfFilebasePluginImage', 'sfFilebasePluginImage::copy() Copying of the image was successful');
 $t->isa_ok($i2->thumbnail(10, 10), 'sfFilebasePluginImage', 'Image transform (thumbnail) successful, assuming all transforms work.');
 $t->isa_ok($i2->save(), 'sfFilebasePluginImage', 'Thumbnail successfully saved');
 $t->ok(strlen($str = $i2->getBinaryString()) > 0, "The resulting image stream: \r\n" . $str);
 ## TEST THE UTILS
 $t->diag('sfFilebasePluginUtil::isAbsolutePathname()');
 $t->ok(sfFilebasePluginUtil::isAbsolutePathname('/hanswurst'));
 $t->ok(sfFilebasePluginUtil::isAbsolutePathname('/hanswurst/kaese'));
 $t->ok(sfFilebasePluginUtil::isAbsolutePathname('c:/hanswurst/kaese'));
 $t->ok(sfFilebasePluginUtil::isAbsolutePathname('c:/hanswurst'));
 $t->ok(sfFilebasePluginUtil::isAbsolutePathname('c:\\hanswurst\\kaese'));
 $t->ok(sfFilebasePluginUtil::isAbsolutePathname('c:\\hanswurst\\kaese'));
 $t->diag('sfFilebasePluginUtil::realpath()');
 $t->ok($p = sfFilebasePluginUtil::realpath('/hanswurst'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('/hanswurst/kaese'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('c:/hanswurst/kaese'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('c:/hanswurst'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('c:\\hanswurst\\kaese'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('c:\\hanswurst\\kaese'), $p);
 $t->ok(!($p = sfFilebasePluginUtil::realpath('c:\\..\\hanssimaus\\hanswurst\\kaese')), 'false');
 $t->ok($p = sfFilebasePluginUtil::realpath('c:\\hanssimaus\\hanswurst\\..\\kaese'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('c:\\hanssimaus\\hanswurst\\würstelchen\\..\\..\\..\\kaese\\..'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('/hanswurst/kaese/../'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('hanswurst/kaese/../naseweis'), $p);
 $t->ok($p = sfFilebasePluginUtil::realpath('hanswurst/../kaese/../naseweis'), $p);
 # DO THE DOCTRINE BEHAVIOUR TEST. USE THIS ONLY IF THE MODEL IS GENERATED
 if (class_exists('testerer')) {
 /**
  * Saves the uploaded file.
  *
  * This method can throw exceptions if there is a problem when saving the file.
  *
  * If you don't pass a file name, it will be generated by the generateFilename method.
  * This will only work if you have passed a path when initializing this instance.
  *
  * @param  string $file      The file path to save the file
  * @param  int    $fileMode  The octal mode to use for the new file
  * @param  bool   $create    Indicates that we should make the directory before moving the file
  * @param  int    $dirMode   The octal mode to use when creating the directory
  *
  * @return string The filename without the $this->path prefix
  *
  * @throws Exception
  */
 public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777)
 {
     $filebase = null;
     if ($file === null) {
         if ($this->originalName === null) {
             $file = $this->generateFilename();
         } else {
             $file = $this->originalName;
         }
     }
     // Check if $file contains an absolute pathname
     if (sfFilebasePluginUtil::isAbsolutePathname($file)) {
         $fb = sfFilebasePlugin::getInstance();
         $f = $fb->getFilebaseFile($file);
         $filebase = sfFilebasePlugin::getInstance($f->getPath(), null, $create);
     } else {
         if ($this->path === null) {
             $filebase = sfFilebasePlugin::getInstance(null, null, $create);
         } else {
             $filebase = sfFilebasePlugin::getInstance($this->path, null, $create);
         }
     }
     $file = $filebase->getFilebaseFile($file);
     // copy the temp file to the destination file
     $f = $filebase->copyFile($this->getTempName(), $file->getPathname());
     // chmod our file
     $file->chmod($fileMode);
     $this->savedName = $file->getPathname();
     return $file;
 }