Skip to content

Commit e2bc10f

Browse files
bug #31923 [Serializer] Fix DataUriNormalizer deprecation (MIME type guesser is optional) (ogizanagi)
This PR was merged into the 4.3 branch. Discussion ---------- [Serializer] Fix DataUriNormalizer deprecation (MIME type guesser is optional) | Q | A | ------------- | --- | Branch? | 4.3 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | N/A <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A Relates to #31771 (comment) : The deprecation isn't fundamentally wrong, but if none of the Mime nor HttpFoundation components are installed, the DataUriNormalizer can be used, and the MIME type used will always be `'application/octet-stream'` https://github.com/symfony/symfony/blob/9691519ca46511005bc701ca93c2973923952034/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php#L39-L46 https://github.com/symfony/symfony/blob/9691519ca46511005bc701ca93c2973923952034/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php#L135-L139 So this completes the deprecation message, as well as allowing `null` again when no default MIME type guesser is available at all. Commits ------- 2740bd1 [Serializer] Fix DataUriNormalizer deprecation (MIME type guesser is optional)
2 parents 3b90c98 + 2740bd1 commit e2bc10f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
3939
private $mimeTypeGuesser;
4040

4141
/**
42-
* @param MimeTypeGuesserInterface
42+
* @param MimeTypeGuesserInterface|null $mimeTypeGuesser
4343
*/
4444
public function __construct($mimeTypeGuesser = null)
4545
{
@@ -48,8 +48,8 @@ public function __construct($mimeTypeGuesser = null)
4848
} elseif (null === $mimeTypeGuesser) {
4949
if (class_exists(MimeTypes::class)) {
5050
$mimeTypeGuesser = MimeTypes::getDefault();
51-
} else {
52-
@trigger_error(sprintf('Passing null to "%s()" without symfony/mime installed is deprecated since Symfony 4.3, install symfony/mime.', __METHOD__), E_USER_DEPRECATED);
51+
} elseif (class_exists(MimeTypeGuesser::class)) {
52+
@trigger_error(sprintf('Passing null to "%s()" to use a default MIME type guesser without Symfony Mime installed is deprecated since Symfony 4.3. Try running "composer require symfony/mime".', __METHOD__), E_USER_DEPRECATED);
5353
$mimeTypeGuesser = MimeTypeGuesser::getInstance();
5454
}
5555
} elseif (!$mimeTypeGuesser instanceof MimeTypes) {
@@ -156,7 +156,9 @@ private function getMimeType(\SplFileInfo $object)
156156

157157
if ($this->mimeTypeGuesser instanceof DeprecatedMimeTypeGuesserInterface && $mimeType = $this->mimeTypeGuesser->guess($object->getPathname())) {
158158
return $mimeType;
159-
} elseif ($this->mimeTypeGuesser && $mimeType = $this->mimeTypeGuesser->guessMimeType($object->getPathname())) {
159+
}
160+
161+
if ($this->mimeTypeGuesser && $mimeType = $this->mimeTypeGuesser->guessMimeType($object->getPathname())) {
160162
return $mimeType;
161163
}
162164

0 commit comments

Comments
 (0)