[HttpFoundation] Make dependency on Mime component optional
This commit is contained in:
parent
83a53a5edf
commit
11cef32ff7
@ -12,6 +12,7 @@ CHANGELOG
|
|||||||
`__construct()` instead)
|
`__construct()` instead)
|
||||||
* added `Request::preferSafeContent()` and `Response::setContentSafe()` to handle "safe" HTTP preference
|
* added `Request::preferSafeContent()` and `Response::setContentSafe()` to handle "safe" HTTP preference
|
||||||
according to [RFC 8674](https://tools.ietf.org/html/rfc8674)
|
according to [RFC 8674](https://tools.ietf.org/html/rfc8674)
|
||||||
|
* made the Mime component an optional dependency
|
||||||
|
|
||||||
5.0.0
|
5.0.0
|
||||||
-----
|
-----
|
||||||
|
@ -54,6 +54,10 @@ class File extends \SplFileInfo
|
|||||||
*/
|
*/
|
||||||
public function guessExtension()
|
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".');
|
||||||
|
}
|
||||||
|
|
||||||
return MimeTypes::getDefault()->getExtensions($this->getMimeType())[0] ?? null;
|
return MimeTypes::getDefault()->getExtensions($this->getMimeType())[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +133,10 @@ class UploadedFile extends File
|
|||||||
*/
|
*/
|
||||||
public function guessClientExtension()
|
public function guessClientExtension()
|
||||||
{
|
{
|
||||||
|
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".');
|
||||||
|
}
|
||||||
|
|
||||||
return MimeTypes::getDefault()->getExtensions($this->getClientMimeType())[0] ?? null;
|
return MimeTypes::getDefault()->getExtensions($this->getClientMimeType())[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,16 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2.5",
|
"php": "^7.2.5",
|
||||||
"symfony/mime": "^4.4|^5.0",
|
|
||||||
"symfony/polyfill-mbstring": "~1.1"
|
"symfony/polyfill-mbstring": "~1.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"predis/predis": "~1.0",
|
"predis/predis": "~1.0",
|
||||||
|
"symfony/mime": "^4.4|^5.0",
|
||||||
"symfony/expression-language": "^4.4|^5.0"
|
"symfony/expression-language": "^4.4|^5.0"
|
||||||
},
|
},
|
||||||
|
"suggest" : {
|
||||||
|
"symfony/mime": "To use the file extension guesser"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\HttpFoundation\\": "" },
|
"psr-4": { "Symfony\\Component\\HttpFoundation\\": "" },
|
||||||
"exclude-from-classmap": [
|
"exclude-from-classmap": [
|
||||||
|
Reference in New Issue
Block a user