Extract method
This commit is contained in:
@@ -44,12 +44,14 @@ final class IconRuntime implements RuntimeExtensionInterface
|
|||||||
{
|
{
|
||||||
$options = $this->mergeWithDefaultOptions($userOptions);
|
$options = $this->mergeWithDefaultOptions($userOptions);
|
||||||
|
|
||||||
$svg = $this->getSanitisedIconSvg($options['icon']);
|
$svg = $this->getSvg($options['icon']);
|
||||||
|
$svg = $this->sanitiseSvg($svg);
|
||||||
|
|
||||||
$colourClasses = $this->getColourClasses($options['colour'], $options['hover']);
|
$colourClasses = $this->getColourClasses($options['colour'], $options['hover']);
|
||||||
$extraClasses = $this->getExtraClasses($options['classes']);
|
$extraClasses = $this->getExtraClasses($options['classes']);
|
||||||
|
|
||||||
$svg = $this->addClassesToSvg($svg, trim($colourClasses.' '.$extraClasses));
|
$classes = trim($colourClasses.' '.$extraClasses);
|
||||||
|
$svg = $this->addClassesToSvg($svg, $classes);
|
||||||
$svg = $this->addTitleToSvgIfNotNull($svg, $options['title']);
|
$svg = $this->addTitleToSvgIfNotNull($svg, $options['title']);
|
||||||
$svg = $this->setSvgHeightAndWidth($svg, $options['size']);
|
$svg = $this->setSvgHeightAndWidth($svg, $options['size']);
|
||||||
|
|
||||||
@@ -81,11 +83,14 @@ final class IconRuntime implements RuntimeExtensionInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSanitisedIconSvg(string $iconName): string
|
private function getSvg(string $iconName): string
|
||||||
{
|
{
|
||||||
$iconFilepath = $this->findSvgFilepath($iconName);
|
$iconFilepath = $this->findSvgFilepath($iconName);
|
||||||
$svg = $this->getSvgMarkup($iconFilepath);
|
return file_get_contents($iconFilepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sanitiseSvg(string &$svg): string
|
||||||
|
{
|
||||||
$this->removeExistingTitleElement($svg);
|
$this->removeExistingTitleElement($svg);
|
||||||
$this->removeBlackStrokeAttributes($svg);
|
$this->removeBlackStrokeAttributes($svg);
|
||||||
$this->removeStrokeCurrentColor($svg);
|
$this->removeStrokeCurrentColor($svg);
|
||||||
@@ -106,11 +111,6 @@ final class IconRuntime implements RuntimeExtensionInterface
|
|||||||
throw new IconNotFound(sprintf('File "%s.svg" not found in %s', $iconName, implode(', ', $this->directories)));
|
throw new IconNotFound(sprintf('File "%s.svg" not found in %s', $iconName, implode(', ', $this->directories)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSvgMarkup(string $filepath): string
|
|
||||||
{
|
|
||||||
return file_get_contents($filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function removeExistingTitleElement(string &$svg): void
|
private function removeExistingTitleElement(string &$svg): void
|
||||||
{
|
{
|
||||||
$svg = preg_replace('/<title>.*<\/title>/', '', $svg);
|
$svg = preg_replace('/<title>.*<\/title>/', '', $svg);
|
||||||
|
|||||||
Reference in New Issue
Block a user