From 215aa73cd51547c4a255e1d21bae49b95d18ed89 Mon Sep 17 00:00:00 2001 From: Justin Cherniak Date: Wed, 2 May 2018 12:51:18 -0700 Subject: [PATCH] Allow resource handles to be passed into svg() twig function, allowing assets to be run through it. --- src/web/twig/Extension.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/web/twig/Extension.php b/src/web/twig/Extension.php index 37be989b905..bfc370f9847 100644 --- a/src/web/twig/Extension.php +++ b/src/web/twig/Extension.php @@ -806,14 +806,19 @@ public function shuffleFunction($arr) /** * Returns the (sanitized) contents of a given SVG file, namespacing any of its IDs in the process. * - * @param string $svg The SVG file path or contents + * @param string|resource $svg The SVG file path or contents * @param bool $sanitize Whether the file should be sanitized first * @return \Twig_Markup|string */ - public function svgFunction(string $svg, bool $sanitize = true) + public function svgFunction($svg, bool $sanitize = true) { + // If it's a resource, read it until the end. + if (is_resource($svg)) + { + $svg = stream_get_contents($svg); + } // If we can't find an tag, it's probably a file path - if (stripos($svg, '