Example #1
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;
 }
Example #2
0
 public function testGetBasename()
 {
     $file = new \r8\FileSys\File();
     $this->assertNull($file->getBasename());
     $file->setExt("php");
     $this->assertNull($file->getBasename());
     $file->setFilename("example");
     $this->assertSame("example.php", $file->getBasename());
     $file->clearExt();
     $this->assertSame("example", $file->getBasename());
     $file->clearFilename();
     $this->assertNull($file->getBasename());
 }