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


PHP FilesystemInterface::has方法代码示例

本文整理汇总了PHP中League\Flysystem\FilesystemInterface::has方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::has方法的具体用法?PHP FilesystemInterface::has怎么用?PHP FilesystemInterface::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在League\Flysystem\FilesystemInterface的用法示例。


在下文中一共展示了FilesystemInterface::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 public function __invoke()
 {
     $version = $this->resourceDO->getVersion();
     $filePath = $this->resourceDO->getFilePath();
     if (!$this->resourceDO->getName() || !$this->resourceDO->getType() || !$this->resourceDO->getBaseDirectory()) {
         throw new CommandErrorException('Cannot delete empty resource');
     }
     if ($this->filesystem->has($filePath)) {
         // Make backup of the default version
         if (ResourceDOInterface::DEFAULT_VERSION === $version) {
             $lastVersion = $this->findLastVersion();
             // But only if previous existing version is not the default and not has the same content as deleting
             if (ResourceDOInterface::DEFAULT_VERSION !== $lastVersion) {
                 $lastVersionResourceDO = clone $this->resourceDO;
                 $lastVersionResourceDO->setVersion($lastVersion);
                 $command = new DestroyEqualResourceCommand($lastVersionResourceDO, $this->resourceDO, $this->filesystem);
                 $result = $command();
                 if ($result === $this->resourceDO) {
                     // If the previous file version already the same, current version is already deleted
                     // and backup and yet another deletion is not needed anymore
                     return $this->resourceDO;
                 }
             }
             $command = new BackupResourceCommand($this->resourceDO, $this->filesystem);
             $command($lastVersion);
         }
         $this->deleteFile($filePath);
         return $this->resourceDO;
     }
     return $this->resourceDO;
 }
开发者ID:kivagant,项目名称:staticus-core,代码行数:31,代码来源:DeleteSafetyResourceCommand.php

示例2: 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);
     }
 }
开发者ID:kivagant,项目名称:staticus-core,代码行数:7,代码来源:DestroyResourceCommand.php

示例3: __invoke

 /**
  * @return ResourceDOInterface SuspectResource if it have been deleted or OriginResource if the Suspect is not equal
  */
 public function __invoke()
 {
     $originName = $this->originResourceDO->getName();
     $suspectName = $this->suspectResourceDO->getName();
     $originType = $this->originResourceDO->getType();
     $suspectType = $this->suspectResourceDO->getType();
     $originFilePath = $this->originResourceDO->getFilePath();
     $suspectFilePath = $this->suspectResourceDO->getFilePath();
     if (!$originName || !$originType) {
         throw new CommandErrorException('Cannot destroy equal resource: the origin resource is empty');
     }
     if (!$suspectName || !$suspectType) {
         throw new CommandErrorException('Cannot destroy equal resource: the suspect resource is empty');
     }
     if ($originFilePath === $suspectFilePath) {
         throw new CommandErrorException('Cannot destroy equal resource: Origin and Suspect have same paths');
     }
     // Unfortunately, this condition can not always work fine.
     // Because some Middlewares can compress, resize etc. the resource that saved before
     // and the second uploaded copy will never be equal
     if ($originType === $suspectType && $this->filesystem->has($originFilePath) === $this->filesystem->has($suspectFilePath) && $this->filesystem->getSize($originFilePath) === $this->filesystem->getSize($suspectFilePath) && $this->getFileHash($originFilePath) === $this->getFileHash($suspectFilePath)) {
         $command = new DestroyResourceCommand($this->suspectResourceDO, $this->filesystem);
         return $command(true);
     }
     return $this->originResourceDO;
 }
开发者ID:kivagant,项目名称:staticus-core,代码行数:29,代码来源:DestroyEqualResourceCommand.php

示例4: find

 /**
  * {@inheritdoc}
  */
 public function find($path)
 {
     if ($this->filesystem->has($path) === false) {
         throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
     }
     $mimeType = $this->filesystem->getMimetype($path);
     return new Binary($this->filesystem->read($path), $mimeType, $this->extensionGuesser->guess($mimeType));
 }
开发者ID:graundas,项目名称:LiipImagineBundle,代码行数:11,代码来源:FlysystemLoader.php

示例5: exists

 /**
  * @override
  * @inheritDoc
  */
 public function exists($path)
 {
     try {
         return $this->fs->has($path);
     } catch (Error $ex) {
     } catch (Exception $ex) {
     }
     throw new ReadException("File {$path} does not exist.", $ex);
 }
开发者ID:kraken-php,项目名称:framework,代码行数:13,代码来源:Filesystem.php

示例6: data

 /**
  * @param ServerRequestInterface $request
  *
  * @return mixed|null
  */
 public function data(ServerRequestInterface $request)
 {
     $url = $request->getUri()->getPath();
     $parameters = array_merge($request->getQueryParams(), $request->getParsedBody());
     $file = $this->file($url, $parameters);
     if (!$this->filesystem->has($file)) {
         $file = $this->defaultFile($url);
     }
     if (!$this->filesystem->has($file)) {
         return null;
     }
     return $this->filesystem->read($file);
 }
开发者ID:satahippy,项目名称:fake-api-server,代码行数:18,代码来源:PathDataProvider.php

示例7: create

 public function create(User $_user, string $extension, string $mime_type, string $original_name, string $temp_location, bool $is_image)
 {
     $query = "INSERT INTO `file` (user_id, extension, mime_type, md5, original_name, date_added, is_image)\n\t\t\t\t\t  VALUES (:u, :e, :mt, :m, :o, :d, :i)";
     $this->_pdo->perform($query, ["u" => $this->user_id = $_user->getId(), "e" => $this->extension = $extension, "mt" => $this->mime_type = $mime_type, "m" => $this->md5 = md5_file($temp_location), "o" => $this->original_name = $original_name, "d" => $this->date_added = Utility::getDateTimeForMySQLDateTime(), "i" => $this->is_image = $is_image]);
     $stream = fopen($temp_location, "r+");
     if (!$this->_filesystem->has($this->getDirMain())) {
         $this->_filesystem->createDir($this->getDirMain());
     }
     if (!$this->_filesystem->has($this->getDirSub())) {
         $this->_filesystem->createDir($this->getDirSub());
     }
     $this->_filesystem->writeStream($this->getPath(), $stream, ["visibility" => AdapterInterface::VISIBILITY_PUBLIC]);
     fclose($stream);
 }
开发者ID:stevenimle,项目名称:GMA,代码行数:14,代码来源:File.php

示例8: 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();
 }
开发者ID:cass-project,项目名称:cass,代码行数:14,代码来源:ThemeService.php

示例9: serveFromSource

 /**
  * Process a source image and Generate a response object
  *
  * @param  String  $path Path to the source image
  * @return Boolean
  */
 private function serveFromSource($path)
 {
     //try and load the image from the source
     if ($this->source->has($path)) {
         $file = $this->source->get($path);
         // Get the template object
         $template = $this->templates[$this->template]();
         // Process the image
         $image = $this->processImage($file, $this->imageManager, $template);
         // Set the headers
         $this->response->headers->set('Content-Type', $image->mime);
         $this->response->headers->set('Content-Length', strlen($image->encoded));
         $lastModified = new \DateTime();
         // now
         $this->setHttpCacheHeaders($lastModified, md5($this->getCachePath() . $lastModified->getTimestamp()), $this->maxAge);
         // Send the processed image in the response
         $this->response->setContent($image->encoded);
         // Setup a callback to write the processed image to the cache
         // This will be called after the image has been sent to the browser
         $this->cacheWrite = function (FilesystemInterface $cache, $path) use($image) {
             // use put() to write or update
             $cache->put($path, $image->encoded);
         };
         return true;
     }
     return false;
 }
开发者ID:diarmuidie,项目名称:imagerack-kernel,代码行数:33,代码来源:Server.php

示例10: FileTransferException

 function it_throws_an_exception_when_the_file_can_not_be_read_on_the_filesystem(FileInterface $file, FilesystemInterface $filesystem)
 {
     $file->getKey()->willReturn('path/to/file.txt');
     $filesystem->has('path/to/file.txt')->willReturn(true);
     $filesystem->readStream('path/to/file.txt')->willReturn(false);
     $this->shouldThrow(new FileTransferException('Unable to fetch the file "path/to/file.txt" from the filesystem.'))->during('fetch', [$file, $filesystem]);
 }
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:7,代码来源:RawFileFetcherSpec.php

示例11: write

 /**
  * Write session data
  * @link http://php.net/manual/en/sessionhandlerinterface.write.php
  * @param string $session_id The session id.
  * @param string $session_data <p>
  * The encoded session data. This data is the
  * result of the PHP internally encoding
  * the $_SESSION superglobal to a serialized
  * string and passing it as this parameter.
  * Please note sessions use an alternative serialization method.
  * </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 write($session_id, $session_data)
 {
     if (!$this->driver->has($path = $this->path . $session_id)) {
         $this->driver->create($path);
     }
     return $this->driver->put($path, $session_data);
 }
开发者ID:AnonymPHP,项目名称:Anonym-Session,代码行数:24,代码来源:FileSessionHandler.php

示例12: _stat

 /**
  * Return stat for given path.
  * Stat contains following fields:
  * - (int)    size    file size in b. required
  * - (int)    ts      file modification time in unix time. required
  * - (string) mime    mimetype. required for folders, others - optionally
  * - (bool)   read    read permissions. required
  * - (bool)   write   write permissions. required
  * - (bool)   locked  is object locked. optionally
  * - (bool)   hidden  is object hidden. optionally
  * - (string) alias   for symlinks - link target path relative to root path. optionally
  * - (string) target  for symlinks - link target path. optionally
  *
  * If file does not exists - returns empty array or false.
  *
  * @param  string  $path    file path
  * @return array|false
  **/
 protected function _stat($path)
 {
     $stat = array('mime' => 'directory', 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'size' => 0);
     // If root, just return from above
     if ($this->root == $path) {
         $stat['name'] = $this->root;
         return $stat;
     }
     // If not exists, return empty
     if (!$this->fs->has($path)) {
         return array();
     }
     $meta = $this->fs->getMetadata($path);
     // Get timestamp/size
     $stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
     $stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
     // Check if file, if so, check mimetype
     if ($meta['type'] == 'file') {
         $stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
         $imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
         if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
             $stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
             $stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
         }
     }
     if (!isset($stat['url']) && $this->fs->getUrl()) {
         $stat['url'] = 1;
     }
     return $stat;
 }
开发者ID:quepasso,项目名称:dashboard,代码行数:48,代码来源:ElFinderVolumeFlysystem.php

示例13: 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;
     }
 }
开发者ID:runopencode,项目名称:backup,代码行数:50,代码来源:FlysystemDestination.php

示例14: touchDir

 private function touchDir(FilesystemInterface $fs, string $entityId, string $collectionUID, string $imageId) : string
 {
     $resultPath = sprintf('%s/%s/%s', $entityId, $collectionUID, $imageId);
     if (!$fs->has($resultPath)) {
         $fs->createDir($resultPath);
     }
     return $resultPath;
 }
开发者ID:cass-project,项目名称:cass,代码行数:8,代码来源:MockAvatarStrategy.php

示例15: 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;
 }
开发者ID:flarum,项目名称:core,代码行数:22,代码来源:DeleteAvatarHandler.php


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