8000 Fixed missing friendly error on call of getMimeType() by GrahamCampbell · Pull Request #35807 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fixed missing friendly error on call of getMimeType() #35807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Symfony/Component/HttpFoundation/File/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ public function __construct(string $path, bool $checkPath = true)
*/
public function guessExtension()
{
if (!class_exists(MimeTypes::class)) {
throw new \LogicException('You cannot guess the extension as the Mime component is not installed. Try running "composer require symfony/mime".');
}
// Do not inline this
$mimeType = $this->getMimeType();

return MimeTypes::getDefault()->getExtensions($this->getMimeType())[0] ?? null;
return MimeTypes::getDefault()->getExtensions($mimeType)[0] ?? null;
}

/**
Expand All @@ -74,6 +73,10 @@ public function guessExtension()
*/
public function getMimeType()
{
if (!class_exists(MimeTypes::class)) {
throw new \LogicException('You cannot guess the mime type as the Mime component is not installed. Try running "composer require symfony/mime".');
}

return MimeTypes::getDefault()->guessMimeType($this->getPathname());
}

Expand Down
0