本文整理汇总了PHP中League\Flysystem\Filesystem::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::update方法的具体用法?PHP Filesystem::update怎么用?PHP Filesystem::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::update方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUpdate
public function testUpdate()
{
$path = 'path.txt';
$contents = 'contents';
$this->prophecy->has($path)->willReturn(true);
$this->prophecy->update($path, $contents, $this->config)->willReturn(compact('path', 'contents'));
$this->assertTrue($this->filesystem->update($path, $contents));
}
示例2: publish
/**
* @param string $content
* @param string $path
* @return bool
* @throws \InvalidArgumentException
* @throws \League\Flysystem\FileNotFoundException
*/
public function publish($content, $path = '')
{
if (empty($path)) {
throw new \InvalidArgumentException('Path is mandatory!');
}
$config = new Config();
try {
return $this->storage->write($path, $content, $config);
} catch (FileExistsException $e) {
return $this->storage->update($path, $content, $config);
}
}
示例3: run
public function run()
{
$log = new Stream('php://stdout');
/** @var Config $config */
$config = Di::getDefault()->getShared('config');
$expireDate = new DateTime('now', new DateTimeZone('UTC'));
$expireDate->modify('+1 month');
$baseUrl = rtrim($config->get('site')->url, '/');
$content = <<<EOL
User-agent: *
Allow: /
Sitemap: {$baseUrl}/sitemap.xml
EOL;
$adapter = new Local(dirname(dirname(__FILE__)) . '/public');
$filesystem = new Filesystem($adapter);
if ($filesystem->has('robots.txt')) {
$result = $filesystem->update('robots.txt', $content);
} else {
$result = $filesystem->write('robots.txt', $content);
}
if ($result) {
$log->info('The robots.txt was successfully updated');
} else {
$log->error('Failed to update the robots.txt file');
}
}
示例4: update
public function update($path, $contents, array $config = [])
{
if (parent::update($path, $contents, $config)) {
return $this->getAdapter()->getModel();
} else {
return false;
}
}
示例5: update
/**
* @inheritdoc
*/
public function update($path, $contents, array $config = [])
{
try {
return $this->fileSystem->update($this->getInnerPath($path), $contents, $config);
} catch (FileNotFoundException $e) {
throw $this->exceptionWrapper($e, $path);
}
}
示例6: run
public function run()
{
$log = new Stream('php://stdout');
/** @var Config $config */
$config = Di::getDefault()->getShared('config');
$expireDate = new DateTime('now', new DateTimeZone('UTC'));
$expireDate->modify('+1 day');
$sitemap = new DOMDocument("1.0", "UTF-8");
$sitemap->formatOutput = true;
$urlset = $sitemap->createElement('urlset');
$urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
$urlset->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$baseUrl = $config->get('site')->url;
$url = $sitemap->createElement('url');
$url->appendChild($sitemap->createElement('loc', $baseUrl));
$url->appendChild($sitemap->createElement('changefreq', 'daily'));
$url->appendChild($sitemap->createElement('priority', '1.0'));
$urlset->appendChild($url);
$karmaSql = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies';
$parametersPosts = ['conditions' => 'deleted != 1', 'columns' => "id, slug, modified_at, {$karmaSql} AS karma", 'order' => 'karma DESC'];
$posts = Posts::find($parametersPosts);
$parametersKarma = ['column' => $karmaSql, 'conditions' => 'deleted != 1'];
$karma = Posts::maximum($parametersKarma);
$modifiedAt = new DateTime('now', new DateTimeZone('UTC'));
foreach ($posts as $post) {
$modifiedAt->setTimestamp($post->modified_at);
$postKarma = $post->karma / ($karma + 100);
$url = $sitemap->createElement('url');
$href = trim($baseUrl, '/') . '/discussion/' . $post->id . '/' . $post->slug;
$url->appendChild($sitemap->createElement('loc', $href));
$valuePriority = $postKarma > 0.7 ? sprintf("%0.1f", $postKarma) : sprintf("%0.1f", $postKarma + 0.25);
$url->appendChild($sitemap->createElement('priority', $valuePriority));
$url->appendChild($sitemap->createElement('lastmod', $modifiedAt->format('Y-m-d\\TH:i:s\\Z')));
$urlset->appendChild($url);
}
$sitemap->appendChild($urlset);
$adapter = new Local(dirname(dirname(__FILE__)) . '/public');
$filesystem = new Filesystem($adapter);
if ($filesystem->has('sitemap.xml')) {
$result = $filesystem->update('sitemap.xml', $sitemap->saveXML() . PHP_EOL);
} else {
$result = $filesystem->write('sitemap.xml', $sitemap->saveXML() . PHP_EOL);
}
if ($result) {
$log->info('The sitemap.xml was successfully updated');
} else {
$log->error('Failed to update the sitemap.xml file');
}
}
示例7: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$dir = $input->getOption("dir");
$dir = realpath(getcwd() . "/" . ($dir ?: ""));
if (!is_dir($dir) || !is_writeable($dir)) {
$output->writeln("<error>Given directory does not exists or is not writeable</error>");
return;
}
$fs = new Filesystem(new Adapter($dir));
$files = $fs->listContents("", true);
$updates = [];
$errors = 0;
foreach ($files as $file) {
if ($file['type'] === 'dir') {
continue;
}
$content = $fs->read($file['path']);
$content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use(&$updates, &$errors, $input) {
list($prefix, $ver) = array_slice($matches, 1);
try {
$semver = new version($ver);
} catch (\Exception $e) {
$errors++;
return $prefix . $ver;
}
if ($input->getOption("major")) {
$semver->inc("major");
} elseif ($input->getOption("minor")) {
$semver->inc("minor");
} elseif ($input->getOption("patch")) {
$semver->inc("patch");
} else {
$semver->inc("patch");
}
if (!isset($updates[$ver])) {
$updates[$ver] = ["count" => 0, "ver" => $semver->getVersion()];
}
$updates[$ver]['count']++;
return $prefix . $semver->getVersion();
}, $content);
$fs->update($file['path'], $content);
}
foreach ($updates as $update => $count) {
$output->writeln("<info>{$count['count']} files have been updated from {$update} to {$count['ver']}</info>");
}
}
示例8: touch
/**
* {@inheritdoc}
*/
public function touch($key, $expire)
{
if (!$this->lock($key)) {
return false;
}
$value = $this->get($key);
if ($value === false) {
$this->unlock($key);
return false;
}
$path = $this->path($key);
$data = $this->wrap($value, $expire);
try {
$success = $this->filesystem->update($path, $data);
return $success && $this->unlock($key);
} catch (FileNotFoundException $e) {
$this->unlock($key);
return false;
}
}
示例9: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$version = $input->getArgument("version");
try {
$semver = new version($version);
} catch (\Exception $e) {
$output->writeln("<error>Given version is not valid. Please provide a semver version</error>");
return;
}
$version = $semver->getVersion();
$dir = $input->getOption("dir");
$dir = realpath(getcwd() . "/" . ($dir ?: ""));
if (!is_dir($dir) || is_writeable($dir)) {
$output->writeln("Given directory does not exists or is not writeable");
return;
}
$fs = new Filesystem(new Adapter($dir));
$files = $fs->listContents("", true);
$updates = [];
foreach ($files as $file) {
if ($file['type'] === 'dir') {
continue;
}
$content = $fs->read($file['path']);
$content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use($version, &$updates) {
list($prefix, $ver) = array_slice($matches, 1);
if (!isset($updates[$ver])) {
$updates[$ver] = 0;
}
$updates[$ver]++;
return $prefix . $version;
}, $content);
$fs->update($file['path'], $content);
}
foreach ($updates as $update => $count) {
$output->writeln("<info>{$count} files have been updated from {$update} to {$version}</info>");
}
}
示例10: update
/**
* {@inheritDoc}
*/
public function update($path, $contents, array $config = [])
{
parent::update($path, $contents, $config);
return $this->get($path);
}
示例11: update
/**
* Update an existing file.
*
* @param string $path The path of the existing file.
* @param string $contents The file contents.
* @param array $config An optional configuration array.
*
* @throws FileNotFoundException
*
* @return bool True on success, false on failure.
*/
public function update($path, $contents, array $config = [])
{
$result = parent::update($path, $contents, $config);
if ($result && ($resource = $this->get($path))) {
return $this->dispatch(new SyncFile($resource));
}
return $result;
}
示例12: krsort
}
krsort($files);
$errorlog = $sqldir . array_shift($files)[0];
}
break;
default:
$file .= 'access_log';
break;
}
// Windows is silly...
if (PHP_OS !== 'Darwin') {
$errorlog = str_replace('_log', '.log', $file);
}
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
if ($filesystem->has($errorlog)) {
$filesystem->update($errorlog, '');
}
}
if ($filesystem->has($errorlog)) {
$data = $filesystem->read($errorlog);
} else {
$data = '';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://raw.githubusercontent.com/Section214/DS3-Log-Viewer/master/log-viewer.php');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$buffer = curl_exec($ch);
curl_close($ch);
if ($buffer) {
示例13: testUpdate
/**
* 1.txt
* 2.txt.
*/
public function testUpdate()
{
$this->assertTrue($this->filesystem->update('1.txt', '456'));
}
示例14: update
/**
* @inheritdoc
*/
public function update($path, $contents, array $config = [])
{
try {
return parent::update($path, $contents, $config);
} catch (\Exception $e) {
$this->errors[] = StringHelper::replace(FileException::FILE_EXISTS, ['path' => $path]);
}
return false;
}