本文整理汇总了PHP中Filesystem::writeFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::writeFile方法的具体用法?PHP Filesystem::writeFile怎么用?PHP Filesystem::writeFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::writeFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveConfig
private function saveConfig()
{
$config = $this->getSource()->getAllKeys();
$json = new PhutilJSON();
$data = $json->encodeFormatted($config);
Filesystem::writeFile($this->getConfigPath(), $data);
}
示例2: setCABundleFromString
/**
* Create a temp file containing an SSL cert, and use it for this session.
*
* This allows us to do host-specific SSL certificates in whatever client
* is using libphutil. e.g. in Arcanist, you could add an "ssl_cert" key
* to a specific host in ~/.arcrc and use that.
*
* cURL needs this to be a file, it doesn't seem to be able to handle a string
* which contains the cert. So we make a temporary file and store it there.
*
* @param string The multi-line, possibly lengthy, SSL certificate to use.
* @return this
*/
public function setCABundleFromString($certificate)
{
$temp = new TempFile();
Filesystem::writeFile($temp, $certificate);
$this->cabundle = $temp;
return $this;
}
示例3: __phutil_signal_handler__
function __phutil_signal_handler__($signal_number)
{
$e = new Exception();
$pid = getmypid();
// Some phabricator daemons may not be attached to a terminal.
Filesystem::writeFile(sys_get_temp_dir() . '/phabricator_backtrace_' . $pid, $e->getTraceAsString());
}
示例4: 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;
}
示例5: handleSignal
public function handleSignal(PhutilSignalRouter $router, $signo)
{
$e = new Exception();
$pid = getmypid();
// Some Phabricator daemons may not be attached to a terminal.
Filesystem::writeFile(sys_get_temp_dir() . '/phabricator_backtrace_' . $pid, $e->getTraceAsString());
}
示例6: 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();
}
示例7: executeChecks
protected function executeChecks()
{
if (phutil_is_windows()) {
$bin_name = 'where';
} else {
$bin_name = 'which';
}
if (!Filesystem::binaryExists($bin_name)) {
$message = pht("Without '%s', Phabricator can not test for the availability " . "of other binaries.", $bin_name);
$this->raiseWarning($bin_name, $message);
// We need to return here if we can't find the 'which' / 'where' binary
// because the other tests won't be valid.
return;
}
if (!Filesystem::binaryExists('diff')) {
$message = pht("Without 'diff', Phabricator will not be able to generate or render " . "diffs in multiple applications.");
$this->raiseWarning('diff', $message);
} else {
$tmp_a = new TempFile();
$tmp_b = new TempFile();
$tmp_c = new TempFile();
Filesystem::writeFile($tmp_a, 'A');
Filesystem::writeFile($tmp_b, 'A');
Filesystem::writeFile($tmp_c, 'B');
list($err) = exec_manual('diff %s %s', $tmp_a, $tmp_b);
if ($err) {
$this->newIssue('bin.diff.same')->setName(pht("Unexpected 'diff' Behavior"))->setMessage(pht("The 'diff' binary on this system has unexpected behavior: " . "it was expected to exit without an error code when passed " . "identical files, but exited with code %d.", $err));
}
list($err) = exec_manual('diff %s %s', $tmp_a, $tmp_c);
if (!$err) {
$this->newIssue('bin.diff.diff')->setName(pht("Unexpected 'diff' Behavior"))->setMessage(pht("The 'diff' binary on this system has unexpected behavior: " . "it was expected to exit with a nonzero error code when passed " . "differing files, but did not."));
}
}
$table = new PhabricatorRepository();
$vcses = queryfx_all($table->establishConnection('r'), 'SELECT DISTINCT versionControlSystem FROM %T', $table->getTableName());
foreach ($vcses as $vcs) {
switch ($vcs['versionControlSystem']) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$binary = 'git';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$binary = 'svn';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$binary = 'hg';
break;
default:
$binary = null;
break;
}
if (!$binary) {
continue;
}
if (!Filesystem::binaryExists($binary)) {
$message = pht('You have at least one repository configured which uses this ' . 'version control system. It will not work without the VCS binary.');
$this->raiseWarning($binary, $message);
}
}
}
示例8: writeFile
public function writeFile($path, $data)
{
$source = new TempFile();
Filesystem::writeFile($source, $data);
$future = $this->getExecFuture($path);
$future->write(csprintf('put %s %s', $source, $path));
$future->resolvex();
}
示例9: generateRawDiffFromFileContent
/**
* Generate a raw diff from two raw files. This is a lower-level API than
* @{method:generateChangesetFromFileContent}, but may be useful if you need
* to use a custom parser configuration, as with Diffusion.
*
* @param string Entire previous file content.
* @param string Entire current file content.
* @return string Raw diff between the two files.
* @task diff
*/
public function generateRawDiffFromFileContent($old, $new)
{
$options = array();
if ($this->ignoreWhitespace) {
$options[] = '-bw';
}
// Generate diffs with full context.
$options[] = '-U65535';
$old_name = nonempty($this->oldName, '/dev/universe') . ' 9999-99-99';
$new_name = nonempty($this->newName, '/dev/universe') . ' 9999-99-99';
$options[] = '-L';
$options[] = $old_name;
$options[] = '-L';
$options[] = $new_name;
$old_tmp = new TempFile();
$new_tmp = new TempFile();
Filesystem::writeFile($old_tmp, $old);
Filesystem::writeFile($new_tmp, $new);
list($err, $diff) = exec_manual('diff %Ls %s %s', $options, $old_tmp, $new_tmp);
if (!$err) {
// This indicates that the two files are the same (or, possibly, the
// same modulo whitespace differences, which is why we can't do this
// check trivially before running `diff`). Build a synthetic, changeless
// diff so that we can still render the raw, unchanged file instead of
// being forced to just say "this file didn't change" since we don't have
// the content.
$entire_file = explode("\n", $old);
foreach ($entire_file as $k => $line) {
$entire_file[$k] = ' ' . $line;
}
$len = count($entire_file);
$entire_file = implode("\n", $entire_file);
// TODO: If both files were identical but missing newlines, we probably
// get this wrong. Unclear if it ever matters.
// This is a bit hacky but the diff parser can handle it.
$diff = "--- {$old_name}\n" . "+++ {$new_name}\n" . "@@ -1,{$len} +1,{$len} @@\n" . $entire_file . "\n";
} else {
if ($this->ignoreWhitespace) {
// Under "-bw", `diff` is inconsistent about emitting "\ No newline
// at end of file". For instance, a long file with a change in the
// middle will emit a contextless "\ No newline..." at the end if a
// newline is removed, but not if one is added. A file with a change
// at the end will emit the "old" "\ No newline..." block only, even
// if the newline was not removed. Since we're ostensibly ignoring
// whitespace changes, just drop these lines if they appear anywhere
// in the diff.
$lines = explode("\n", $diff);
foreach ($lines as $key => $line) {
if (isset($line[0]) && $line[0] == '\\') {
unset($lines[$key]);
}
}
$diff = implode("\n", $lines);
}
}
return $diff;
}
示例10: __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, '');
}
示例11: writeAndRead
private function writeAndRead($write, $read, $delimiter = "\n")
{
$tmp = new TempFile();
Filesystem::writeFile($tmp, $write);
$lines = array();
$iterator = id(new LinesOfALargeFile($tmp))->setDelimiter($delimiter);
foreach ($iterator as $n => $line) {
$lines[$n - 1] = $line;
}
$this->assertEqual($read, $lines, "Write: " . phutil_utf8_shorten($write, 32));
}
示例12: writeAndRead
private function writeAndRead($write, $read, $delimiter = "\n")
{
$tmp = new TempFile();
Filesystem::writeFile($tmp, $write);
$lines = array();
$iterator = id(new LinesOfALargeFile($tmp))->setDelimiter($delimiter);
foreach ($iterator as $n => $line) {
$lines[$n - 1] = $line;
}
$this->assertEqual($read, $lines, 'Write: ' . id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(32)->truncateString($write));
}
示例13: renderDifferences
public static function renderDifferences($old, $new, $context_lines = 3, $diff_options = "-L 'Old Value' -L 'New Value'")
{
if ((string) $old === (string) $new) {
$new .= "\n(Old and new values are identical.)";
}
$file_old = new TempFile();
$file_new = new TempFile();
Filesystem::writeFile($file_old, (string) $old . "\n");
Filesystem::writeFile($file_new, (string) $new . "\n");
list($err, $stdout) = exec_manual('diff %C -U %s %s %s', $diff_options, $context_lines, $file_old, $file_new);
return $stdout;
}
示例14: __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, '');
}
示例15: execute
public function execute(PhutilArgumentParser $args)
{
$styles = PhabricatorSyntaxStyle::getAllStyles();
$root = dirname(phutil_get_library_root('phabricator'));
$root = $root . '/webroot/rsrc/css/syntax/';
foreach ($styles as $key => $style) {
$content = $this->generateCSS($style);
$path = $root . '/syntax-' . $key . '.css';
Filesystem::writeFile($path, $content);
echo tsprintf("%s\n", pht('Rebuilt "%s" syntax CSS.', basename($path)));
}
return 0;
}