Author: Victor Bocharsky (bocharsky.bw@gmail.com)
Inheritance: extends SplFileInfo
 /**
  * {@inheritdoc}
  */
 public function provideName(FileInfo $srcFileInfo)
 {
     $datetime = \DateTime::createFromFormat('U.u', microtime(true));
     $pathSuffix = FileInfo::purifyPath($datetime->format($this->dirFormat));
     $dstFileInfo = $srcFileInfo->changePath($srcFileInfo->getPath() . FileInfo::SEPARATOR_DIRECTORY . $pathSuffix)->changeBasename($datetime->format($this->fileFormat));
     return $dstFileInfo;
 }
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException If source file does not exist
  */
 public function provideName(FileInfo $srcFileInfo)
 {
     if (!$srcFileInfo->isFile()) {
         throw new \InvalidArgumentException(sprintf('The source file does not exist on "%s" specified path.', $srcFileInfo->toString()));
     }
     $hash = hash_file($this->algorithm, $srcFileInfo->toString());
     $dstFileInfo = $this->provideNameByHash($srcFileInfo, $hash);
     return $dstFileInfo;
 }
 /**
  * {@inheritdoc}
  */
 public function provideName(FileInfo $srcFileInfo)
 {
     $dstFileInfo = $srcFileInfo;
     $strategies = $this->isReverseMode() ? array_reverse($this->strategies, true) : $this->strategies;
     foreach ($strategies as $strategy) {
         $filename = (string) $strategy->provideName($dstFileInfo);
         $dstFileInfo = new FileInfo($filename);
     }
     return $dstFileInfo->toString();
 }
 /**
  * @param FileInfo $srcFileInfo
  * @param string $hash
  *
  * @return FileInfo
  */
 public function provideNameByHash(FileInfo $srcFileInfo, $hash)
 {
     $pathSuffixParts = array();
     for ($i = 0; $i < $this->partCount; $i++) {
         $pathSuffixParts[] = substr($hash, $i * $this->partLength, $this->partLength);
     }
     $name = substr($hash, $i * $this->partLength);
     $pathSuffix = implode(FileInfo::SEPARATOR_DIRECTORY, $pathSuffixParts);
     $dstFileInfo = $srcFileInfo->changeBasename($name)->changePath($srcFileInfo->getPath() . FileInfo::SEPARATOR_DIRECTORY . $pathSuffix);
     return $dstFileInfo;
 }
 /**
  * {@inheritdoc}
  */
 public function provideName(FileInfo $srcFileInfo)
 {
     $string = $this->generateUniqueString();
     $hash = hash($this->algorithm, $string);
     $pathSuffixParts = array();
     for ($i = 0; $i < $this->partCount; $i++) {
         $pathSuffixParts[] = substr($hash, $i * $this->partLength, $this->partLength);
     }
     $name = substr($hash, $i * $this->partLength);
     $pathSuffix = implode(FileInfo::SEPARATOR_DIRECTORY, $pathSuffixParts);
     $dstFileInfo = $srcFileInfo->changeBasename($name)->changePath($srcFileInfo->getPath() . FileInfo::SEPARATOR_DIRECTORY . $pathSuffix);
     return $dstFileInfo->toString();
 }
Example #6
0
 public function testToString()
 {
     $fileInfo = new FileInfo(__FILE__);
     $this->assertEquals(__FILE__, $fileInfo->toString());
 }