当前位置: 首页>>代码示例>>PHP>>正文


PHP Filesystem::createTemporaryDirectory方法代码示例

本文整理汇总了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();
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:45,代码来源:PhutilInteractiveEditor.php

示例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, '');
 }
开发者ID:rmoorman,项目名称:libphutil,代码行数:10,代码来源:TempFile.php

示例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, '');
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:21,代码来源:TempFile.php

示例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));
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:17,代码来源:PhutilKeyValueCacheTestCase.php

示例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);
 }
开发者ID:chaozhang80,项目名称:tool-package,代码行数:41,代码来源:ArcanistBundle.php

示例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;
 }
开发者ID:lewisf,项目名称:arcanist,代码行数:23,代码来源:ArcanistMercurialAPI.php

示例7: newEmptyFixture

 public static function newEmptyFixture()
 {
     $obj = new PhutilDirectoryFixture();
     $obj->path = Filesystem::createTemporaryDirectory();
     return $obj;
 }
开发者ID:chaozhang80,项目名称:tool-package,代码行数:6,代码来源:PhutilDirectoryFixture.php


注:本文中的Filesystem::createTemporaryDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。