svgDocumentFactory = $svgDocumentFactory; } public function injectSvgDocumentService(SvgDocumentService $svgDocumentService): void { $this->svgDocumentService = $svgDocumentService; } public function prepareIconMarkup(Icon $icon, array $options = []): void { $icon->setMarkup($this->generateMarkup($icon, $options)); $icon->setAlternativeMarkup(self::MARKUP_IDENTIFIER_INLINE, $this->generateInlineMarkup($options)); } /** * Calculate public path of SVG file */ protected function getPublicPath(string $source): string { return (string)PathUtility::getSystemResourceUri($source); } protected function getInlineSvg(string $source): string { $svgContent = $this->getInlineSvgContents($source); if ($svgContent === null) { return ''; } try { return $this->svgDocumentService->toInlineMarkup( $this->svgDocumentFactory->fromStringAndSanitize($svgContent) ); } catch (InvalidSvgException) { return ''; } } protected function getInlineSvgContents(string $source): ?string { try { $resourceFactory = GeneralUtility::makeInstance(SystemResourceFactory::class); $resource = $resourceFactory->createResource($source); if ($resource instanceof SystemResourceInterface) { return $resource->getContents(); } } catch (SystemResourceDoesNotExistException) { return null; } catch (SystemResourceException) { } if (!PathUtility::isAbsolutePath($source)) { $source = GeneralUtility::getFileAbsFileName($source); } if (!file_exists($source)) { return null; } return file_get_contents($source) ?: null; } }