Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/serializer/Normalizer/DataUriNormalizer.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/symfony/serializer/Normalizer/DataUriNormalizer.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/serializer/Normalizer/DataUriNormalizer.php Mon Apr 23 09:46:53 2018 +0100 @@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; use Symfony\Component\Serializer\Exception\InvalidArgumentException; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; /** * Normalizes an {@see \SplFileInfo} object to a data URI. @@ -25,6 +25,12 @@ */ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface { + private static $supportedTypes = array( + \SplFileInfo::class => true, + \SplFileObject::class => true, + File::class => true, + ); + /** * @var MimeTypeGuesserInterface */ @@ -79,11 +85,14 @@ * Regex adapted from Brian Grinstead code. * * @see https://gist.github.com/bgrins/6194623 + * + * @throws InvalidArgumentException + * @throws NotNormalizableValueException */ public function denormalize($data, $class, $format = null, array $context = array()) { if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) { - throw new UnexpectedValueException('The provided "data:" URI is not valid.'); + throw new NotNormalizableValueException('The provided "data:" URI is not valid.'); } try { @@ -96,7 +105,7 @@ return new \SplFileObject($data); } } catch (\RuntimeException $exception) { - throw new UnexpectedValueException($exception->getMessage(), $exception->getCode(), $exception); + throw new NotNormalizableValueException($exception->getMessage(), $exception->getCode(), $exception); } throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $class)); @@ -107,13 +116,7 @@ */ public function supportsDenormalization($data, $type, $format = null) { - $supportedTypes = array( - \SplFileInfo::class => true, - \SplFileObject::class => true, - 'Symfony\Component\HttpFoundation\File\File' => true, - ); - - return isset($supportedTypes[$type]); + return isset(self::$supportedTypes[$type]); } /**