本文整理汇总了PHP中League\Flysystem\FilesystemInterface::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::delete方法的具体用法?PHP FilesystemInterface::delete怎么用?PHP FilesystemInterface::delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteFile
protected function deleteFile($filePath)
{
// If file is already gone somewhere, it is OK for us
if ($this->filesystem->has($filePath) && !$this->filesystem->delete($filePath)) {
throw new CommandErrorException('The file cannot be removed: ' . $filePath);
}
}
示例2: delete
public function delete($spiBinaryFileId)
{
try {
$this->filesystem->delete($spiBinaryFileId);
} catch (FlysystemNotFoundException $e) {
throw new BinaryFileNotFoundException($spiBinaryFileId, $e);
}
}
示例3: delete
/**
* Delete an item from the storage if it exists.
*
* @param string $key
*
* @return void
*/
public function delete($key)
{
try {
$this->flysystem->delete($key);
} catch (FileNotFoundException $e) {
//
}
}
示例4: delete
/**
* {@inheritdoc}
*/
public function delete($path)
{
try {
return $this->filesystem->delete($path);
} catch (FileNotFoundException $exception) {
return false;
}
}
示例5: copyFile
protected function copyFile($fromFullPath, $toFullPath, $replace = false)
{
$this->createDirectory(dirname($toFullPath));
if ($replace) {
$this->filesystem->delete($toFullPath);
}
if (!$this->filesystem->copy($fromFullPath, $toFullPath)) {
throw new CommandErrorException('File cannot be copied to the path ' . $toFullPath);
}
}
示例6: handle
public function handle(DeleteAvatarCommand $command)
{
$user = $this->users->findOrFail($command->userId);
// Make sure the current user is allowed to edit the user profile.
// This will let admins and the user themselves pass through, and
// throw an exception otherwise.
$user->assertCan($command->actor, 'edit');
$avatarPath = $user->avatar_path;
$user->changeAvatarPath(null);
event(new AvatarWillBeDeleted($user, $command));
$this->uploadDir->delete($avatarPath);
$user->save();
$this->dispatchEventsFor($user);
return $user;
}
示例7: gc
/**
* Cleanup old sessions
* @link http://php.net/manual/en/sessionhandlerinterface.gc.php
* @param int $maxlifetime <p>
* Sessions that have not updated for
* the last maxlifetime seconds will be removed.
* </p>
* @return bool <p>
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
* @since 5.4.0
*/
public function gc($maxlifetime)
{
$files = Finder::create()->in($this->path)->files()->ignoreDotFiles(true)->date('<= now - ' . $maxlifetime . ' seconds');
foreach ($files as $file) {
$this->driver->delete($file->getRealPath());
}
}
示例8:
function it_can_remove_old_backups(FilesystemInterface $filesystem)
{
$files = [['path' => '.gitignore'], ['path' => 'foo.sql'], ['path' => 'foo1.sql'], ['path' => 'foo2.sql'], ['path' => 'foo3.sql'], ['path' => 'foo4.sql'], ['path' => 'foo5.sql'], ['path' => 'foo6.sql']];
$filesystem->listFiles()->willReturn($files);
$filesystem->getTimestamp('foo.sql')->willReturn(10000);
$filesystem->getTimestamp('foo1.sql')->willReturn(500);
$filesystem->getTimestamp('foo2.sql')->willReturn(10000);
$filesystem->getTimestamp('foo3.sql')->willReturn(10000);
$filesystem->getTimestamp('foo4.sql')->willReturn(100);
$filesystem->getTimestamp('.gitignore')->willReturn(50);
$filesystem->getTimestamp('foo5.sql')->willReturn(10000);
$filesystem->getTimestamp('foo6.sql')->willReturn(10000);
$filesystem->delete('foo1.sql')->shouldBeCalled();
$filesystem->delete('foo4.sql')->shouldBeCalled();
$this->removeOldBackups(5)->shouldReturn(['foo4.sql', 'foo1.sql']);
}
示例9: push
/**
* {@inheritdoc}
*/
public function push(BackupInterface $backup)
{
$backupDirectory = $backup->getName();
if (!$this->flysystem->has($backupDirectory) && !$this->flysystem->createDir($backupDirectory)) {
throw new DestinationException(sprintf('Unable to create backup directory "%s" in flysystem destination.', $backupDirectory));
}
$removedBackupFiles = $this->getFiles($backupDirectory);
/**
* @var FileInterface $backupFile
*/
foreach ($backup->getFiles() as $backupFile) {
if (isset($removedBackupFiles[$backupFile->getRelativePath()])) {
unset($removedBackupFiles[$backupFile->getRelativePath()]);
}
$path = $backupDirectory . '/' . $backupFile->getRelativePath();
try {
if ($this->flysystem->has($path)) {
if ($backupFile->getModifiedAt() > new \DateTime('@' . $this->flysystem->getTimestamp($path))) {
$resource = fopen($backupFile->getPath(), 'r');
$this->flysystem->updateStream($path, $resource);
fclose($resource);
}
} else {
$resource = fopen($backupFile->getPath(), 'r');
$this->flysystem->putStream($path, $resource);
fclose($resource);
}
} catch (\Exception $e) {
throw new DestinationException(sprintf('Unable to backup file "%s" to flysystem destination.', $backupFile->getPath()), 0, $e);
}
}
/**
* @var FileInterface $removedBackupFile
*/
foreach ($removedBackupFiles as $removedBackupFile) {
$path = $backupDirectory . '/' . $removedBackupFile->getRelativePath();
try {
$this->flysystem->delete($path);
} catch (\Exception $e) {
throw new DestinationException(sprintf('Unable to cleanup backup destination "%s" after backup process, file "%s" could not be removed.', $backupDirectory, $path), 0, $e);
}
}
$this->removeEmptyDirectories($backupDirectory);
if (is_array($this->backups)) {
$this->backups[$backup->getName()] = $backup;
}
}
示例10: delete
/**
* Delete the file at a given path.
*
* @param string|array $paths
* @return bool
*/
public function delete($paths)
{
$paths = is_array($paths) ? $paths : func_get_args();
foreach ($paths as $path) {
$this->driver->delete($path);
}
return true;
}
示例11: handle
/**
* @param DeleteAvatar $command
* @return \Flarum\Core\User
* @throws PermissionDeniedException
*/
public function handle(DeleteAvatar $command)
{
$actor = $command->actor;
$user = $this->users->findOrFail($command->userId);
if ($actor->id !== $user->id) {
$this->assertCan($actor, 'edit', $user);
}
$avatarPath = $user->avatar_path;
$user->changeAvatarPath(null);
$this->events->fire(new AvatarWillBeDeleted($user, $actor));
$user->save();
if ($this->uploadDir->has($avatarPath)) {
$this->uploadDir->delete($avatarPath);
}
$this->dispatchEventsFor($user, $actor);
return $user;
}
示例12: createAndBackup
private function createAndBackup($path, $content)
{
if ($this->enableBackup) {
if ($this->backup->has($path)) {
$this->backup->delete($path);
}
$this->backup->write($path, $content);
}
$this->master->write($path, $content);
}
示例13: delete
/**
* Delete the file at a given path.
*
* @param string|array $paths
* @return bool
*/
public function delete($paths)
{
$paths = is_array($paths) ? $paths : func_get_args();
foreach ($paths as $path) {
try {
$this->driver->delete($path);
} catch (FileNotFoundException $e) {
//
}
}
return true;
}
示例14: delete
/**
* Delete the file at a given path.
*
* @param string|array $paths
* @return bool
*/
public function delete($paths)
{
$paths = is_array($paths) ? $paths : func_get_args();
$success = true;
foreach ($paths as $path) {
try {
if (!$this->driver->delete($path)) {
$success = false;
}
} catch (FileNotFoundException $e) {
$success = false;
}
}
return $success;
}
示例15: uploadFile
protected function uploadFile(UploadedFileInterface $content, $mime, $filePath)
{
$uri = $content->getStream()->getMetadata('uri');
if (!$uri) {
throw new SaveResourceErrorException('Unknown error: can\'t get uploaded file uri');
}
$uploadedMime = $this->filesystem->getMimetype($uri);
if ($mime !== $uploadedMime) {
/**
* Try to remove unnecessary file because UploadFile object can be emulated
* @see \Staticus\Middlewares\ActionPostAbstract::download
*/
$this->filesystem->delete($uri);
throw new WrongRequestException('Bad request: incorrect mime-type of the uploaded file');
}
$content->moveTo($filePath);
}