name: DataUriNormalizer class_comment: null dependencies: - name: File type: class source: Symfony\Component\HttpFoundation\File\File - name: MimeTypeGuesserInterface type: class source: Symfony\Component\Mime\MimeTypeGuesserInterface - name: MimeTypes type: class source: Symfony\Component\Mime\MimeTypes - name: InvalidArgumentException type: class source: Symfony\Component\Serializer\Exception\InvalidArgumentException - name: NotNormalizableValueException type: class source: Symfony\Component\Serializer\Exception\NotNormalizableValueException properties: [] methods: - name: denormalize visibility: public parameters: - name: data - name: type - name: format default: 'null' - name: context default: '[]' comment: "# * Normalizes an {@see \\SplFileInfo} object to a data URI.\n# * Denormalizes\ \ a data URI to a {@see \\SplFileObject} object.\n# *\n# * @author K\xE9vin Dunglas\ \ \n# */\n# final class DataUriNormalizer implements NormalizerInterface,\ \ DenormalizerInterface\n# {\n# private const SUPPORTED_TYPES = [\n# \\SplFileInfo::class\ \ => true,\n# \\SplFileObject::class => true,\n# File::class => true,\n# ];\n\ # \n# private readonly ?MimeTypeGuesserInterface $mimeTypeGuesser;\n# \n# public\ \ function __construct(?MimeTypeGuesserInterface $mimeTypeGuesser = null)\n# {\n\ # if (!$mimeTypeGuesser && class_exists(MimeTypes::class)) {\n# $mimeTypeGuesser\ \ = MimeTypes::getDefault();\n# }\n# \n# $this->mimeTypeGuesser = $mimeTypeGuesser;\n\ # }\n# \n# public function getSupportedTypes(?string $format): array\n# {\n# return\ \ self::SUPPORTED_TYPES;\n# }\n# \n# public function normalize(mixed $object,\ \ ?string $format = null, array $context = []): string\n# {\n# if (!$object instanceof\ \ \\SplFileInfo) {\n# throw new InvalidArgumentException('The object must be an\ \ instance of \"\\SplFileInfo\".');\n# }\n# \n# $mimeType = $this->getMimeType($object);\n\ # $splFileObject = $this->extractSplFileObject($object);\n# \n# $data = '';\n\ # \n# $splFileObject->rewind();\n# while (!$splFileObject->eof()) {\n# $data .=\ \ $splFileObject->fgets();\n# }\n# \n# if ('text' === explode('/', $mimeType,\ \ 2)[0]) {\n# return \\sprintf('data:%s,%s', $mimeType, rawurlencode($data));\n\ # }\n# \n# return \\sprintf('data:%s;base64,%s', $mimeType, base64_encode($data));\n\ # }\n# \n# public function supportsNormalization(mixed $data, ?string $format\ \ = null, array $context = []): bool\n# {\n# return $data instanceof \\SplFileInfo;\n\ # }\n# \n# /**\n# * Regex adapted from Brian Grinstead code.\n# *\n# * @see https://gist.github.com/bgrins/6194623\n\ # *\n# * @throws InvalidArgumentException\n# * @throws NotNormalizableValueException" - name: supportsDenormalization visibility: public parameters: - name: data - name: type - name: format default: 'null' - name: context default: '[]' comment: null - name: getMimeType visibility: private parameters: - name: object comment: '# * Gets the mime type of the object. Defaults to application/octet-stream.' - name: extractSplFileObject visibility: private parameters: - name: object comment: '# * Returns the \SplFileObject instance associated with the given \SplFileInfo instance.' traits: - Symfony\Component\HttpFoundation\File\File - Symfony\Component\Mime\MimeTypeGuesserInterface - Symfony\Component\Mime\MimeTypes - Symfony\Component\Serializer\Exception\InvalidArgumentException - Symfony\Component\Serializer\Exception\NotNormalizableValueException interfaces: - NormalizerInterface