Changes base name of file without extension (or base name of directory).
public changeBasename ( string $basename ) : |
||
$basename | string | |
Результат |
public function testChangeBasename() { $srcFileInfo = new FileInfo(__FILE__); $dstFileInfo = $srcFileInfo->changeBasename('/index/'); $this->assertEquals('index', $dstFileInfo->getBasename()); $this->assertNotSame($srcFileInfo, $dstFileInfo); }
/** * @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(); }