本文整理汇总了PHP中Filesystem::rename方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::rename方法的具体用法?PHP Filesystem::rename怎么用?PHP Filesystem::rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::rename方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setKeys
public function setKeys(array $keys, $ttl = null)
{
$this->validateKeys(array_keys($keys));
$this->lockCache(15);
if ($ttl) {
$ttl_epoch = time() + $ttl;
} else {
$ttl_epoch = null;
}
foreach ($keys as $key => $value) {
$dict = array('value' => $value);
if ($ttl_epoch) {
$dict['ttl'] = $ttl_epoch;
}
try {
$key_file = $this->getKeyFile($key);
$key_dir = dirname($key_file);
if (!Filesystem::pathExists($key_dir)) {
Filesystem::createDirectory($key_dir, $mask = 0755, $recursive = true);
}
$new_file = $key_file . '.new';
Filesystem::writeFile($new_file, serialize($dict));
Filesystem::rename($new_file, $key_file);
} catch (FilesystemException $ex) {
phlog($ex);
}
}
$this->unlockCache();
return $this;
}
示例2: testWrite
/**
* @dataProvider filesystemProvider
*/
public function testWrite(Filesystem $filesystem, $adapter, $cache)
{
$this->assertTrue($filesystem->write('some_file.txt', 'some content'));
$this->assertTrue($filesystem->has('some_file.txt'));
$this->assertTrue($cache->has('some_file.txt'));
$this->assertTrue($adapter->has('some_file.txt'));
$this->assertCount(1, $filesystem->listContents());
$this->assertCount(1, $cache->listContents('', false));
$this->assertCount(1, $adapter->listContents('', false));
$filesystem->rename('some_file.txt', 'other_name.txt');
$this->assertFalse($filesystem->has('some_file.txt'));
$this->assertFalse($cache->has('some_file.txt'));
$this->assertFalse($adapter->has('some_file.txt'));
$this->assertTrue($filesystem->has('other_name.txt'));
$this->assertTrue($cache->has('other_name.txt'));
$this->assertTrue($adapter->has('other_name.txt'));
$this->assertCount(1, $filesystem->listContents());
$this->assertCount(1, $cache->listContents('', false));
$this->assertCount(1, $adapter->listContents('', false));
$filesystem->delete('other_name.txt');
$this->assertFalse($filesystem->has('other_name.txt'));
$this->assertFalse($cache->has('other_name.txt'));
$this->assertFalse($adapter->has('other_name.txt'));
$this->assertCount(0, $filesystem->listContents());
$this->assertCount(0, $cache->listContents('', false));
$this->assertCount(0, $adapter->listContents('', false));
}
示例3: writePatchToDisk
public function writePatchToDisk()
{
$path = $this->lintResult->getFilePathOnDisk();
$data = $this->getModifiedFileContent();
$ii = null;
do {
$lint = $path . '.linted' . $ii++;
} while (file_exists($lint));
// Copy existing file to preserve permissions. 'chmod --reference' is not
// supported under OSX.
if (Filesystem::pathExists($path)) {
// This path may not exist if we're generating a new file.
Filesystem::copyFile($path, $lint);
}
Filesystem::writeFile($lint, $data);
try {
Filesystem::rename($lint, $path);
} catch (FilesystemException $e) {
throw new Exception(pht("Unable to overwrite path '%s', patched version was left at '%s'.", $path, $lint));
}
foreach ($this->applyMessages as $message) {
$message->didApplyPatch();
}
}
示例4: run
//.........这里部分代码省略.........
Filesystem::appendFile($tmp, $lint_result);
} else {
$console->writeOut('%s', $lint_result);
}
}
if ($apply_patches && $result->isPatchable()) {
$patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
$old_file = $result->getFilePathOnDisk();
if ($prompt_patches && !($result_all_autofix && !$prompt_autofix_patches)) {
if (!Filesystem::pathExists($old_file)) {
$old_file = '/dev/null';
}
$new_file = new TempFile();
$new = $patcher->getModifiedFileContent();
Filesystem::writeFile($new_file, $new);
// TODO: Improve the behavior here, make it more like
// difference_render().
list(, $stdout, $stderr) = exec_manual('diff -u %s %s', $old_file, $new_file);
$console->writeOut('%s', $stdout);
$console->writeErr('%s', $stderr);
$prompt = pht('Apply this patch to %s?', phutil_console_format('__%s__', $result->getPath()));
if (!$console->confirm($prompt, $default = true)) {
continue;
}
}
$patcher->writePatchToDisk();
$wrote_to_disk = true;
$file_hashes[$old_file] = md5_file($old_file);
}
}
$postamble = $renderer->renderPostamble();
if ($tmp) {
Filesystem::appendFile($tmp, $postamble);
Filesystem::rename($tmp, $this->getArgument('outfile'));
} else {
$console->writeOut('%s', $postamble);
}
if ($wrote_to_disk && $this->shouldAmendChanges) {
if ($this->shouldAmendWithoutPrompt || $this->shouldAmendAutofixesWithoutPrompt && $all_autofix) {
$console->writeOut("<bg:yellow>** %s **</bg> %s\n", pht('LINT NOTICE'), pht('Automatically amending HEAD with lint patches.'));
$amend = true;
} else {
$amend = $console->confirm(pht('Amend HEAD with lint patches?'));
}
if ($amend) {
if ($repository_api instanceof ArcanistGitAPI) {
// Add the changes to the index before amending
$repository_api->execxLocal('add -u');
}
$repository_api->amendCommit();
} else {
throw new ArcanistUsageException(pht('Sort out the lint changes that were applied to the working ' . 'copy and relint.'));
}
}
if ($this->getArgument('output') == 'json') {
// NOTE: Required by save_lint.php in Phabricator.
return 0;
}
if ($failed) {
if ($failed instanceof ArcanistNoEffectException) {
if ($renderer instanceof ArcanistNoneLintRenderer) {
return 0;
}
}
throw $failed;
}
示例5: saveCache
/**
* @task storage
*/
private function saveCache()
{
if (!$this->lock) {
throw new PhutilInvalidStateException('loadCache');
}
// We're holding a lock so we're safe to do a write to a well-known file.
// Write to the same directory as the cache so the rename won't imply a
// copy across volumes.
$new = $this->getCacheFile() . '.new';
Filesystem::writeFile($new, serialize($this->cache));
Filesystem::rename($new, $this->getCacheFile());
$this->lock->unlock();
$this->lock = null;
}