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


PHP MimeTypeGuesser::getInstance方法代码示例

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


在下文中一共展示了MimeTypeGuesser::getInstance方法的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::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。