本文整理汇总了PHP中Gaufrette\Filesystem::mimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::mimeType方法的具体用法?PHP Filesystem::mimeType怎么用?PHP Filesystem::mimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaufrette\Filesystem
的用法示例。
在下文中一共展示了Filesystem::mimeType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: load
/**
* {@inheritDoc}
*/
public function load($path)
{
try {
$contents = $this->filesystem->read($path);
} catch (FileNotFoundException $e) {
throw new Exception\ImageNotFoundException(sprintf('Source image not found in "%s"', $path));
}
try {
$mimeType = $this->filesystem->mimeType($path);
} catch (\LogicException $e) {
// Mime Type could not be detected
return $contents;
}
if (!$mimeType) {
// Mime Type could not be detected
return $contents;
}
return new Binary($contents, $mimeType);
}
示例3: createFromFilename
/**
* Create a media and load file information
*
* @param string $filename
* @param bool $isUploaded
*
* @throws \InvalidArgumentException When file does not exist
*
* @return ProductMediaInterface
*/
public function createFromFilename($filename, $isUploaded = true)
{
if ($isUploaded) {
$filePath = $this->uploadDirectory . DIRECTORY_SEPARATOR . $filename;
} else {
$filePath = $filename;
}
if ($isUploaded && !$this->filesystem->has($filename)) {
throw new \InvalidArgumentException(sprintf('File "%s" does not exist', $filePath));
}
$media = $this->factory->createMedia();
$media->setOriginalFilename(basename($filename));
$media->setFilename($filename);
if (!$isUploaded) {
$media->setFile(new File($filename));
} else {
$media->setMimeType($this->filesystem->mimeType($filename));
}
return $media;
}