feature #35642 [HttpFoundation] Make dependency on Mime component optional (atailouloute)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[HttpFoundation] Make dependency on Mime component optional

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Make the Mime component dependency optional

/cc @nicolas-grekas

Commits
-------

11cef32ff7 [HttpFoundation] Make dependency on Mime component optional
This commit is contained in:
Fabien Potencier 2020-02-08 08:05:09 +01:00
commit f4490a6c65
4 changed files with 13 additions and 1 deletions

View File

@ -12,6 +12,7 @@ CHANGELOG
`__construct()` instead)
* added `Request::preferSafeContent()` and `Response::setContentSafe()` to handle "safe" HTTP preference
according to [RFC 8674](https://tools.ietf.org/html/rfc8674)
* made the Mime component an optional dependency
5.0.0
-----

View File

@ -54,6 +54,10 @@ class File extends \SplFileInfo
*/
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;
}

View File

@ -133,6 +133,10 @@ class UploadedFile extends File
*/
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;
}

View File

@ -17,13 +17,16 @@
],
"require": {
"php": "^7.2.5",
"symfony/mime": "^4.4|^5.0",
"symfony/polyfill-mbstring": "~1.1"
},
"require-dev": {
"predis/predis": "~1.0",
"symfony/mime": "^4.4|^5.0",
"symfony/expression-language": "^4.4|^5.0"
},
"suggest" : {
"symfony/mime": "To use the file extension guesser"
},
"autoload": {
"psr-4": { "Symfony\\Component\\HttpFoundation\\": "" },
"exclude-from-classmap": [