Exemplo n.º 1
0
 public function testGetPath()
 {
     $file = new \r8\FileSys\File();
     $this->assertNull($file->getPath());
     $file->setDir("dir/to");
     $this->assertSame("dir/to/", $file->getPath());
     $file->setDir("/dir/to/");
     $this->assertSame("/dir/to/", $file->getPath());
     $file->setExt("php");
     $this->assertSame("/dir/to/", $file->getPath());
     $file->setFilename("Example");
     $this->assertSame("/dir/to/Example.php", $file->getPath());
     $file->clearExt();
     $this->assertSame("/dir/to/Example", $file->getPath());
     $file->clearDir();
     $this->assertSame("Example", $file->getPath());
     $file->setExt("php");
     $this->assertSame("Example.php", $file->getPath());
     $file->clearFilename()->clearExt();
     $this->assertNull($file->getPath());
 }
Exemplo n.º 2
0
 /**
  * Returns the name of a file that doesn't yet exist in this directory
  *
  * Without a prefix or extension, this will create a filename 15 characters
  * long. If you change the $moreEntropy flag to true, the result will be
  * 25 characters
  *
  * @param String $prefix A prefix to attach to the file name
  * @param String $extension The extension the file should have
  * @param Boolean $moreEntropy Increases the length of the generated filename
  * @return \r8\FileSys\File
  */
 public function getUniqueFile($prefix = null, $extension = null, $moreEntropy = FALSE)
 {
     if (!$this->dirExists()) {
         throw new \r8\Exception\Variable("Dir", "No directory has been set for this instance");
     }
     $file = new \r8\FileSys\File();
     $file->setDir($this->getRawDir());
     if (!\r8\isVague($extension)) {
         $file->setExt($extension);
     }
     $prefix = \r8\isVague($prefix) ? null : (string) $prefix;
     $moreEntropy = (bool) $moreEntropy;
     do {
         if ($moreEntropy) {
             $uniq = md5(uniqid(null, true));
         } else {
             $uniq = substr(md5(uniqid()), 0, 15);
         }
         $file->setFileName($prefix . $uniq);
     } while ($file->exists());
     return $file;
 }