X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fserializer%2FNormalizer%2FDataUriNormalizer.php;fp=vendor%2Fsymfony%2Fserializer%2FNormalizer%2FDataUriNormalizer.php;h=995bdf14417763d74dcc74b05eb7af90955d5253;hp=9e5af130d03b756cdcc00de53667f38aa9879a44;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/serializer/Normalizer/DataUriNormalizer.php b/vendor/symfony/serializer/Normalizer/DataUriNormalizer.php index 9e5af130d..995bdf144 100644 --- a/vendor/symfony/serializer/Normalizer/DataUriNormalizer.php +++ b/vendor/symfony/serializer/Normalizer/DataUriNormalizer.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\File\File; 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 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; */ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface { + private static $supportedTypes = array( + \SplFileInfo::class => true, + \SplFileObject::class => true, + File::class => true, + ); + /** * @var MimeTypeGuesserInterface */ @@ -79,11 +85,14 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface * 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 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface 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 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface */ 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]); } /**