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.