for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace BZIon\Twig;
class Ionicon
{
private static $svgPath = '/assets/svg';
private static $svgIcons = [];
public function __invoke(\Twig_Environment $env, $name, $height = null, $width = null)
$svg = DOC_ROOT . self::$svgPath . '/' . $name . '.svg';
if (isset(self::$svgIcons[$name])) {
return self::$svgIcons[$name];
}
if (file_exists($svg)) {
$svgDoc = simplexml_load_string(file_get_contents($svg));
if ($svgDoc === false) {
return '';
$svgDoc->addAttribute('class', 'ionicon');
$height && $svgDoc->addAttribute('height', $height);
$width && $svgDoc->addAttribute('width', $width);
self::$svgIcons[$name] = $svgDoc->asXML();
public static function get()
return new \Twig_SimpleFunction('ionicon', new self(), [
'needs_environment' => true,
'is_safe' => [
'evaluate' => true
]
]);