Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Configurations | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| load | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| for | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Fulltext; |
| 6 | |
| 7 | use Celema\Quma\Database; |
| 8 | use Cosray\Exception\RuntimeException; |
| 9 | use Cosray\Locale; |
| 10 | use Cosray\Locales; |
| 11 | |
| 12 | final class Configurations |
| 13 | { |
| 14 | /** @var array<string, string> */ |
| 15 | private array $names = []; |
| 16 | |
| 17 | public function __construct( |
| 18 | private readonly Database $db, |
| 19 | ) {} |
| 20 | |
| 21 | public function load(Locales $locales): void |
| 22 | { |
| 23 | // Locales is an Iterator; a search may run inside a caller's locale loop. |
| 24 | foreach (clone $locales as $locale) { |
| 25 | $this->for($locale); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public function for(Locale $locale): string |
| 30 | { |
| 31 | $name = $locale->pgDict ?? 'simple'; |
| 32 | if (isset($this->names[$name])) { |
| 33 | return $this->names[$name]; |
| 34 | } |
| 35 | |
| 36 | $row = $this->db->fulltext->config(['name' => $name])->first(); |
| 37 | if (!$row) { |
| 38 | throw new RuntimeException( |
| 39 | "Fulltext configuration '{$name}' for locale '{$locale->id}' is unavailable. Check pgDict and apply the fulltext migration.", |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | return $this->names[$name] = $row['config']; |
| 44 | } |
| 45 | } |