/**
* Create @svg() Blade directive
* use like
* @php $url = App\asset_path("images/logo-icon.svg"); @endphp
* @svg( $url )
*/
sage('blade')->compiler()->directive('svg', function ($arguments) {
// Accept multiple arguments
list($path, $class) = array_pad(explode(',', trim($arguments, "() ")), 2, '');
$path = trim($path, "' \"");
$class = trim($class, "' \"");
// Create the DOM document to remove the XML version element
$class = $class ? "'$class'" : '\'\'';
$path = strpos($path, '$') !== 0 ? "'$path'" : $path;
$output = <<<EOF
<?php
\$svg = new \DOMDocument();
\$svg->load( $path );
\$svg->documentElement->setAttribute("class", $class);
echo \$svg->saveXML(\$svg->documentElement);
?>
EOF;
return $output;
});