Use references to edit string in place
This commit is contained in:
@@ -84,12 +84,13 @@ final class IconRuntime implements RuntimeExtensionInterface
|
|||||||
private function getSanitisedIconSvg(string $iconName): string
|
private function getSanitisedIconSvg(string $iconName): string
|
||||||
{
|
{
|
||||||
$iconFilepath = $this->findSvgFilepath($iconName);
|
$iconFilepath = $this->findSvgFilepath($iconName);
|
||||||
$rawSvgMarkup = $this->getSvgMarkup($iconFilepath);
|
$svg = $this->getSvgMarkup($iconFilepath);
|
||||||
$cleanSvgMarkup = $this->removeExistingTitleElement($rawSvgMarkup);
|
|
||||||
$cleanSvgMarkup = $this->removeBlackStrokeAttributes($cleanSvgMarkup);
|
|
||||||
$cleanSvgMarkup = $this->removeStrokeCurrentColor($cleanSvgMarkup);
|
|
||||||
|
|
||||||
return $this->removeBlackFillAttributes($cleanSvgMarkup);
|
$this->removeExistingTitleElement($svg);
|
||||||
|
$this->removeBlackStrokeAttributes($svg);
|
||||||
|
$this->removeStrokeCurrentColor($svg);
|
||||||
|
|
||||||
|
return $this->removeBlackFillAttributes($svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function findSvgFilepath(string $iconName): string
|
private function findSvgFilepath(string $iconName): string
|
||||||
@@ -110,19 +111,19 @@ final class IconRuntime implements RuntimeExtensionInterface
|
|||||||
return file_get_contents($filepath);
|
return file_get_contents($filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeExistingTitleElement(string $svg): string
|
private function removeExistingTitleElement(string &$svg): void
|
||||||
{
|
{
|
||||||
return preg_replace('/<title>.*<\/title>/', '', $svg);
|
$svg = preg_replace('/<title>.*<\/title>/', '', $svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeBlackStrokeAttributes(string $content): string
|
private function removeBlackStrokeAttributes(string &$svg): void
|
||||||
{
|
{
|
||||||
return preg_replace('/stroke(=|:)"?\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"?/', '', $content);
|
$svg = preg_replace('/stroke(=|:)"?\s*(#0{6}|#000|rgb\(\s*0,\s*0,\s*0\s*\)|black)\s*"?/', '', $svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeStrokeCurrentColor(string $content): string
|
private function removeStrokeCurrentColor(string &$svg): void
|
||||||
{
|
{
|
||||||
return \preg_replace('/stroke=(\'|")currentColor(\'|")/', '', $content);
|
$svg = \preg_replace('/stroke=(\'|")currentColor(\'|")/', '', $svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeBlackFillAttributes(string $content): string
|
private function removeBlackFillAttributes(string $content): string
|
||||||
|
|||||||
Reference in New Issue
Block a user