當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MimeType\MimeTypeGuesser類代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser的典型用法代碼示例。如果您正苦於以下問題:PHP MimeTypeGuesser類的具體用法?PHP MimeTypeGuesser怎麽用?PHP MimeTypeGuesser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MimeTypeGuesser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSymfonyGuesserRegistration

 /**
  * @covers ::registerWithSymfonyGuesser
  *
  * @see Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
  */
 public function testSymfonyGuesserRegistration()
 {
     // Make the guessers property accessible on Symfony's MimeTypeGuesser.
     $symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
     // Test that the Drupal mime type guess is not being used before the
     // override method is called. It is possible that the test environment does
     // not support the default guessers.
     $guessers = $this->readAttribute($symfony_guesser, 'guessers');
     if (count($guessers)) {
         $this->assertNotInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
     }
     $container = new ContainerBuilder();
     $container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
     MimeTypeGuesser::registerWithSymfonyGuesser($container);
     $symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
     $guessers = $this->readAttribute($symfony_guesser, 'guessers');
     $this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
     $this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
     $count = count($guessers);
     $container = new ContainerBuilder();
     $container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
     MimeTypeGuesser::registerWithSymfonyGuesser($container);
     $symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
     $guessers = $this->readAttribute($symfony_guesser, 'guessers');
     $this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
     $this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
     $new_count = count($guessers);
     $this->assertEquals($count, $new_count, 'The count of mime type guessers remains the same after container re-init.');
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:34,代碼來源:MimeTypeGuesserTest.php

示例2: testLoad

 /**
  * @dataProvider provideLoadCases
  */
 public function testLoad($rootDir, $path)
 {
     $loader = new FileSystemLoader(MimeTypeGuesser::getInstance(), ExtensionGuesser::getInstance(), $rootDir);
     $binary = $loader->find($path);
     $this->assertInstanceOf('Liip\\ImagineBundle\\Model\\Binary', $binary);
     $this->assertStringStartsWith('text/', $binary->getMimeType());
 }
開發者ID:umanit,項目名稱:LiipImagineBundle,代碼行數:10,代碼來源:FileSystemLoaderTest.php

示例3: testGuessExtensionIsBasedOnMimeType

 public function testGuessExtensionIsBasedOnMimeType()
 {
     $file = new File(__DIR__ . '/Fixtures/test');
     $guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
     MimeTypeGuesser::getInstance()->register($guesser);
     $this->assertEquals('gif', $file->guessExtension());
 }
開發者ID:peintune,項目名稱:Ternado,代碼行數:7,代碼來源:FileTest.php

示例4: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $user = $this->getReference("user/{$this->creator}");
     $directory = $this->getReference("directory/{$this->directory}");
     $resourceManager = $this->container->get('claroline.manager.resource_manager');
     $filesDirectory = $this->container->getParameter('claroline.param.files_directory');
     $ut = $this->container->get('claroline.utilities.misc');
     $fileType = $manager->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('file');
     foreach ($this->files as $filePath) {
         $filePathParts = explode(DIRECTORY_SEPARATOR, $filePath);
         $fileName = array_pop($filePathParts);
         $extension = pathinfo($filePath, PATHINFO_EXTENSION);
         $hashName = "{$ut->generateGuid()}.{$extension}";
         $targetFilePath = $filesDirectory . DIRECTORY_SEPARATOR . $hashName;
         $file = new File();
         $file->setName($fileName);
         $file->setHashName($hashName);
         if (file_exists($filePath)) {
             copy($filePath, $targetFilePath);
             $file->setSize(filesize($filePath));
         } else {
             touch($targetFilePath);
             $file->setSize(0);
         }
         $mimeType = MimeTypeGuesser::getInstance()->guess($targetFilePath);
         $file->setMimeType($mimeType);
         $resourceManager->create($file, $fileType, $user, $directory->getWorkspace(), $directory);
         $this->addReference("file/{$fileName}", $file);
     }
     $manager->flush();
 }
開發者ID:ngydat,項目名稱:CoreBundle,代碼行數:34,代碼來源:LoadFileData.php

示例5: getUploadedFile

 /**
  * Get the uploaded file from a local path
  * like "/home/user/pictures/photo.png"
  *
  * @param  string $path
  * @return UploadedFile
  */
 protected function getUploadedFile($path)
 {
     $mimeTypeGuesser = MimeTypeGuesser::getInstance();
     $copiedFile = $this->getFileCopy($path);
     $uploadedFile = new UploadedFile($copiedFile, $copiedFile, $mimeTypeGuesser->guess($copiedFile), filesize($copiedFile), null, true);
     return $uploadedFile;
 }
開發者ID:gorvelyfab,項目名稱:KoopaBaseAdminer,代碼行數:14,代碼來源:UploadedFileTrait.php

示例6: __construct

 public function __construct(MimeTypeGuesserInterface $mimeTypeGuesser = null)
 {
     if (null === $mimeTypeGuesser && class_exists('Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesser')) {
         $mimeTypeGuesser = MimeTypeGuesser::getInstance();
     }
     $this->mimeTypeGuesser = $mimeTypeGuesser;
 }
開發者ID:Ener-Getick,項目名稱:symfony,代碼行數:7,代碼來源:DataUriNormalizer.php

示例7: testConvertPdfAsPng

 public function testConvertPdfAsPng()
 {
     $result = $this->pdfToPpm->convertPdf(dirname(__DIR__) . '/Resources/test_1_page.pdf', null, true);
     $mimeTypeGuesser = MimeTypeGuesser::getInstance();
     $mimeType = $mimeTypeGuesser->guess($result->current()->getPathName());
     $this->assertSame('image/png', $mimeType);
 }
開發者ID:waarneembemiddeling,項目名稱:php-pdftoppm,代碼行數:7,代碼來源:PdfToPpmTest.php

示例8: getMimeTypeGuesser

 /**
  * @return MimeTypeGuesser
  */
 private function getMimeTypeGuesser()
 {
     if (!$this->mimeTypeGuesser) {
         $this->mimeTypeGuesser = MimeTypeGuesser::getInstance();
     }
     return $this->mimeTypeGuesser;
 }
開發者ID:pekkis,項目名稱:mime-types,代碼行數:10,代碼來源:SymfonyResolver.php

示例9: load

 /**
  * {@inheritdoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.yml');
     $mimeTypeGuesser = MimeTypeGuesser::getInstance();
     $mimeTypeGuesser->register(new ImageTypeGuesser());
 }
開發者ID:dylanschoenmakers,項目名稱:Cms,代碼行數:10,代碼來源:OpiferMediaExtension.php

示例10: filterDump

 /**
  * @param AssetInterface $asset
  */
 public function filterDump(AssetInterface $asset)
 {
     $sourceBase = $asset->getSourceRoot();
     $sourcePath = $asset->getSourcePath();
     $assetRoot = $this->assetRoot;
     if (null === $sourcePath) {
         return;
     }
     $content = $this->filterReferences($asset->getContent(), function ($matches) use($sourceBase, $sourcePath, $assetRoot) {
         // its not a relative path
         if (false !== strpos($matches['url'], '://') || 0 === strpos($matches['url'], '//') || 0 === strpos($matches['url'], 'data:') || isset($matches['url'][0]) && '/' == $matches['url'][0]) {
             return $matches[0];
         }
         $url = $matches['url'];
         if (false !== ($pos = strpos($url, '?'))) {
             $url = substr($url, 0, $pos);
         }
         $sourceAsset = dirname($sourceBase . '/' . $sourcePath) . '/' . $url;
         if (!is_file($sourceAsset)) {
             return $matches[0];
         }
         $mimeType = MimeTypeGuesser::getInstance()->guess($sourceAsset);
         $destRelativePath = substr($mimeType, 0, strpos($mimeType, '/')) . '/' . basename($url);
         $destAsset = $assetRoot . '/' . $destRelativePath;
         if (!is_dir(dirname($destAsset))) {
             mkdir(dirname($destAsset), 0777, true);
         }
         copy($sourceAsset, $destAsset);
         return str_replace($matches['url'], '../' . $destRelativePath, $matches[0]);
     });
     $asset->setContent($content);
 }
開發者ID:saxulum,項目名稱:saxulum-assetic-twig-provider,代碼行數:35,代碼來源:CssCopyFileFilter.php

示例11: __construct

 public function __construct($path)
 {
     $mimeTypeGuesser = MimeTypeGuesser::getInstance();
     $this->path = $path;
     $this->originalName = basename($path);
     $this->mimeType = $mimeTypeGuesser->guess($path);
     $this->size = filesize($path);
 }
開發者ID:sandyandi,項目名稱:test-uploadedfile-factory,代碼行數:8,代碼來源:DupeFile.php

示例12: testGuessWithNonReadablePath

 public function testGuessWithNonReadablePath()
 {
     $path = __DIR__ . '/../Fixtures/to_delete';
     touch($path);
     chmod($path, 0333);
     $this->setExpectedException('Symfony\\Component\\HttpFoundation\\File\\Exception\\AccessDeniedException');
     MimeTypeGuesser::getInstance()->guess($path);
 }
開發者ID:rooster,項目名稱:symfony,代碼行數:8,代碼來源:MimeTypeTest.php

示例13: guessFileMimeType

 private function guessFileMimeType($filePath)
 {
     $type = MimeTypeGuesser::getInstance()->guess($filePath);
     if (!isset($type)) {
         return DEFAULT_MIME_TYPE;
     }
     return $type;
 }
開發者ID:pavelsavelyev,項目名稱:allure-php-adapter-api,代碼行數:8,代碼來源:AddAttachmentEvent.php

示例14: register

 /**
  * Registers mime type guessers given the configuration
  */
 public function register()
 {
     $guesser = MimeTypeGuesser::getInstance();
     $guesser->register(new RawImageMimeTypeGuesser());
     $guesser->register(new PostScriptMimeTypeGuesser());
     $guesser->register(new AudioMimeTypeGuesser());
     $guesser->register(new VideoMimeTypeGuesser());
     $guesser->register(new CustomExtensionGuesser($this->conf->get(['border-manager', 'extension-mapping'], [])));
 }
開發者ID:luisbrito,項目名稱:Phraseanet,代碼行數:12,代碼來源:MimeGuesserConfiguration.php

示例15: bootstrap

 /**
  * @inheritdoc
  */
 public function bootstrap(Request $request)
 {
     LoggerRegistry::debug('FileModule::bootstrap()');
     // Register the extension-based MIME type guesser which doesn't fail on CSS files.
     MimeTypeGuesser::getInstance()->register(new ExtensionMimeTypeGuesser($this->getEngine()->config('system.mime-types')));
     // TODO files in preview mode
     $filename = $this->getEngine()->getSiteInfo()->getPublicPath(ResourceLocations::RESOURCE_LOCATION_SITE, $request->getPathInfo(), $this);
     return $this->getEngine()->createFileResponse($request, $filename);
 }
開發者ID:sitegear,項目名稱:sitegear,代碼行數:12,代碼來源:FileModule.php


注:本文中的Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。