From cebeed2cf059dff1d4cfabd6bc74ab10f8896996 Mon Sep 17 00:00:00 2001 From: Ezequiel Villarreal Date: Fri, 6 May 2016 21:30:05 -0500 Subject: [PATCH] HTML::svg New method to work and manipulate svg files. --- classes/Kohana/HTML.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/classes/Kohana/HTML.php b/classes/Kohana/HTML.php index 9752a1e65..2938dd7e4 100644 --- a/classes/Kohana/HTML.php +++ b/classes/Kohana/HTML.php @@ -280,6 +280,33 @@ public static function image($file, array $attributes = NULL, $protocol = NULL, return ''; } + + /** + * Creates a svg link. + * + * echo HTML::svg('media/img/logo.svg', array('class' => 'my-class')); + * + * @param string $file file name + * @param array $attributes default attributes + * @return string + */ + public static function svg($file, array $attributes = NULL) + { + $ret = file_get_contents($file); + + if ( ! empty($attributes)) + { + $dom = new DOMDocument(); + $dom->loadXml($ret); + + foreach($attributes as $key => $value) + $dom->documentElement->setAttribute($key, $value); + + $ret = $dom->saveHTML(); + } + + return $ret; + } /** * Compiles an array of HTML attributes into an attribute string.