Test for palletes not existing
This commit is contained in:
@@ -15,7 +15,8 @@ final class IconExtension extends AbstractExtension
|
||||
private const DEFAULT_OPTIONS = [
|
||||
'icon' => null,
|
||||
'title' => null,
|
||||
'size' => self::DEFAULT_SIZE
|
||||
'size' => self::DEFAULT_SIZE,
|
||||
'colour' => 'primary'
|
||||
];
|
||||
|
||||
public function __construct(private array $directories, private array $palletes)
|
||||
@@ -59,7 +60,14 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* [ options here ]
|
||||
* ```
|
||||
* $options = [
|
||||
* 'icon' => (string) Which icon to use
|
||||
* 'title' => (?string) Text to appear on mouse hover
|
||||
* 'size' => (int) Height and width in px
|
||||
* 'colour' => (string) Main colour pallete
|
||||
* ]
|
||||
* ```
|
||||
*/
|
||||
public function renderIcon(array $userOptions): string
|
||||
{
|
||||
@@ -69,6 +77,8 @@ final class IconExtension extends AbstractExtension
|
||||
$rawSvgMarkup = $this->getSvgMarkup($iconFilepath);
|
||||
$cleanSvgMarkup = $this->cleanSvgMarkup($rawSvgMarkup);
|
||||
|
||||
$mainColour = $this->getMainPallete($options['colour']);
|
||||
|
||||
if ($this->isNonEmptyString($options['title']))
|
||||
$markup = $this->addTitleToMarkup($cleanSvgMarkup, $options['title']);
|
||||
|
||||
@@ -112,6 +122,14 @@ final class IconExtension extends AbstractExtension
|
||||
return preg_replace('/<title>.*<\/title>/', '', $markup);
|
||||
}
|
||||
|
||||
private function getMainPallete(string $palleteName): array
|
||||
{
|
||||
if (array_key_exists($palleteName, $this->palletes))
|
||||
return $this->palletes[$palleteName];
|
||||
|
||||
throw new PalleteNotFound("The pallete '$palleteName' was not found!");
|
||||
}
|
||||
|
||||
private function isNonEmptyString(mixed $title): bool
|
||||
{
|
||||
if (!is_string($title) && null !== $title)
|
||||
@@ -168,6 +186,8 @@ final class IconExtension extends AbstractExtension
|
||||
|
||||
class IconNotFound extends \Exception {};
|
||||
|
||||
class PalleteNotFound extends \Exception {};
|
||||
|
||||
// class="stroke-neutral-400 fill-neutral-400"
|
||||
|
||||
// hover:stroke-ses-highlight
|
||||
|
||||
Reference in New Issue
Block a user