comparison vendor/symfony/serializer/Normalizer/DataUriNormalizer.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
23 * 23 *
24 * @author Kévin Dunglas <dunglas@gmail.com> 24 * @author Kévin Dunglas <dunglas@gmail.com>
25 */ 25 */
26 class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface 26 class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface
27 { 27 {
28 private static $supportedTypes = array( 28 private static $supportedTypes = [
29 \SplFileInfo::class => true, 29 \SplFileInfo::class => true,
30 \SplFileObject::class => true, 30 \SplFileObject::class => true,
31 File::class => true, 31 File::class => true,
32 ); 32 ];
33 33
34 /** 34 /**
35 * @var MimeTypeGuesserInterface 35 * @var MimeTypeGuesserInterface
36 */ 36 */
37 private $mimeTypeGuesser; 37 private $mimeTypeGuesser;
46 } 46 }
47 47
48 /** 48 /**
49 * {@inheritdoc} 49 * {@inheritdoc}
50 */ 50 */
51 public function normalize($object, $format = null, array $context = array()) 51 public function normalize($object, $format = null, array $context = [])
52 { 52 {
53 if (!$object instanceof \SplFileInfo) { 53 if (!$object instanceof \SplFileInfo) {
54 throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".'); 54 throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".');
55 } 55 }
56 56
87 * @see https://gist.github.com/bgrins/6194623 87 * @see https://gist.github.com/bgrins/6194623
88 * 88 *
89 * @throws InvalidArgumentException 89 * @throws InvalidArgumentException
90 * @throws NotNormalizableValueException 90 * @throws NotNormalizableValueException
91 */ 91 */
92 public function denormalize($data, $class, $format = null, array $context = array()) 92 public function denormalize($data, $class, $format = null, array $context = [])
93 { 93 {
94 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)) { 94 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)) {
95 throw new NotNormalizableValueException('The provided "data:" URI is not valid.'); 95 throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
96 } 96 }
97 97