本文整理汇总了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.');
}
示例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());
}
示例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());
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例8: getMimeTypeGuesser
/**
* @return MimeTypeGuesser
*/
private function getMimeTypeGuesser()
{
if (!$this->mimeTypeGuesser) {
$this->mimeTypeGuesser = MimeTypeGuesser::getInstance();
}
return $this->mimeTypeGuesser;
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例13: guessFileMimeType
private function guessFileMimeType($filePath)
{
$type = MimeTypeGuesser::getInstance()->guess($filePath);
if (!isset($type)) {
return DEFAULT_MIME_TYPE;
}
return $type;
}
示例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'], [])));
}
示例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);
}