當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。