本文整理汇总了PHP中League\Flysystem\FilesystemInterface::write方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::write方法的具体用法?PHP FilesystemInterface::write怎么用?PHP FilesystemInterface::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadImagePreview
public function uploadImagePreview(int $themeId, string $path) : string
{
$theme = $this->getThemeById($themeId);
$dir = $theme->getId();
$name = sprintf('%s.png', GenerateRandomString::gen(self::GENERATE_FILENAME_LENGTH));
$newPath = sprintf('%s/%s', $dir, $name);
if ($this->fileSystem->has($dir)) {
$this->fileSystem->deleteDir($dir);
}
$this->fileSystem->write($newPath, file_get_contents($path));
$theme->setPreview($newPath);
$this->themeRepository->saveTheme($theme);
return $theme->getPreview();
}
示例2: uploadContents
/**
* Uploads raw contents to the service.
*
* @param string $contents
* @return array The meta of the file.
*/
public function uploadContents($name, $contents)
{
$this->filesystem->write($name, $contents);
$meta = $this->filesystem->getMetadata($name);
$urlGenerator = app('Flarum\\Forum\\UrlGenerator');
if (empty($this->settings->get('flagrow.image-upload.cdnUrl'))) {
// if there is no cdnUrl
$meta['url'] = $urlGenerator->toPath('assets/images/' . $name);
} else {
// if there is
$meta['url'] = $this->settings->get('flagrow.image-upload.cdnUrl') . 'assets/images/' . $name;
}
return $meta;
}
示例3: makeImage
/**
* Generate manipulated image.
* @param string $path Image path.
* @param array $params Image manipulation params.
* @return string Cache path.
* @throws FileNotFoundException
* @throws FilesystemException
*/
public function makeImage($path, array $params)
{
$sourcePath = $this->getSourcePath($path);
$cachedPath = $this->getCachePath($path, $params);
if ($this->cacheFileExists($path, $params) === true) {
return $cachedPath;
}
if ($this->sourceFileExists($path) === false) {
throw new FileNotFoundException('Could not find the image `' . $sourcePath . '`.');
}
$source = $this->source->read($sourcePath);
if ($source === false) {
throw new FilesystemException('Could not read the image `' . $sourcePath . '`.');
}
// We need to write the image to the local disk before
// doing any manipulations. This is because EXIF data
// can only be read from an actual file.
$tmp = tempnam(sys_get_temp_dir(), 'Glide');
if (file_put_contents($tmp, $source) === false) {
throw new FilesystemException('Unable to write temp file for `' . $sourcePath . '`.');
}
try {
$write = $this->cache->write($cachedPath, $this->api->run($tmp, $this->getAllParams($params)));
if ($write === false) {
throw new FilesystemException('Could not write the image `' . $cachedPath . '`.');
}
} catch (FileExistsException $exception) {
// This edge case occurs when the target already exists
// because it's currently be written to disk in another
// request. It's best to just fail silently.
}
unlink($tmp);
return $cachedPath;
}
示例4: write
/**
* @param ConfigInterface $config
*
* @return bool
*/
public function write(ConfigInterface $config)
{
$fileName = $config->getFileName() ?: Config::CONFIG_FILE_NAME;
$array = $config->getCleanArray();
$contents = Yaml::dump($array);
return $this->projectFileSystem->write($fileName, $contents);
}
示例5: handle
/**
* Handles the command execution.
*
* @param UploadImage $command
* @return null|string
*/
public function handle(UploadImage $command)
{
if ($command->postId) {
// load the Post for this image
$post = $this->posts->findOrFail($command->postId, $command->actor);
} else {
$post = null;
}
// todo check rights
// todo validate file
$image = new Image();
$image->user_id = $command->actor->id;
$image->upload_method = 'local';
if ($post) {
$image->post_id = $post->id;
}
$this->events->fire(new ImageWillBeSaved($post, $command->actor, $image, $command->file));
$file_name = sprintf('%d-%d-%s.jpg', $post ? $post->id : 0, $command->actor->id, str_random());
if (!$this->uploadDir->write($file_name, $command->file)) {
// todo should throw error
return null;
}
$appPath = parse_url($this->app->url(), PHP_URL_PATH);
$image->file_name = sprintf('%s/assets/images/%s', $appPath, $file_name);
$image->created_at = Carbon::now();
$image->save();
return $image;
}
示例6: _mkfile
/**
* Create file and return it's path or false on failed
*
* @param string $path parent dir path
* @param string $name new file name
* @return string|bool
**/
protected function _mkfile($path, $name)
{
$path = $this->_joinPath($path, $name);
if ($this->fs->write($path, '')) {
return $path;
}
return false;
}
示例7: write
/**
* Write settings content of a namespace
*
* @param string $namespace
* @param array $data
* @return void
*/
protected function write($namespace, array $data)
{
$file = $this->adapter->getFileName($namespace);
$contents = $this->adapter->prepareForWriting($data);
if (!$this->fileSystem->has($file)) {
$this->fileSystem->write($file, $contents);
}
$this->fileSystem->update($file, $contents);
}
示例8: writeSitemap
/**
* Writes the given sitemap to the filesystem. The filename pattern is:
* {MD5_Hash}.{Class_Name}.{Index}.xml
* @param string $groupName
* @param AbstractSitemap $sitemap
* @return string The filename of the sitemap written
*/
protected function writeSitemap($groupName, AbstractSitemap $sitemap)
{
static $index = 0;
$className = (new \ReflectionClass($sitemap))->getShortName();
$fileName = "{$groupName}.{$className}.{$index}.xml";
$this->filesystem->write($fileName, $sitemap->toString());
array_push($this->filesCreated, $fileName);
$index++;
return $fileName;
}
示例9: create
/**
* Create a new file.
*
* @param string $path
* @param string $contents
* @param string $visibility
* @throws IoWriteException
*/
public function create($path, $contents = '', $visibility = self::VISIBILITY_DEFAULT)
{
try {
$this->fs->write($path, $contents, $this->prepareConfig($visibility));
} catch (Error $ex) {
throw new IoWriteException("File {$path} could not be created.", $ex);
} catch (Exception $ex) {
throw new IoWriteException("File {$path} could not be created.", $ex);
}
}
示例10: uploadAttachment
public function uploadAttachment(string $tmpFile, string $desiredFileName) : Attachment
{
$desiredFileName = FileNameFilter::filter($desiredFileName);
$attachmentType = $this->factoryFileAttachmentType($tmpFile);
if ($attachmentType instanceof FileAttachmentType) {
$this->validateFileSize($tmpFile, $attachmentType);
}
$subDirectory = join('/', str_split(GenerateRandomString::gen(12), 2));
$storagePath = $subDirectory . '/' . $desiredFileName;
$publicPath = sprintf('%s/%s/%s', $this->wwwDir, $subDirectory, $desiredFileName);
$finfo = new \finfo(FILEINFO_MIME);
$content = file_get_contents($tmpFile);
$contentType = $finfo->buffer($content);
if ($this->fileSystem->write($storagePath, $content) === false) {
throw new \Exception('Failed to copy uploaded file');
}
$result = new Result($publicPath, $content, $contentType);
$source = new LocalSource($publicPath, $storagePath);
return $this->linkAttachment($publicPath, $subDirectory, $desiredFileName, $result, $source);
}
示例11: __construct
/**
* @param FilesystemInterface $filesystem
* @param string $fileName
*
* @throws StorageException
*/
public function __construct(FilesystemInterface $filesystem, $fileName = self::DEFAULT_FILENAME)
{
if (!$filesystem->has($fileName)) {
$filesystem->write($fileName, '');
}
$handler = $filesystem->get($fileName);
if (!$handler->isFile()) {
throw new StorageException(sprintf('Expected path "%s" to be a file but its a "%s".', $handler->getPath(), $handler->getType()));
}
$this->file = $handler;
}
示例12: backupAndUpdate
private function backupAndUpdate($path, $content)
{
if ($this->enableBackup) {
$oldContent = $this->master->read($path);
if ($oldContent !== false) {
if ($this->backup->has($path)) {
$this->backup->update($path, $oldContent);
} else {
$this->backup->write($path, $oldContent);
}
}
}
$this->master->update($path, $content);
}
示例13: makeImage
/**
* Generate manipulated image.
* @return Request The request object.
* @throws NotFoundException
*/
public function makeImage()
{
$request = $this->resolveRequestObject(func_get_args());
if ($this->cacheFileExists($request) === true) {
return $request;
}
if ($this->sourceFileExists($request) === false) {
throw new NotFoundException('Could not find the image `' . $this->getSourcePath($request) . '`.');
}
$source = $this->source->read($this->getSourcePath($request));
if ($source === false) {
throw new FilesystemException('Could not read the image `' . $this->getSourcePath($request) . '`.');
}
try {
$write = $this->cache->write($this->getCachePath($request), $this->api->run($request, $source));
} catch (FileExistsException $exception) {
// Cache file failed to write. Fail silently.
return $request;
}
if ($write === false) {
throw new FilesystemException('Could not write the image `' . $this->getCachePath($request) . '`.');
}
return $request;
}
示例14: write
/**
* Write a new file.
*
* @param string $path The path of the new file.
* @param string $contents The file contents.
* @param array $config An optional configuration array.
*
* @throws FileExistsException
*
* @return bool True on success, false on failure.
*/
public function write($path, $contents, array $config = [])
{
return $this->fileSystem->write($path, $contents, $config);
}
示例15: writeContent
/**
* @param $path
* @param $content
* @return mixed
*/
public function writeContent($path, $content)
{
$result = $this->filesystem->write($path, $content);
return $result;
}