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


PHP Filesystem::has方法代码示例

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


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

示例1: generateThumbnail

 /**
  * @param string $fileKey
  * @param string $fileKeyWithFormat
  * @param Format $format
  *
  * @return
  */
 protected function generateThumbnail($fileKey, $fileKeyWithFormat, Format $format)
 {
     // check if has original picture
     try {
         $has = $this->fileSystem->has($fileKey);
     } catch (\OutOfBoundsException $e) {
         $has = false;
     }
     if (!$has) {
         throw new Exception\ImageDoesNotExistException();
     }
     // create thumbnail
     try {
         $blobOriginal = $this->fileSystem->read($fileKey);
     } catch (FileNotFound $e) {
         throw new Exception\ImageDoesNotExistException();
     }
     $imagine = new Imagine();
     $image = $imagine->load($blobOriginal);
     $resizedImage = Manipulator::resize($image, $format);
     $extension = $this->getExtension($fileKey);
     $blobResizedImage = $resizedImage->get($extension, array('jpeg_quality' => 90, 'png_compression_level' => 9));
     $this->fileSystem->write($fileKeyWithFormat, $blobResizedImage, true);
     return $blobResizedImage;
 }
开发者ID:fvilpoix,项目名称:php-common,代码行数:32,代码来源:Resizator.php

示例2: showAction

 /**
  * @param Request $request
  * @param string  $filename
  *
  * @throws NotFoundHttpException If media is not found
  *
  * @return Response
  */
 public function showAction(Request $request, $filename)
 {
     if (!$this->filesystem->has($filename)) {
         throw new NotFoundHttpException(sprintf('Media "%s" not found', $filename));
     }
     $response = new Response($content = $this->filesystem->read($filename));
     $mime = $this->filesystem->mimeType($filename);
     if (($filter = $request->query->get('filter')) && null !== $mime && 0 === strpos($mime, 'image')) {
         try {
             $cachePath = $this->cacheManager->resolve($request, $filename, $filter);
             if ($cachePath instanceof Response) {
                 $response = $cachePath;
             } else {
                 $image = $this->imagine->load($content);
                 $response = $this->filterManager->get($request, $filter, $image, $filename);
                 $response = $this->cacheManager->store($response, $cachePath, $filter);
             }
         } catch (\RuntimeException $e) {
             if (0 === strpos($e->getMessage(), 'Filter not defined')) {
                 throw new HttpException(404, sprintf('The filter "%s" cannot be found', $filter), $e);
             }
             throw $e;
         }
     }
     if ($mime) {
         $response->headers->set('Content-Type', $mime);
     }
     return $response;
 }
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:37,代码来源:MediaController.php

示例3: preUpload

 /**
  * Update attachment entity before upload
  *
  * @param File $entity
  */
 public function preUpload(File $entity)
 {
     if ($entity->isEmptyFile()) {
         if ($this->filesystem->has($entity->getFilename())) {
             $this->filesystem->delete($entity->getFilename());
         }
         $entity->setFilename(null);
         $entity->setExtension(null);
         $entity->setOriginalFilename(null);
     }
     if ($entity->getFile() !== null && $entity->getFile()->isFile()) {
         $entity->setOwner($this->securityFacadeLink->getService()->getLoggedUser());
         $file = $entity->getFile();
         if ($entity->getFilename() !== null && $this->filesystem->has($entity->getFilename())) {
             $this->filesystem->delete($entity->getFilename());
         }
         $entity->setExtension($file->guessExtension());
         if ($file instanceof UploadedFile) {
             $entity->setOriginalFilename($file->getClientOriginalName());
             $entity->setMimeType($file->getClientMimeType());
             $entity->setFileSize($file->getClientSize());
         } else {
             $entity->setOriginalFilename($file->getFileName());
             $entity->setMimeType($file->getMimeType());
             $entity->setFileSize($file->getSize());
         }
         $entity->setFilename(uniqid() . '.' . $entity->getExtension());
         if ($this->filesystem->getAdapter() instanceof MetadataSupporter) {
             $this->filesystem->getAdapter()->setMetadata($entity->getFilename(), ['contentType' => $entity->getMimeType()]);
         }
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:37,代码来源:AttachmentManager.php

示例4: deleteFile

 /**
  * delete the given file
  *
  * @param string $file
  */
 public function deleteFile($file)
 {
     if (!$this->filesystem->has($file)) {
         return;
     }
     $this->filesystem->delete($file);
     $this->cacheManager->remove($file);
 }
开发者ID:CampaignChain,项目名称:core,代码行数:13,代码来源:FileUploadService.php

示例5: write

 /**
  * @param mixed $data
  * @param int $mode
  * @return int
  */
 public function write($data, $mode = 0)
 {
     if ($mode & FILE_APPEND) {
         $data = $this->read() . $data;
     }
     if (!$this->gaufrette->has($this->filePath)) {
         $this->gaufrette->createFile($this->filePath);
     }
     return $this->gaufrette->write($this->filePath, $data, true);
 }
开发者ID:raphhh,项目名称:balloon,代码行数:15,代码来源:GaufretteAdapter.php

示例6: upload

 /**
  * {@inheritdoc}
  */
 public function upload(ImageInterface $image)
 {
     if (!$image->hasFile()) {
         return;
     }
     if (null !== $image->getPath()) {
         $this->remove($image->getPath());
     }
     do {
         $hash = md5(uniqid(mt_rand(), true));
         $path = $this->expandPath($hash . '.' . $image->getFile()->guessExtension());
     } while ($this->filesystem->has($path));
     $image->setPath($path);
     $this->filesystem->write($image->getPath(), file_get_contents($image->getFile()->getPathname()));
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:18,代码来源:ImageUploader.php

示例7: let

 function let(Filesystem $filesystem, ImageInterface $image)
 {
     $filesystem->has(Argument::any())->willReturn(false);
     $file = new File(__FILE__, 'img.jpg');
     $image->getFile()->willReturn($file);
     $this->beConstructedWith($filesystem);
 }
开发者ID:Silwereth,项目名称:Sylius,代码行数:7,代码来源:ImageUploaderSpec.php

示例8: shouldDeleteFile

 /**
  * @test
  * @group functional
  */
 public function shouldDeleteFile()
 {
     $this->filesystem->write('foo', 'Some content');
     $this->assertTrue($this->filesystem->has('foo'));
     $this->filesystem->delete('foo');
     $this->assertFalse($this->filesystem->has('foo'));
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:11,代码来源:FunctionalTestCase.php

示例9: fileExists

 /**
  * Predicate to know if file exists physically
  *
  * @param ProductMediaInterface $media
  *
  * @return bool
  */
 protected function fileExists(ProductMediaInterface $media)
 {
     if (null === $media->getFilename()) {
         return false;
     }
     return $this->filesystem->has($media->getFilename());
 }
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:14,代码来源:MediaManager.php

示例10: read

 private function read(Filesystem $fs)
 {
     $profileFilename = Application::PROFILE_FILENAME;
     if ($fs->has($profileFilename)) {
         $this->processProfileContent($fs->read($profileFilename));
     }
 }
开发者ID:lebris,项目名称:karma,代码行数:7,代码来源:ProfileReader.php

示例11: shouldWorkWithHiddenFiles

 /**
  * @test
  * @group functional
  */
 public function shouldWorkWithHiddenFiles()
 {
     $this->filesystem->write('.foo', 'hidden');
     $this->assertTrue($this->filesystem->has('.foo'));
     $this->assertContains('.foo', $this->filesystem->keys());
     $this->filesystem->delete('.foo');
     $this->assertFalse($this->filesystem->has('.foo'));
 }
开发者ID:course-hero,项目名称:gaufrette-extras,代码行数:12,代码来源:FunctionalTestCase.php

示例12: upload

 /**
  * {@inheritdoc}
  */
 public function upload(MediaInterface $media, $name = null, $test = false)
 {
     if (!$media->hasMedia()) {
         return;
     }
     if (null !== $media->getName()) {
         $this->remove($media->getName());
     }
     do {
         $hash = md5(uniqid(mt_rand(), true));
         if ($test === false) {
             $name = $hash . '.' . $media->getMedia()->guessExtension();
         }
     } while ($this->filesystem->has($name));
     $media->setName($name);
     if ($test === false) {
         $this->filesystem->write($media->getName(), file_get_contents($media->getMedia()->getPathname()));
     }
 }
开发者ID:dasklney,项目名称:kreta,代码行数:22,代码来源:MediaUploader.php

示例13:

 function it_uploads_without_removing(MediaInterface $media, Filesystem $filesystem, UploadedFile $file)
 {
     $media->hasMedia()->shouldBeCalled()->willReturn(true);
     $media->getName()->shouldBeCalled()->willReturn(null);
     $media->getMedia()->shouldBeCalled()->willReturn($file);
     $file->guessExtension()->shouldBeCalled()->willReturn('md');
     $filesystem->has(Argument::containingString('.md'))->shouldBeCalled()->willReturn(false);
     $media->setName(Argument::any())->shouldBeCalled()->willReturn($media);
     $media->getMedia()->shouldBeCalled()->willReturn($file);
     $file->getPathname()->shouldBeCalled()->willReturn(__DIR__ . '/../../../../../README.md');
     $filesystem->write(Argument::any(), file_get_contents(__DIR__ . '/../../../../../README.md'))->shouldBeCalled()->willReturn(Argument::type('int'));
     $this->upload($media);
 }
开发者ID:cespedosa,项目名称:kreta,代码行数:13,代码来源:MediaUploaderSpec.php

示例14: cleanup

 public function cleanup(UserProfile $prop)
 {
     if ($prop->getProperty()->getFieldType() === ProfileProperty::TYPE_FILE) {
         /*$fileName = str_replace($this->getBaseFileUrl() . '/', '', $prop->getPropertyValue());
           if ( is_file($this->getBaseFilePath() . '/' . $fileName) ) {
               echo 'maybe removing ' . $this->getBaseFilePath() . '/' . $fileName;
               @unlink($this->getBaseFilePath() . '/' . $fileName);
           }*/
         $fileKey = AbstractUploader::extractKey($prop->getPropertyValue(), $this->awsBucket);
         if ($fileKey && $this->filesystem->has($fileKey)) {
             $this->filesystem->delete($fileKey);
         }
     }
 }
开发者ID:scottstuff,项目名称:GCProtractorJS,代码行数:14,代码来源:UserPropertyHandler.php

示例15: has

 public function has($id)
 {
     return $this->filesystem->has($id);
 }
开发者ID:radnan,项目名称:rdn-upload,代码行数:4,代码来源:Gaufrette.php


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