8000 [HttpFoundation] Make dependency on Mime component optional · symfony/symfony@11cef32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 11cef32

Browse files
committed
[HttpFoundation] Make dependency on Mime component optional
1 parent 83a53a5 commit 11cef32

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
`__construct()` instead)
1313
* added `Request::preferSafeContent()` and `Response::setContentSafe()` to handle "safe" HTTP preference
1414
according to [RFC 8674](https://tools.ietf.org/html/rfc8674)
15+
* made the Mime component an optional dependency
1516

1617
5.0.0
1718
-----

src/Symfony/Component/HttpFoundation/File/File.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function __construct(string $path, bool $checkPath = true)
5454
*/
5555
public function guessExtension()
5656
{
57+
if (!class_exists(MimeTypes::class)) {
58+
throw new \LogicException('You cannot guess the extension as the Mime component is not installed. Try running "composer require symfony/mime".');
59+
}
60+
5761
return MimeTypes::getDefault()->getExtensions($this->getMimeType())[0] ?? null;
5862
}
5963

src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public function getClientMimeType()
133133
*/
134134
public function guessClientExtension()
135135
{
136+
if (!class_exists(MimeTypes::class)) {
137+
throw new \LogicException('You cannot guess the extension as the Mime component is not installed. Try running "composer require symfony/mime".');
138+
}
139+
136140
return MimeTypes::getDefault()->getExtensions($this->getClientMimeType())[0] ?? null;
137141
}
138142

src/Symfony/Component/HttpFoundation/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
],
1818
"require": {
1919
"php": "^7.2.5",
20-
"symfony/mime": "^4.4|^5.0",
2120
"symfony/polyfill-mbstring": "~1.1"
2221
},
2322
"require-dev": {
2423
"predis/predis": "~1.0",
24+
"symfony/mime": "^4.4|^5.0",
2525
"symfony/expression-language": "^4.4|^5.0"
2626
},
27+
"suggest" : {
28+
"symfony/mime": "To use the file extension guesser"
29+
},
2730
"autoload": {
2831
"psr-4": { "Symfony\\Component\\HttpFoundation\\": "" },
2932
"exclude-from-classmap": [

0 commit comments

Comments
 (0)
0