Skip to content

Commit

Permalink
feature #35642 [HttpFoundation] Make dependency on Mime component opt…
Browse files Browse the repository at this point in the history
…ional (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
-------

11cef32 [HttpFoundation] Make dependency on Mime component optional
  • Loading branch information
fabpot committed Feb 8, 2020
2 parents 4253251 + 11cef32 commit f4490a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/CHANGELOG.md
Expand Up @@ -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
-----
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/File/File.php
Expand Up @@ -54,6 +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".');
}

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

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/File/UploadedFile.php
Expand Up @@ -133,6 +133,10 @@ public function getClientMimeType()
*/
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;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/HttpFoundation/composer.json
Expand Up @@ -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": [
Expand Down

0 comments on commit f4490a6

Please sign in to comment.