Last active
August 24, 2016 15:01
-
-
Save Daniel-Griffiths/9f33ef6a541dad37e484b5e1c2be8dec to your computer and use it in GitHub Desktop.
PHP Svg Helper Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Icon; | |
/** | |
* Simple helper class that outputs | |
* svg icons as text | |
*/ | |
class Icon | |
{ | |
/** | |
* Path where the icons are stored | |
* @var string | |
*/ | |
private $directory = ''; | |
const FILE_EXTENSION = '.svg'; | |
/** | |
* @param string $directory | |
*/ | |
public function __construct(string $directory = '') | |
{ | |
$this->directory = $directory; | |
} | |
/** | |
* Returns the contents of the svg file | |
* @param string $file | |
* @return string | |
*/ | |
public function render(string $file) | |
{ | |
return file_get_contents($this->directory . $file . self::FILE_EXTENSION); | |
} | |
} | |
/* demo usage */ | |
$icon = new Icon(__DIR__.'/icons/'); | |
echo $icon->render('cat'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment