本文整理汇总了PHP中Filesystem::createTemporaryDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::createTemporaryDirectory方法的具体用法?PHP Filesystem::createTemporaryDirectory怎么用?PHP Filesystem::createTemporaryDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::createTemporaryDirectory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editInteractively
/**
* Launch an editor and edit the content. The edited content will be
* returned.
*
* @return string Edited content.
* @throws Exception The editor exited abnormally or something untoward
* occurred.
*
* @task edit
*/
public function editInteractively()
{
$name = $this->getName();
$content = $this->getContent();
if (phutil_is_windows()) {
$content = str_replace("\n", "\r\n", $content);
}
$tmp = Filesystem::createTemporaryDirectory('edit.');
$path = $tmp . DIRECTORY_SEPARATOR . $name;
try {
Filesystem::writeFile($path, $content);
} catch (Exception $ex) {
Filesystem::remove($tmp);
throw $ex;
}
$editor = $this->getEditor();
$offset = $this->getLineOffset();
$err = $this->invokeEditor($editor, $path, $offset);
if ($err) {
Filesystem::remove($tmp);
throw new Exception("Editor exited with an error code (#{$err}).");
}
try {
$result = Filesystem::readFile($path);
Filesystem::remove($tmp);
} catch (Exception $ex) {
Filesystem::remove($tmp);
throw $ex;
}
if (phutil_is_windows()) {
$result = str_replace("\r\n", "\n", $result);
}
$this->setContent($result);
return $this->getContent();
}
示例2: __construct
public function __construct($filename = null, $dir = null)
{
$this->dir = Filesystem::createTemporaryDirectory();
if ($filename === null) {
$this->file = tempnam($this->dir, getmypid() . '-');
} else {
$this->file = $this->dir . '/' . $filename;
}
Filesystem::writeFile($this, '');
}
示例3: __construct
/**
* Create a new temporary file.
*
* @param string? Filename hint. This is useful if you intend to edit the
* file with an interactive editor, so the user's editor shows
* "commit-message" instead of "p3810hf-1z9b89bas".
* @task create
*/
public function __construct($filename = null)
{
$this->dir = Filesystem::createTemporaryDirectory();
if ($filename === null) {
$this->file = tempnam($this->dir, getmypid() . '-');
} else {
$this->file = $this->dir . '/' . $filename;
}
// If we fatal (e.g., call a method on NULL), destructors are not called.
// Make sure our destructor is invoked.
register_shutdown_function(array($this, '__destruct'));
Filesystem::writeFile($this, '');
}
示例4: testDirectoryCacheSpecialDirectoryRules
public function testDirectoryCacheSpecialDirectoryRules()
{
$cache = new PhutilDirectoryKeyValueCache();
$dir = Filesystem::createTemporaryDirectory();
$dir = $dir . '/dircache/';
$cache->setCacheDirectory($dir);
$cache->setKey('a', 1);
$this->assertEqual(true, Filesystem::pathExists($dir . '/a.cache'));
$cache->setKey('a/b', 1);
$this->assertEqual(true, Filesystem::pathExists($dir . '/a/'));
$this->assertEqual(true, Filesystem::pathExists($dir . '/a/b.cache'));
$cache->deleteKey('a/b');
$this->assertEqual(false, Filesystem::pathExists($dir . '/a/'));
$this->assertEqual(false, Filesystem::pathExists($dir . '/a/b.cache'));
$cache->destroyCache();
$this->assertEqual(false, Filesystem::pathExists($dir));
}
示例5: writeToDisk
public function writeToDisk($path)
{
$changes = $this->getChanges();
$change_list = array();
foreach ($changes as $change) {
$change_list[] = $change->toDictionary();
}
$hunks = array();
foreach ($change_list as $change_key => $change) {
foreach ($change['hunks'] as $key => $hunk) {
$hunks[] = $hunk['corpus'];
$change_list[$change_key]['hunks'][$key]['corpus'] = count($hunks) - 1;
}
}
$blobs = array();
foreach ($change_list as $change) {
if (!empty($change['metadata']['old:binary-phid'])) {
$blobs[$change['metadata']['old:binary-phid']] = null;
}
if (!empty($change['metadata']['new:binary-phid'])) {
$blobs[$change['metadata']['new:binary-phid']] = null;
}
}
foreach ($blobs as $phid => $null) {
$blobs[$phid] = $this->getBlob($phid);
}
$meta_info = array('version' => 5, 'projectName' => $this->getProjectID(), 'baseRevision' => $this->getBaseRevision(), 'revisionID' => $this->getRevisionID(), 'encoding' => $this->getEncoding(), 'authorName' => $this->getAuthorName(), 'authorEmail' => $this->getAuthorEmail());
$dir = Filesystem::createTemporaryDirectory();
Filesystem::createDirectory($dir . '/hunks');
Filesystem::createDirectory($dir . '/blobs');
Filesystem::writeFile($dir . '/changes.json', json_encode($change_list));
Filesystem::writeFile($dir . '/meta.json', json_encode($meta_info));
foreach ($hunks as $key => $hunk) {
Filesystem::writeFile($dir . '/hunks/' . $key, $hunk);
}
foreach ($blobs as $key => $blob) {
Filesystem::writeFile($dir . '/blobs/' . $key, $blob);
}
execx('(cd %s; tar -czf %s *)', $dir, Filesystem::resolvePath($path));
Filesystem::remove($dir);
}
示例6: getBulkFileDataAtRevision
private function getBulkFileDataAtRevision($paths, $revision)
{
// Calling 'hg cat' on each file individually is slow (1 second per file
// on a large repo) because mercurial has to decompress and parse the
// entire manifest every time. Do it in one large batch instead.
// hg cat will write the file data to files in a temp directory
$tmpdir = Filesystem::createTemporaryDirectory();
// Mercurial doesn't create the directories for us :(
foreach ($paths as $path) {
$tmppath = $tmpdir . '/' . $path;
Filesystem::createDirectory(dirname($tmppath), 0755, true);
}
list($err, $stdout) = $this->execManualLocal('cat --rev %s --output %s -- %C', $revision, $tmpdir . '/%p', implode(' ', $paths));
$filedata = array();
foreach ($paths as $path) {
$tmppath = $tmpdir . '/' . $path;
if (Filesystem::pathExists($tmppath)) {
$filedata[$path] = Filesystem::readFile($tmppath);
}
}
Filesystem::remove($tmpdir);
return $filedata;
}
示例7: newEmptyFixture
public static function newEmptyFixture()
{
$obj = new PhutilDirectoryFixture();
$obj->path = Filesystem::createTemporaryDirectory();
return $obj;
}