Skip to content

Instantly share code, notes, and snippets.

@Daniel-Griffiths
Last active August 24, 2016 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daniel-Griffiths/9f33ef6a541dad37e484b5e1c2be8dec to your computer and use it in GitHub Desktop.
Save Daniel-Griffiths/9f33ef6a541dad37e484b5e1c2be8dec to your computer and use it in GitHub Desktop.
PHP Svg Helper Class
<?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