Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/cake4'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	composer.json
#	src/Utility/Language.php
  • Loading branch information
dereuromark committed Sep 9, 2024
2 parents 0cf4c99 + 317b628 commit 72af965
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/Utility/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ public static function parseLanguageList(?string $languageList = null, array $op
*
* @param array<string> $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;
}
Expand All @@ -112,9 +113,10 @@ public static function findFirstMatch(array $accepted, array $available = []) {
*
* @param array<string> $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();
Expand All @@ -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') {
Expand All @@ -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;
}
}
}
Expand All @@ -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]) {
Expand Down
2 changes: 1 addition & 1 deletion src/View/Icon/Collector/FontAwesome5IconCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions src/View/Icon/FontAwesome4Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
6 changes: 6 additions & 0 deletions src/View/Icon/FontAwesome5Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
Expand Down
6 changes: 6 additions & 0 deletions src/View/Icon/FontAwesome6Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 72af965

Please sign in to comment.