diff --git a/src/Utility/Language.php b/src/Utility/Language.php index 0936d404..1c4b1c95 100644 --- a/src/Utility/Language.php +++ b/src/Utility/Language.php @@ -91,10 +91,11 @@ public static function parseLanguageList(?string $languageList = null, array $op * * @param array $accepted * @param array $available + * @param bool $onlyTwoLetters * @return string|null */ - public static function findFirstMatch(array $accepted, array $available = []) { - $matches = static::findMatches($accepted, $available); + public static function findFirstMatch(array $accepted, array $available = [], bool $onlyTwoLetters = false) { + $matches = static::findMatches($accepted, $available, $onlyTwoLetters); if (!$matches) { return null; } @@ -112,9 +113,10 @@ public static function findFirstMatch(array $accepted, array $available = []) { * * @param array $accepted * @param array $available + * @param bool $onlyTwoLetters * @return array */ - public static function findMatches(array $accepted, array $available = []): array { + public static function findMatches(array $accepted, array $available = [], bool $onlyTwoLetters = false): array { $matches = []; if (!$available) { $available = static::parseLanguageList(); @@ -127,7 +129,7 @@ public static function findMatches(array $accepted, array $available = []): arra } foreach ($availableValues as $availableValue) { - $matchingGrade = static::_matchLanguage($acceptedValue, $availableValue); + $matchingGrade = static::_matchLanguage($acceptedValue, $availableValue, $onlyTwoLetters); if ($matchingGrade > 0) { $q = (string)($availableQuality * $matchingGrade); if ($q === '1') { @@ -137,7 +139,7 @@ public static function findMatches(array $accepted, array $available = []): arra $matches[$q] = []; } if (!in_array($availableValue, $matches[$q])) { - $matches[$q][] = $availableValue; + $matches[$q][] = $onlyTwoLetters ? $acceptedValue : $availableValue; } } } @@ -153,12 +155,15 @@ public static function findMatches(array $accepted, array $available = []): arra * * @param string $a * @param string $b - * + * @param bool $onlyTwoLetters * @return float */ - protected static function _matchLanguage(string $a, string $b) { + protected static function _matchLanguage(string $a, string $b, bool $onlyTwoLetters = false) { $a = explode('-', strtolower($a)); $b = explode('-', strtolower($b)); + if ($onlyTwoLetters) { + return $a[0] === $b[0] ? 1 : 0; + } for ($i = 0, $n = min(count($a), count($b)); $i < $n; $i++) { if ($a[$i] !== $b[$i]) { diff --git a/src/View/Icon/Collector/FontAwesome5IconCollector.php b/src/View/Icon/Collector/FontAwesome5IconCollector.php index 5f35adc9..2ae71932 100644 --- a/src/View/Icon/Collector/FontAwesome5IconCollector.php +++ b/src/View/Icon/Collector/FontAwesome5IconCollector.php @@ -24,7 +24,7 @@ public static function collect(string $filePath): array { switch ($ext) { case 'svg': preg_match_all('/symbol id="([a-z][^"]+)"/', $content, $matches); - if (!$matches) { + if (empty($matches[1])) { throw new RuntimeException('Cannot parse SVG: ' . $filePath); } $icons = $matches[1]; diff --git a/src/View/Icon/FontAwesome4Icon.php b/src/View/Icon/FontAwesome4Icon.php index 733a9678..b88cecb3 100644 --- a/src/View/Icon/FontAwesome4Icon.php +++ b/src/View/Icon/FontAwesome4Icon.php @@ -41,6 +41,12 @@ public function render(string $icon, array $options = [], array $attributes = [] $attributes += $this->config['attributes']; } + // Shimming + if (isset($options['title'])) { + $attributes['title'] = $options['title']; + unset($options['title']); + } + $namespace = 'fa'; $class = [ diff --git a/src/View/Icon/FontAwesome5Icon.php b/src/View/Icon/FontAwesome5Icon.php index 682f9278..69f6e58c 100644 --- a/src/View/Icon/FontAwesome5Icon.php +++ b/src/View/Icon/FontAwesome5Icon.php @@ -42,6 +42,12 @@ public function render(string $icon, array $options = [], array $attributes = [] $attributes += $this->config['attributes']; } + // Shimming + if (isset($options['title'])) { + $attributes['title'] = $options['title']; + unset($options['title']); + } + $class = [ $this->config['namespace'], ]; diff --git a/src/View/Icon/FontAwesome6Icon.php b/src/View/Icon/FontAwesome6Icon.php index 7c5f0d6a..ceba51f7 100644 --- a/src/View/Icon/FontAwesome6Icon.php +++ b/src/View/Icon/FontAwesome6Icon.php @@ -42,6 +42,12 @@ public function render(string $icon, array $options = [], array $attributes = [] $attributes += $this->config['attributes']; } + // Shimming + if (isset($options['title'])) { + $attributes['title'] = $options['title']; + unset($options['title']); + } + $namespace = 'fa-' . $this->config['namespace']; $class = [